Adaptive Hexapod:
CPG Locomotion Engine
"Wheels fail where the ground fights back. To explore the lunar surface, we had to reinvent the step."
The Regolith Problem
NASA's Lunabotics competition challenges engineers to navigate a simulated lunar surface. The loose, granular regolith is a nightmare for traditional rovers ā wheels spin out, dig holes, and get stuck.
To guarantee traversal over boulders and craters, I abandoned wheels entirely. I designed a six-legged hexapod capable of stepping over obstacles rather than rolling through them. Each foot can probe for stable ground independently ā something no wheel can do.

Inverse Kinematics (IK)
Moving a leg isn't just "move servo A." To place a foot at exactly [x, y, z], you must solve a system of non-linear equations ā the Law of Cosines applied through three joint planes simultaneously ā to determine coxa, femur, and tibia angles.
I implemented a custom geometric IK engine in C++, validated to sub-millimeter round-trip accuracy across all six legs. It runs in under 0.6ms per leg on the Arduino Mega ā fast enough to solve all 18 joints within the 25ms control budget at 40Hz.
The same IK math was independently ported to Python for simulation, where phase-plane visualization confirmed the geometric approach matched the firmware to floating-point precision.
Central Pattern Generator
Real insects don't compute gait keyframes ā their spinal cord runs a self-organizing oscillator network called a Central Pattern Generator. The brain sends one signal ("walk faster"), and the CPG handles all inter-leg coordination automatically. I implemented the same architecture.
| Ļ (rad/s) | GAIT | LEGS DOWN | USE CASE |
|---|---|---|---|
| ~1.0 | Wave | 5 | Rocks, slopes, max stability |
| ~3.0 | Ripple | 4 | General traversal, sand |
| ~5.0 | Tripod | 3 | Speed, flat cleared ground |
The key insight: gait type is not a mode switch. It is a continuous function of Ļ. Change one number, and the waveārippleātripod transition emerges from the coupling dynamics automatically. No state machine. No hard-coded offsets.
Terrain Sensor Suite
Each sensor feeds directly back into the CPG parameters ā not a simple stop/turn interrupt, but a continuous modulation of oscillator frequency, duty factor, and step height. The robot's gait adapts in real time to what it's actually experiencing.
MPU-6050 IMU
Body roll, pitch, and yaw at 40Hz. Feeds body height compensation and asymmetric stance adjustments on inclines.
6Ć Foot Contact Switches
Microswitches at each tibia tip trigger CPG phase-reset on touchdown ā the robot re-syncs gait to actual ground contact rather than predicted contact. Biological insects use the same mechanism.
3Ć IR Range (GP2Y0A21)
Front-facing downward IR sensors detect sudden loss of ground return ā indicating a crater or drop edge. Triggers hard stop and reroute.
3Ć HC-SR04 Ultrasonic
Forward-facing sonar detects surface obstacles at 2ā400cm. Detection increases Ļ (wave gait) and STEP_HEIGHT for clearance, resolving smaller rocks without stopping.
Frame Replacement
FutureTrace kit ā markwtech 3D-printed frameThe original FutureTrace kit mounts every servo as a cantilever ā the output shaft is the only structural connection between the servo body and the driven leg segment. Every stance phase redirects the robot's full weight radially through that shaft. The stock plastic bushing grinds out within hours. The shaft deflects under load, and that deflection introduces positioning error that compounds through the entire IK chain. Cheap servos fighting shear loads they were never designed for.
Single cantilevered bushing. Radial load grinds it out in hours. Output drifts ±3ā5° from commanded angle. Gait becomes unreliable on sand.
Dual 624Z bearings built into every servo mount. Servo outputs pure torque. All radial load carried by the printed frame. Sub-degree positioning throughout.
The markwtech hexapod (inspired by the Trossen PhantomX, designed for MG996R-class servos) solves the shear problem at the design level ā not as a retrofit. Every one of the 18 servo mounts has a press-fit 624Z bearing seat on the outboard side, machined into the print geometry itself. The bearings are structural from day one.
- >
PLA, 30% infill ā printed hot (210°C) for layer adhesion
- >
TPU, 10% infill ā compliant, grip-enhancing on regolith
- >
624Z (4mm ID Ć 13mm OD Ć 5mm) Ć 18 ā one per servo mount
- >
4-40 machine screws + nuts, 3/8ā³ / 1/2ā³ / 5/8ā³ lengths
- >
MG996R clone, 11 kgĀ·cm ā same pinout as existing firmware
- >
Thingiverse #3463845 ā Fusion 360 source + print-ready STLs
Body bottom plate
Body top plate
Body risers
Servo mounts (bearing seat)
Femur brackets
Femur bracket end caps
Tibia brackets
Tibia bracket end caps
Tibia base plates
Tibia foot plates
Tibia sides 1 + 2
Tibia spacer tubes
TPU foot bumpers
Wire guides
Control Loop Budget
The Arduino Mega runs at 16MHz with no FPU. Every millisecond is accounted for. The 40Hz loop (25ms period) is divided across tasks in strict priority order.
Total used: ~8.4ms of 25ms available. 16.6ms headroom reserved for sensor fusion algorithms and future expansion.