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 every leg movement, we define a reward function. The robot receives higher scores for desired behaviours, such as moving forward at the requested speed, keeping its body stable, and producing smooth movements. At the same time, it receives penalties for undesired behaviours, such as high effort, sudden movements, or instability.
In real Reinforcement Learning systems, a neural policy is trained in a simulator using an algorithm such as PPO, which stands for Proximal Policy Optimization. In this lab, students will work with a simplified reward tuning sandbox in order to understand how a reward function is calculated and how changing the coefficients affects the final score.
If the physical Pupper robot is available, the second part of the lab allows students to test an already trained policy on the real robot.
The original repository contains the controller and deploy files for Pupper. For the reward tuning activity, each student team will create an additional folder named reward_lab.
This folder will contain a simplified reward tuning sandbox. It is not a full physics simulator and it does not train a real neural policy. Its purpose is to help students understand how a reward function is built, how different reward terms are combined, and how changing coefficients affects the final score.
From the root of the repository, run:
cd ~/lab_5_fall_2025 mkdir -p reward_lab/outputs
After this step, the repository should contain:
lab_5_fall_2025/
├── config.yaml
├── launch.py
├── estop_controller.cpp
├── parkour_policy.json
├── test_policy.json
├── rebuild_neural_controller.py
├── deploy.py
└── reward_lab/
└── outputs/
The folder reward_lab will be used only for the reward tuning exercise. Students must not modify config.yaml or the .json policy files when working on the reward function.
For the reward tuning activity, use the starter archive provided on OCW:
The original repository contains the controller and deploy files for Pupper. The archive reward_lab.zip adds a simplified reward tuning sandbox. This sandbox is not a full physics simulator and it does not train a real neural policy. Its purpose is to help you understand how a reward function is built, how different reward terms are combined, and how changing coefficients affects the final score.
Download reward_lab.zip and extract it in the root folder of the repository:
cd ~/lab_5_fall_2025 unzip reward_lab.zip ls reward_lab
After extraction, the repository should contain:
lab_5_fall_2025/
├── config.yaml
├── launch.py
├── estop_controller.cpp
├── parkour_policy.json
├── test_policy.json
├── rebuild_neural_controller.py
├── deploy.py
└── reward_lab/
├── reward_config.yaml
├── reward_functions.py
├── run_reward_experiment.py
├── README.md
└── outputs/
The folder reward_lab is used only for the reward tuning exercise. Do not modify config.yaml or the .json policy files when working on the reward function.
Install the required Python package:
sudo apt install python3-yaml
Run the experiment:
python3 reward_lab/run_reward_experiment.py --config reward_lab/reward_config.yaml
List the generated output files:
ls reward_lab/outputs
The script prints:
reward_lab/outputs.
Important: effort and smoothness are calculated as positive values, but they usually have negative coefficients in the configuration file. This means they reduce the total reward.
Before continuing, each team must confirm that:
reward_lab exists;reward_config.yaml exists;reward_functions.py exists;run_reward_experiment.py exists;python3 reward_lab/run_reward_experiment.py --config reward_lab/reward_config.yaml
The script displays:
reward_lab/outputs.Example output:
Reward experiment completed Average total reward: 2.1453 Average components: tracking_lin_vel: 0.8741 tracking_ang_vel: 0.9632 effort: 0.5120 stability: 0.8018 smoothness: 0.0921
Important: the effort and smoothness functions return positive values, but in the configuration file they usually have negative coefficients. This means they decrease the total reward.
List the main files in the repository:
ls
List the available policies:
ls *.json
Open the configuration file:
cat config.yaml
Answer in the report:
.json files are available?config.yaml?.json files not the place where we modify the reward?In this mission, the robot should receive a high reward for tracking the desired linear velocity.
Edit the file:
nano reward_lab/reward_config.yaml
Set:
target_linear_velocity: 1.0 target_angular_velocity: 0.0 experiment: steps: 200 seed: 42 profile: "baseline" reward_weights: tracking_lin_vel: 3.0 tracking_ang_vel: 0.5 effort: 0.0 stability: 0.5 smoothness: 0.0
Run:
python3 reward_lab/run_reward_experiment.py --config reward_lab/reward_config.yaml
Write down:
tracking_lin_vel;Now we keep the target velocity, but we penalise effort.
Modify the configuration:
target_linear_velocity: 1.0 target_angular_velocity: 0.0 experiment: steps: 200 seed: 42 profile: "baseline" reward_weights: tracking_lin_vel: 3.0 tracking_ang_vel: 0.5 effort: -0.5 stability: 0.5 smoothness: 0.0
Run:
python3 reward_lab/run_reward_experiment.py --config reward_lab/reward_config.yaml
Compare the result with the previous mission.
Answer:
Now we want a more stable behaviour, even if the robot becomes slightly slower.
Modify the configuration:
target_linear_velocity: 0.8 target_angular_velocity: 0.0 experiment: steps: 200 seed: 42 profile: "stable" reward_weights: tracking_lin_vel: 1.5 tracking_ang_vel: 0.5 effort: -0.2 stability: 3.0 smoothness: -0.2
Run:
python3 reward_lab/run_reward_experiment.py --config reward_lab/reward_config.yaml
Answer:
stability?In this mission, we penalise sudden movements.
Modify the configuration:
target_linear_velocity: 0.8 target_angular_velocity: 0.0 experiment: steps: 200 seed: 42 profile: "stable" reward_weights: tracking_lin_vel: 1.5 tracking_ang_vel: 0.5 effort: -0.2 stability: 3.0 smoothness: -0.2
Run:
python3 reward_lab/run_reward_experiment.py --config reward_lab/reward_config.yaml
Answer:
smoothness penalty influence the total score?Each team must propose its own configuration.
Create a new file:
cp reward_lab/reward_config.yaml reward_lab/reward_config_team.yaml nano reward_lab/reward_config_team.yaml
You may modify:
baseline, fast, stable, or unstable;Run:
python3 reward_lab/run_reward_experiment.py --config reward_lab/reward_config_team.yaml
The team must explain:
Choose the 3 most important configurations you tested and complete the table:
| Configuration | tracking_lin_vel | effort | stability | smoothness | Average total reward | Observation |
|---|---|---|---|---|---|---|
| Speed-focused | ||||||
| Effort penalty | ||||||
| Team configuration |
Answer:
This part is done only if you have access to the physical Pupper robot.
The script rebuild_neural_controller.py must be executed on the robot's Raspberry Pi, not on Windows and not in the local folder used for reward tuning.
Connect to the Raspberry Pi:
ssh pi@IP_ROBOT
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 the repository is located in:
/home/pi/lab_5_fall_2025
and that the files listed above exist.
This part is done only on the real robot.
On the Raspberry Pi:
cd ~/lab_5_fall_2025 python3 deploy.py
After loading the policy, test the robot in a safe space.
Observe:
Reward tuning:
reward_lab/;reward_config.yaml;run_reward_experiment.py;Deploy:
rebuild_neural_controller.py;.json files;Each team must submit:
reward_config_team.yaml;reward_lab/outputs;The report must have a maximum of 2-3 pages and include:
Answer briefly:
.json files not the place where we modify the reward?rebuild_neural_controller.py be executed on the Raspberry Pi?
If the reward_lab folder is missing, create it using the instructions at the beginning of the lab.
If run_reward_experiment.py does not start, check that you are in the main repository folder:
pwd ls ls reward_lab
If you get a No such file or directory error, check the path to the configuration file.
If you get an error related to yaml, run:
sudo apt install python3-yaml
If you run rebuild_neural_controller.py on your laptop and get errors related to /home/pi, the script was executed in the wrong environment. This script is intended for the robot's Raspberry Pi.
If the physical robot is not available, the deploy part is optional.