Goal
In this guide, you’ll run the main comparison test that demonstrates the power of adaptive RL control. You’ll see three simulations side-by-side showing how the robot performs:- Baseline on flat terrain - establishes ideal performance
- Baseline on rough terrain - shows degradation without adaptation
- Adaptive RL on rough terrain - demonstrates learned improvements
Time required: ~10 minutes (includes 3 × 17-second simulations + setup)
Prerequisites
Before starting, make sure you’ve completed the installation guide. You’ll need:- ROS2 Jazzy installed and sourced
- Python dependencies from
requirements.txt - The source code cloned to your machine
Step 1: Source ROS2 Environment
Every time you work with the robot, start by sourcing ROS2:Add this line to your
~/.bashrc to automatically source ROS2 in every terminal session.Step 2: Navigate to Project Directory
model/, controllers/, envs/, tests/, etc.
Step 3: Run the Comparison Test
Execute the main comparison script with the pre-trained model:What do these arguments mean?
What do these arguments mean?
--model: Path to the trained PPO policy network (.zip file)--normalize: Path to observation normalization statistics (.pkl file)--seconds: Duration of each simulation (17 seconds gives clear results)
Step 4: Watch the Simulations
The script will run three simulations automatically:Step 1: Baseline (Flat)
A MuJoCo viewer window opens showing the robot on flat terrain. The baseline gait controller moves the robot forward steadily. This simulation lasts 17 seconds.Expected: Smooth forward progression (~0.5m traveled)
Step 2: Baseline (Rough)
The window closes and reopens with rough terrain. Same controller, but now the irregular ground disrupts the gait.Expected: Slower, less efficient movement (~0.3m traveled, 41% degradation)
Step 5: Review the Results
After all three simulations complete, you’ll see:Terminal Output
A summary table with detailed metrics:Comparison Plot
A three-panel visualization saved totests/baseline_vs_adaptive_comparison.png.
Each panel shows:
- Time vs X position trajectory
- Start (green) and end (red) markers
- Distance traveled and average velocity
- Percentage improvement/degradation
Trajectory Data
Three JSON files with complete trajectory data:Understanding the Results
Why Does Baseline Degrade on Rough Terrain?
The baseline controller uses open-loop gait generation:- Ground height varies unexpectedly
- Contact timing differs from predictions
- Body orientation changes due to terrain
How Does Adaptive Control Help?
The RL policy learns to add residual corrections that compensate for terrain:- Body position, velocity, and orientation
- Joint angles and velocities
- Contact states for each foot
- Recent command history
Next Steps
Run Standalone Simulation
Try a simpler simulation without the comparison framework:Press
Space to pause/resume.Try GUI with Joystick
Run the full ROS2 stack with GUI control:Terminal 1:Terminal 2:
Train Your Own Model
Train a new adaptive policy from scratch:Takes ~1.5 hours with 12 CPU cores.
Explore the Code
Dive into the implementation:
gait_controller.py- Baseline diagonal gaitcontrollers/adaptive_gait_controller.py- RL wrapperenvs/adaptive_gait_env.py- Training environmentutils/ik.py- Inverse kinematics solver
Troubleshooting
Error: No module named 'mujoco'
Error: No module named 'mujoco'
You need to install Python dependencies:
Error: Model file not found
Error: Model file not found
Make sure you’re running the script from the project root directory (
walk2/), not from inside tests/.The pre-trained model should exist at:Simulation runs in headless mode (no window)
Simulation runs in headless mode (no window)
Check your If running over SSH without X11 forwarding, MuJoCo will default to headless rendering.
MUJOCO_GL environment variable:Robot falls over immediately
Robot falls over immediately
This might indicate:
- Wrong terrain file (check console output)
- Incorrect IK parameters
- Corrupted model checkpoint
Performance is worse than expected
Performance is worse than expected
Results can vary based on:
- Random terrain generation (each rough terrain is unique)
- Initial robot placement
- Simulation timestep accuracy
Visualization Tips
MuJoCo Viewer Controls
While simulations are running:| Action | Control |
|---|---|
| Rotate camera | Right-click + drag |
| Pan camera | Middle-click + drag |
| Zoom | Scroll wheel |
| Pause | Space bar |
| Reset view | Double-click |
| Exit fullscreen | ESC |
Analyzing Trajectories
Load and plot trajectory data with Python:Learn More
MuJoCo Docs
Physics engine documentation
Stable Baselines 3
RL training framework
ROS2 Jazzy
ROS2 distribution docs