Overview
The robot implements a diagonal trot gait using a state machine that coordinates diagonal leg pairs in alternating swing and stance phases. Foot trajectories are generated using cubic Bézier curves for smooth, natural swing motion.The diagonal trot is a dynamic gait where diagonal pairs of legs move together (FL+RR, FR+RL), providing excellent stability while enabling efficient forward locomotion.
Gait Parameters
Fromgait_controller.py:18-33, the default configuration is:
Parameter Details
| Parameter | Default | Range | Description |
|---|---|---|---|
body_height | 0.07 m | 0.02-0.10 m | Distance from body to ground |
step_length | 0.05 m | 0.02-0.08 m | Forward/backward stride |
step_height | 0.015 m | 0.005-0.03 m | Maximum foot lift during swing |
cycle_time | 0.8 s | 0.4-1.5 s | Duration of full gait cycle |
swing_shape | 0.35 | 0.05-0.95 | Bézier control point position |
These parameters can be adapted online by the reinforcement learning controller to optimize performance on different terrains. See Reinforcement Learning for details.
Diagonal Trot State Machine
Leg Pairs
Fromgait_controller.py:10-14:
State Transitions
The gait uses a two-state machine implemented with thetransitions library:
- FL and RR legs in swing phase (lifting and moving forward)
- FR and RL legs in stance phase (supporting body weight, pushing)
- Duration:
cycle_time / 2(e.g., 400ms)
- FR and RL legs in swing phase
- FL and RR legs in stance phase
- Duration:
cycle_time / 2(e.g., 400ms)
State Machine Implementation Details
State Machine Implementation Details
From The
gait_controller.py:49-58, the controller sets up automatic transitions:toggle_pair event is triggered automatically when phase_elapsed >= state_duration.Swing Phase Trajectory
Swing phase uses a cubic Bézier curve for smooth, natural foot motion.Bézier Curve Construction
Fromgait_controller.py:106-119:
Control Points
For default parameters (step_length=0.05m, step_height=0.015m, body_height=0.07m):| Point | X | Y | Z | Description |
|---|---|---|---|---|
| P0 | -0.025 | 0 | 0.070 | Start (rear touchdown) |
| P1 | -0.00875 | 0 | 0.055 | First control point |
| P2 | +0.00875 | 0 | 0.055 | Second control point |
| P3 | +0.025 | 0 | 0.070 | End (forward touchdown) |
The
swing_shape parameter (default 0.35) controls how quickly the foot lifts. Lower values create a more aggressive lift, higher values create a gentler arc.Trajectory Evaluation
Fromgait_controller.py:121-125:
tau ranges from 0.0 to 1.0 over the swing duration, smoothly interpolating the Bézier curve.
Stance Phase Trajectory
Stance phase uses a linear sweep from front to rear, simulating ground contact and body propulsion.Linear Motion
Fromgait_controller.py:127-133:
- τ = 0.0: x = +0.025m (forward position)
- τ = 0.5: x = 0.0m (under body center)
- τ = 1.0: x = -0.025m (rear position)
body_height (0.07m) throughout stance, maintaining ground contact.
The constant Z-height assumption works well on flat terrain. On rough terrain, the RL controller adds residual corrections to adapt to surface irregularities.
Gait Update Loop
Fromgait_controller.py:67-87, the main control loop:
Execution Flow
- Accumulate time: Add simulation timestep to phase counter
- Check transition: If phase exceeds half-cycle duration, toggle pairs
- Compute phase: Normalize elapsed time to [0, 1] range
- Generate targets: Evaluate Bézier (swing) or linear (stance) for each leg
- Return targets: Foot positions sent to IK solver
Coordinate Frames
Understanding the coordinate system
Understanding the coordinate system
From README.md:290-294:IK leg frame:
- X: Forward (toward front of robot)
- Y: Lateral (left/right)
- Z: Downward (gravity direction)
- X: Forward with
FORWARD_SIGN = -1.0applied during IK - Y: Lateral offsets for leg spacing
- Z: Height above ground (positive = higher)
FORWARD_SIGN = -1.0) ensures gait coordinates match the IK solver’s convention where Z points down.Lateral Offsets
Fromgait_controller.py:135-140:
- Wider stance for increased stability
- Track width adjustment for narrow passages
- Asymmetric gaits for turning maneuvers
Performance Characteristics
Flat Terrain (Baseline)
From the comparison test results:- Distance traveled: ~0.5 m in 17 seconds
- Average velocity: ~0.03 m/s
- Gait stability: Excellent (minimal roll/pitch)
Rough Terrain (Baseline)
Performance degrades significantly:- Distance traveled: ~0.3 m in 17 seconds
- Average velocity: ~0.018 m/s
- Performance drop: ~40% compared to flat terrain
The baseline gait controller is purely kinematic with no sensory feedback. On rough terrain, this causes efficiency loss as the rigid trajectories cannot adapt to surface variations. See Reinforcement Learning for adaptive solutions.
Related Topics
- Inverse Kinematics - Converting foot targets to joint angles
- Robot Design - Hardware constraints affecting gait design
- Reinforcement Learning - Learning adaptive gait modifications