This is an old revision of the document!
In this lab, we study how a quadruped robot, Pupper, can learn to walk using Reinforcement Learning.
Instead of manually programming each leg movement, we define a reward function and train a neural policy in simulation. The robot receives higher rewards for behaviours we want, such as tracking a desired velocity, staying stable and moving efficiently. It receives penalties for behaviours we do not want, such as using too much effort, falling, tilting too much or producing jerky movements.
The original Stanford CS123 workflow uses large-scale parallel simulation for training. This means that many virtual Pupper robots are simulated at the same time. Each simulated robot collects experience, and the Reinforcement Learning algorithm uses that experience to improve the policy.
In this lab, students will follow this workflow:
By the end of the lab, students should be able to:
In Reinforcement Learning, an agent interacts with an environment. At each step, the agent observes the state of the environment, chooses an action and receives a reward.
In this lab:
The algorithm used in the original workflow is PPO, which stands for Proximal Policy Optimization. We do not focus on the full mathematical derivation of PPO in this lab. The important idea is that PPO updates the neural policy so that actions leading to better rewards become more likely.
Training directly on the real robot would be slow, expensive and risky. During early training, the robot may fall, move aggressively, damage its servos or behave unpredictably.
Simulation solves this problem. In the simulator, thousands of trials can be run safely. If a virtual robot falls, the simulation simply resets. No hardware is damaged.
The Stanford workflow uses parallel simulation with MuJoCo/MJX and JAX. Instead of simulating one Pupper at a time, the system simulates many Pupper robots in parallel. This allows the policy to collect experience much faster.
The general idea is:
many simulated Pupper environments
↓
parallel experience collection
↓
PPO policy update
↓
improved walking behaviour
Pupper does not know what “good walking” means. We must define it through a reward function.
A reward function is usually built from several components. Each component encourages or discourages a specific behaviour.
Common reward terms for locomotion include:
A policy trained with a reward focused only on speed may become fast but unstable. A policy trained with too much effort penalty may become energy-efficient but too slow. A good reward function balances speed, stability, energy efficiency and smoothness.
The repository may contain files used for deploying a trained policy on the real robot, for example:
config.yaml launch.py estop_controller.cpp parkour_policy.json test_policy.json rebuild_neural_controller.py deploy.py
These files are used for controller setup and deployment. They are not necessarily the full training environment.
The reward function is not modified inside config.yaml and it is not modified inside .json policy files.
Important:
.json files are already trained policies;config.yaml points the controller to a policy file;rebuild_neural_controller.py prepares the controller on the Raspberry Pi;deploy.py loads a trained policy on the robot;If the full training notebook/environment is not available, students must ask the instructor for the official Lab 5 training material. The deploy repository alone is not enough for full Reinforcement Learning training.
Software:
Optional hardware:
Clone the Lab 5 repository indicated by the instructor:
cd ~ git clone https://github.com/cs123-stanford/lab_5_fall_2025.git cd lab_5_fall_2025
Check the files:
ls
If you only see deploy/controller files and policy .json files, this repository is mainly for deploying a trained policy. The actual reward tuning and training must be done in the official training notebook or training environment.
Open the official Lab 5 training notebook or training environment provided by the instructor.
The training environment is the place where you should find:
Do not try to modify the reward function in config.yaml from the deploy folder. That file is for loading a trained policy, not for training a new one.
Weights & Biases is used to monitor training experiments.
Create or use an existing WandB account. Then follow the instructions from the training notebook to log in.
Typical command:
wandb login
or, inside the notebook, paste your WandB API key when requested.
During training, WandB will record:
Each team should save the WandB run link for the final report.
Before modifying the reward function, run or inspect the baseline policy.
The goal is to understand how the default policy behaves before training a new version.
Observe:
Deliverable for this mission:
Find the reward section in the official training notebook or training code.
Identify the terms used for the reward function.
Look for terms such as:
tracking_lin_vel tracking_ang_vel effort torque stability orientation smoothness height termination
Write down:
Complete the table:
| Reward term | Reward or penalty? | Behaviour affected | Coefficient |
|---|---|---|---|
| tracking_lin_vel | |||
| tracking_ang_vel | |||
| effort / torque | |||
| stability / orientation | |||
| smoothness |
In this mission, the goal is to encourage Pupper to follow a desired forward velocity.
Modify the reward configuration so that velocity tracking has a stronger influence.
Example idea:
tracking_lin_vel = higher value tracking_ang_vel = moderate value effort penalty = low or disabled
Use the exact variable names and configuration format from the official training notebook.
Run the training experiment.
While training, monitor:
Deliverables:
A robot that moves fast but uses too much energy is not necessarily a good robot. In this mission, add or increase the effort penalty.
Example idea:
tracking_lin_vel = keep similar value effort / torque penalty = increase penalty smoothness = optional
Run the training again.
Compare this run with the velocity-focused run.
Observe:
Deliverables:
In this mission, the goal is to obtain a more natural and stable gait.
Modify the reward configuration by adding or increasing terms related to:
Example idea:
tracking_lin_vel = medium value effort penalty = moderate value stability / orientation = higher value smoothness = moderate penalty
Run the training experiment.
Observe:
Deliverables:
Each team must design its own reward configuration.
The goal is to obtain the best balance between:
Your team may modify:
The team must explain:
Deliverables:
Compare at least three policies:
Complete the table:
| Policy | Main reward focus | Average reward / final reward | Behaviour observed | Main problem |
|---|---|---|---|---|
| Baseline | ||||
| Velocity-focused | ||||
| Effort/stability-focused | ||||
| Team policy |
Answer:
A policy trained in simulation may not work perfectly on the real robot. This difference is called the sim-to-real gap.
Possible causes:
Answer in the report:
If the training environment supports it, enable or modify domain randomization.
Examples of randomized parameters:
Train again and compare the policy with the previous version.
Observe:
Deliverable:
This part is done only if the physical Pupper robot is available.
The script rebuild_neural_controller.py must be executed on the robot's Raspberry Pi, not on Windows and not in the training notebook.
Connect to the Raspberry Pi:
ssh pi@IP_ROBOT
Clone the deploy repository on the Raspberry Pi:
cd ~ git clone https://github.com/cs123-stanford/lab_5_fall_2025.git cd lab_5_fall_2025
Check the required files:
ls config.yaml launch.py estop_controller.cpp parkour_policy.json test_policy.json
Run:
python3 rebuild_neural_controller.py
If you get the error Source file does not exist, check that:
/home/pi/lab_5_fall_2025;After training a policy, deploy it only if the physical robot is available and the instructor confirms that the robot is ready for testing.
On the Raspberry Pi:
cd ~/lab_5_fall_2025 python3 deploy.py
Select the trained policy or WandB run indicated by the instructor.
Test the robot in a safe space.
Observe:
Deliverables:
Each team must submit:
The report should have 2-3 pages and include:
Answer briefly:
If the training notebook is not available, ask the instructor for the official Lab 5 training material. The deploy repository alone is not enough for full RL training.
If WandB does not work, check your API key and internet connection.
If training is very slow, check whether GPU/accelerator support is enabled.
If MuJoCo, MJX or JAX fails to import, check the environment setup instructions from the official training notebook.
If the generated videos do not appear, check the notebook output folder and WandB media tab.
If rebuild_neural_controller.py gives errors involving /home/pi, it is probably being run in the wrong environment. It must be run on the Raspberry Pi of the robot.
If the policy works in simulation but not on the real robot, discuss the sim-to-real gap instead of assuming that the training failed.