REF-03 // HEXAPOD|COLORADO SPACE GRANT ROBOTICS COMPETITION

Adaptive Hexapod:
CPG Locomotion Engine

A six-legged, 18-servo walker built to cross terrain wheels can't, then raced (and danced) at the Great Sand Dunes.

18
DOF
40Hz
Control Loop
9-DOF
IMU
2
Bump Sensors

The Regolith Problem

Loose, granular regolith, the kind NASA's Lunabotics competition simulates and the kind that covers the Great Sand Dunes, is a nightmare for traditional rovers. Wheels spin out, dig holes, and get stuck.

To guarantee traversal over that terrain, I abandoned wheels entirely and designed a six-legged hexapod capable of stepping over loose sand rather than rolling through it. The real proving ground ended up being the Colorado Space Grant Robotics Competition, held right on the dunes.

Standing on markwtech's Shoulders

Rather than design a hexapod frame from scratch, we started from markwtech's open-source hexapod design, the 3D model below, and built, wired, and reprogrammed our own unit on top of it, later reworking the servo mounts ourselves (see 06__MECH).

markwtech open-source hexapod 3D model, six-legged frame with 18 servos and central microcontroller mount, used as the base designmarkwtech reference 3D model, our starting point

Bring-up went leg by leg. Here's the first leg wired up and moving under our own firmware, before the rest of the frame was even assembled.

First leg, built and moving

All six legs assembled, wired, and mounted to the central Arduino Mega controller, fully built for the first time.

Fully assembled hexapod robot with all six legs, servos, and central Arduino Mega controller, resting on a wooden workbenchFully assembled, all 18 servos wired

And its first steps under its own power.

First steps

Inverse Kinematics (IK)

// THE MATH

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. This IK engine is what both the CPG research below and the simpler gait that actually raced (05__GAIT) are built on top of.

Central Pattern Generator

// R&D, NOT WHAT RACED

This is real, completed work (designed, coded, and validated in simulation), not vaporware. But coordinating six independently-driven oscillators in firmware turned out to be its own project, and with competition day approaching we shipped a simpler, proven gait instead (see 05__GAIT). This section is what we built toward, not what raced.

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 designed the same architecture for this robot.

// KURAMOTO COUPLED OSCILLATORS
dφᵢ/dt = ω + Σⱼ Kᵢⱼ · sin(φⱼ − φᵢ − θᵢⱼ)
φᵢ : oscillator phase, leg i ∈ [0, 2π)
ω : natural frequency → controls speed + gait type
Kᵢⱼ : coupling strength between legs i and j
θᵢⱼ : target phase offset → encodes desired gait
ω (rad/s)GAITLEGS DOWNUSE 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. The fixed tripod gait that actually raced is the ω≈5.0 row of this table, hard-coded instead of emergent.

What Actually Raced

With the CPG unfinished, the fielded robot ran a fixed tripod gait adapted from markwtech's reference code, three legs down at all times, simple and proven, driven through our own IK engine. Obstacle handling was a straightforward bump-and-recover loop instead of continuous sensor fusion:

FRONT-LEFT bumper hit → turn right → resume forward
FRONT-RIGHT bumper hit → turn left → resume forward
after N steps forward → read 9-DOF IMU heading → re-correct back to straight

That's it: two front bump switches for obstacles, and the IMU periodically pulling the heading back to forward so small drift doesn't compound over a run.

// WHAT DIDN'T MAKE IT IN

The IR range finders, foot contact switches, and ultrasonic sensors from the original CPG-fed sensor suite design were never implemented on the competition robot: there simply wasn't time. Bump switches and the IMU were the entire terrain-sensing budget on race day.

Frame Replacement

FutureTrace kit → markwtech 3D-printed frame

The 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.

// BEFORE: FutureTrace kit
servo ──[bushing]──horn──── leg
↑ all load here

Single cantilevered bushing. Radial load grinds it out in hours. Output drifts ±3–5° from commanded angle. Gait becomes unreliable on sand.

// AFTER: markwtech frame
servo ──[624Z]──horn──── leg ────[624Z]── mount
↑ shared ↑ shared

Dual 624Z bearings built into every servo mount. Servo outputs pure torque. All radial load carried by the printed frame. Sub-degree positioning throughout.

// WHY THIS FRAME

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

// PRINTED PARTS MANIFEST

Body bottom plate

Body top plate

Body risers

18×

Servo mounts (bearing seat)

12×

Femur brackets

12×

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. This is the budget for the gait that actually raced (fixed tripod gait, bump switches, and IMU heading correction) inside the 40Hz (25ms) loop.

Tripod step() + 6× IK solve
3.5ms
Bump switch reads (2× digital)
0.1ms
IMU read (I²C, 9-DOF)
0.5ms
Serial + overhead
0.5ms
Headroom
20.4ms

Total used: ~4.6ms of 25ms available. Plenty of headroom left over: most of it would have gone to the CPG and the extra sensors in 04__CPG, had there been time to finish them.

Race Day at the Great Sand Dunes

The Colorado Space Grant Robotics Competition ran right on the dunes, as close to a lunar regolith analog as Colorado gets.

Morning view of the Great Sand Dunes in Colorado, with storm clouds rolling over the mountains behind the dune fieldGreat Sand Dunes, CO: competition morning

The tripod gait and bump-recovery loop got us through the first course clean.

Hexapod robot walking a lane marked with wooden course stakes on the sand dunes, leaving a trail of leg prints in the sandFirst course, completed

We failed every other course. The tripod gait and bump logic that worked on the first run didn't generalize to the rest of the obstacle set.

The other courses: did not go as well

But it can dance. We built a dedicated dance mode, and it was worth every minute.

Dance mode, undefeated
The hexapod team at the Great Sand Dunes: Janga, Cal, Luke, and Haley, from left to right, holding the robotJanga, Cal, Luke, and Haley, at the Great Sand Dunes
Team

Janga, Cal, Luke Bray, and Haley: Colorado Space Grant Robotics Competition team.

Frame design based on markwtech's open-source hexapod, adapted from the Trossen PhantomX.