Official Implementation for Bridging Adaptivity and Safety: Learning Agile Collision-Free Locomotion Across Varied Physics.
L4DC 2025
Yichao Zhong, Chong Zhang, Tairan He, Guanya Shi
This codebase is under CC BY-NC 4.0 license, with inherited license in Legged Gym and RSL RL from ETH Zurich, Nikita Rudin and NVIDIA CORPORATION & AFFILIATES. You may not use the material for commercial purposes, e.g., to make demos to advertise your commercial products.
Please read through the whole README.md before cloning the repo.
Note: Before running our code, it's highly recommended to first play with RSL's Legged Gym version to get a basic understanding of the Isaac-LeggedGym-RslRL framework.
-
Create environment and install torch
conda create -n bas python=3.8 # or use virtual environment/docker pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116 # used version during this work: torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 # for older cuda ver: pip3 install torch==1.10.0+cu113 torchvision==0.11.1+cu113 torchaudio==0.10.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html -
Install Isaac Gym preview 4 release https://developer.nvidia.com/isaac-gym
unzip files to a folder, then install with pip:
cd isaacgym/python && pip install -e .check it is correctly installed by playing:
cd examples && python 1080_balls_of_solitude.py
-
Clone this codebase and install our
rsl_rlin the training folderpip install -e rsl_rl
-
Install our
legged_gympip install -e legged_gym
Ensure you have installed the following packages:
- pip install numpy==1.21 (must < 1.24, >1.20)
- pip install tensorboard
- pip install setuptools==59.5.0
-
Try training.
can use "--headless" to disable gui, press "v" to pause/resume gui play.
for go1, in
legged_gym/legged_gym,# BAS agile policy along with explicit estimator python scripts/trains/train.py --task=go1_pos_estimator_rough --max_iterations=5000 # BAS agile policy w/o explicit estimator (w/ implicit estimator) python scripts/trains/train.py --task=go1_pos_implicit_estimator_rough --max_iterations=5000 # ABS agile policy python scripts/trains/train.py --task=go1_pos_rough --max_iterations=5000 # PPO-Lagrangian agile policy python scripts/trains/train.py --task=go1_pos_rough_ppo_lagrangian --max_iterations=5000 # RMA-PPO-Lagrangian agile policy python scripts/trains/rma_train_teacher.py --task=go1_teacher_rough_ppo_lagrangian --max_iterations=5000 python scripts/trains/rma_train_student.py --task=go1_student_rough_ppo_lagrangian --max_iterations=5000 # Turn from `RMA` to `Action-Distill` in one code by setting `use_action_loss=True` # recovery policy python scripts/trains/train.py --task=go1_rec_rough --max_iterations=1000 -
Play the trained policy
python scripts/plays/play_bas.py --task=go1_pos_rough python scripts/plays/play_bas.py --task=go1_rec_rough
-
Use the testbed, and train/test Reach-Avoid network (Taking BAS as example):
# For following steps in 7&8, you can change `bas` in filename to [`abs`, 'rma_teacher', 'rma_student', `implicit`] for other entries # try testbed python scripts/testbeds/bas_testbed.py --task=go1_pos_estimator_rough [--load_run=xxx] --num_envs=1 # train RA (be patient it will take time to converge) # make sure you have at least exported one policy by play.py so the exported folder exists python scripts/testbeds/bas_testbed.py --task=go1_pos_estimator_rough --num_envs=1000 --headless --trainRA # test RA (only when you have trained one RA) python scripts/testbeds/bas_testbed.py --task=go1_pos_estimator_rough --num_envs=1 --testRA # evaluate python scripts/testbeds/bas_testbed.py --task=go1_pos_estimator_rough --num_envs=1000 --headless [--load_run=xxx] [--testRA] # On-policy finetuning on estimator python scripts/testbeds/bas_finetune_testbed.py --task=go1_pos_rough --num_envs=1000 --headless [--load_run=xxx] --testRA -
Sample dataset for ray-prediction network training
python scripts/trains/camrec.py --task=go1_pos_rough --num_envs=3- Tips 1: You can edit the
shiftvalue in Line 93 and thelog_rootin Line 87 to collect different dataset files in parallel (so you can merge them by simply moving the files), and manually change the obstacles inenv_cfg.asset.object_filesin Line 63. - Tips 2: After collecting the data, there's a template code in
train_depth_resnet.pyto train the ray-prediction network, but using what you like for training CV models is highly encouraged! - Tips 3: You may change camera configs of resolution, position, FOV, and depth range in the config file Line 151.
- Robot: Unitree Go1 EDU
- Perception: ZED mini Camera
- Onboard Compute: Orin NX (16GB)
- LED: PSEQT LED Lights
- Power Regulator: Pololu 12V, 15A Step-Down Voltage Regulator D24V150F12
- Orin NX mount: STL-PCMount_v2
- ZED mini mount: STL-CameraSeat and STL-ZEDMountv1
- Unitree Go1 SDK
- ZED SDK
- ROS Noetic
- Pytorch on a Python 3 environment
-
Low Level Control Mode for Unitree Go1:
L2+A->L2+B->L1+L2+Start -
Network Configuration for Orin NX:
- IP:
192.168.123.15 - Netmask:
255.255.255.0
- IP:
-
Convert the
.ptfiles of agile/recovery policy, RA value to.onnxfiles usingsrc/abs_src/onnx_model_converter.py -
Modify the path of (.onnx or .pt) models in
publisher_depthimg_linvel.pyanddepth_obstacle_depth_goal_ros.py
roscore: Activate ROS Noetic Envriomentcd src/bas_src/: Enter the ABS scripts filepython publisher_depthimg_linvel.py: Publish ray prediction results and odometry results for navigation goalspython led_control_ros.py: Control the two LED lights based on RA valuespython depth_obstacle_depth_goal_ros.py: Activate the Go1 using the agile policy and the recovery policypython publisher_estimator.py: Publish environment estimation results (with one additional dim for timestamp) for adaptation
B: Emergence stopDefault: Go1 Running ABS based on goal commandL2: Turn leftR2: Turn rightDown: BackUp: StandA: Turn aroundX: Back to initial position
If our work does help you, please consider citing us and the following works:
@misc{zhong2025bridgingadaptivitysafetylearning,
title={Bridging Adaptivity and Safety: Learning Agile Collision-Free Locomotion Across Varied Physics},
author={Yichao Zhong and Chong Zhang and Tairan He and Guanya Shi},
year={2025},
eprint={2501.04276},
archivePrefix={arXiv},
primaryClass={cs.RO},
url={https://arxiv.org/abs/2501.04276},
}This work builds upon Agile But Safe: Learning Collision-Free High-Speed Legged Locomotion. We used codes in Legged Gym and RSL RL, based on the paper:
- Rudin, Nikita, et al. "Learning to walk in minutes using massively parallel deep reinforcement learning." CoRL 2022.

