Firmware simulation, Unity project, and sim-verified robot fixes

Simulation
- sim/: the unchanged robot firmware compiled into hexapod_sim.dll
  against PC stand-ins (Arduino, Servo, Wire + register-level MPU6050,
  RF24 with matching-config radio), a kinematic body model (support
  plane + planted-foot odometry) that also drives the simulated IMU,
  and a headless smoke test (sim_smoke). build.ps1 builds and tests.
- Hexapod_Simulation_Unity/ folded in (history kept in a bundle
  outside the repo). Assets/HexapodSim loads the DLL, drives the
  existing leg rig, and offers joystick / keyboard / robot-serial
  input plus a test panel.

Robot (all found or confirmed in the simulation)
- Config.h geometry taken from the Unity model.
- IK femur elevation sign, gait stance direction, body pose
  rotation direction, yaw lever arm.
- Stance feet integrated from the current command; gait restarts at
  mid-stance; heading integrates the applied turn rate, only while
  walking.
- Leg clearance and reach checks (Limits::feetFeasible); walk command
  and body pose scaled as a whole, pose scale rate-limited, planted
  feet guarded so the body never snaps or legs collide.
- Robot-gyro self-leveling as an integrator.
- Heading mode: steering relative to the body; S walks backward.
- Standing height from the remote (STANCE_HEIGHT_RANGE_MM).

Protocol v3 (reflash both boards)
- CmdPacket gains body_height (22 bytes).

Remote
- Height slider (Nextion hHeight/nHeight, serial [ ]).
- Fixed unspecified I2C read order in RemoteIMU.

LEGACY/: owner's old Nextion HMI and remote hardware assets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mangavalkandClaude Opus 5.5 committed 2026-09-29 00:37:12 +02:00
1 parent 91dac16fca
commit 935526eab5
145 files changed
+431258 -114

No files matched your search

+31 -8
View File
@@ -7,16 +7,20 @@
// =====================================================================
// ---- Leg geometry ----
// Taken from the Unity model (Hexapod_Simulation_Unity/Assets/Main.unity,
// 1 Unity unit = 10 mm): hip pivots at x = +-10 / 0, z = +-5 / +-6.5;
// coxa 5.5, femur 10, tibia 15. BENCH: confirm against the real chassis.
constexpr int NUM_LEGS = 6;
// Leg order: 0=front-right, 1=mid-right, 2=rear-right, 3=rear-left, 4=mid-left, 5=front-left
// Angles measured counterclockwise from the body's +X (forward) axis, viewed from above.
constexpr float LEG_MOUNT_ANGLE_DEG[NUM_LEGS] = { -45, -90, -135, 135, 90, 45 };
constexpr float LEG_MOUNT_X_MM[NUM_LEGS] = { 80, 0, -80, -80, 0, 80 };
constexpr float LEG_MOUNT_Y_MM[NUM_LEGS] = { -60, -90, -60, 60, 90, 60 };
// This is the direction the coxa points at servo center: straight sideways on this chassis.
constexpr float LEG_MOUNT_ANGLE_DEG[NUM_LEGS] = { -90, -90, -90, 90, 90, 90 };
constexpr float LEG_MOUNT_X_MM[NUM_LEGS] = { 100, 0, -100, -100, 0, 100 };
constexpr float LEG_MOUNT_Y_MM[NUM_LEGS] = { -50, -65, -50, 50, 65, 50 };
constexpr float COXA_LEN_MM = 30.0f;
constexpr float FEMUR_LEN_MM = 60.0f;
constexpr float TIBIA_LEN_MM = 100.0f;
constexpr float COXA_LEN_MM = 55.0f;
constexpr float FEMUR_LEN_MM = 100.0f;
constexpr float TIBIA_LEN_MM = 150.0f;
// ---- Joint limits, degrees ----
constexpr float COXA_MIN_DEG = -60, COXA_MAX_DEG = 60;
@@ -24,8 +28,21 @@ constexpr float FEMUR_MIN_DEG = -80, FEMUR_MAX_DEG = 80;
constexpr float TIBIA_MIN_DEG = -150, TIBIA_MAX_DEG = -20;
// ---- Neutral stance, relative to each leg's own coxa pivot ----
constexpr float STANCE_RADIUS_MM = 140.0f; // how far out the foot rests
constexpr float STANCE_HEIGHT_MM = 90.0f; // how far below the coxa pivot the foot rests
// From the Unity model's rest foot point: 130 mm out from the coxa pivot
// (= COXA_LEN_MM + 75), 150 mm below it.
constexpr float STANCE_RADIUS_MM = 75.0f; // how far out the foot rests, beyond the coxa
constexpr float STANCE_HEIGHT_MM = 150.0f; // how far below the coxa pivot the foot rests (default height)
// The remote's height slider (CmdPacket.body_height) moves the standing
// height by up to this much either way (100..200 mm here - both ends checked
// reachable in the simulation), at no more than STANCE_HEIGHT_RATE_MM_S.
constexpr float STANCE_HEIGHT_RANGE_MM = 50.0f;
constexpr float STANCE_HEIGHT_RATE_MM_S = 60.0f;
// ---- Leg collision ----
// Minimum distance between the center lines of neighbouring legs' segments
// (coxa, femur, tibia). Gait strides and body poses are scaled down to keep
// it. BENCH: set to roughly the width of a leg (servo body + bracket).
constexpr float LEG_CLEARANCE_MM = 30.0f;
// ---- Servo pins (Teensy 4.0). Verify these are PWM-capable on your board. ----
// Order per leg: coxa, femur, tibia.
@@ -55,6 +72,12 @@ constexpr uint8_t RADIO_CE_PIN = 33;
constexpr uint8_t RADIO_CSN_PIN = 34;
constexpr float LINK_TIMEOUT_SEC = 0.3f;
// ---- Robot-gyro self-leveling ----
// Integral gain (1/s): a leftover tilt of 1 deg changes the correction by
// this many deg/s. Higher levels faster but can wobble. BENCH: tune on the robot.
constexpr float ROBOT_GYRO_KI = 3.0f;
constexpr float ROBOT_GYRO_MAX_CORR_DEG = 15.0f; // steepest slope it will level out
// ---- Setpoint smoothing rates ----
constexpr float POSE_TILT_MAX_RATE_DEG = 120.0f; // roll/pitch/yaw offset, deg/s
constexpr float POSE_OFFSET_MAX_RATE_MM = 150.0f; // X/Y/Z offset, mm/s