A complete ROS 2 Jazzy simulation package for the Unitree Go2 quadruped robot, featuring autonomous navigation, SLAM mapping, and a CHAMP-based locomotion controller. Designed for educational use and as a foundation for robotics research and development.
Unitree Go2 in Gazebo Harmonic simulation environment
RViz showing robot model, sensor data, and navigation visualization
- Full Gazebo Harmonic Simulation: Physics-accurate simulation with Gazebo Harmonic (gz-sim)
- CHAMP Locomotion Controller: Quadruped gait generation with inverse kinematics
- Dynamic Body Pose Control: Real-time body orientation and height adjustment (6-DOF)
- Nav2 Integration: Autonomous navigation with dynamic path planning
- SLAM Mapping: Real-time map building with SLAM Toolbox
- Multiple Test Environments: Pre-configured worlds for different scenarios
- ROS 2 Jazzy: Built for the latest ROS 2 LTS release
- Operating System: Ubuntu 24.04 (Noble Numbat)
- ROS Distribution: ROS 2 Jazzy Jalisco
- Simulator: Gazebo Harmonic
- Hardware: Recommended 8GB RAM, 4+ CPU cores
If you haven't installed ROS 2 Jazzy yet, follow the official installation guide:
# Set up sources
sudo apt update && sudo apt install software-properties-common
sudo add-apt-repository universe
sudo apt update && sudo apt install curl -y
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
# Install ROS 2 Jazzy Desktop
sudo apt update
sudo apt install ros-jazzy-desktopsudo apt install gz-harmonicsudo apt install \
ros-jazzy-navigation2 \
ros-jazzy-nav2-bringup \
ros-jazzy-slam-toolbox \
ros-jazzy-ros-gz \
ros-jazzy-ros-gz-sim \
ros-jazzy-ros-gz-bridge \
ros-jazzy-gz-ros2-control \
ros-jazzy-robot-localization \
ros-jazzy-rosbridge-suite \
ros-jazzy-joint-state-publisher \
ros-jazzy-joint-state-publisher-gui \
ros-jazzy-xacro \
python3-colcon-common-extensions# Clone the repository
cd ~
git clone https://github.com/AOShei/go2-quadruped-sim.git
cd go2-quadruped-sim
# Build all packages
colcon build
# Source the workspace
source install/setup.bashsource install/setup.bash
ros2 launch unitree_go2_nav2 simulation.launch.pyThis will start:
- Gazebo Harmonic with the Go2 robot
- SLAM Toolbox for mapping
- Nav2 for autonomous navigation
- RViz2 for visualization
There are two main ways to control the Go2 robot in simulation:
The easiest way to move the robot is using Nav2's goal-based navigation in RViz:
-
Launch the full simulation (if not already running):
source install/setup.bash ros2 launch unitree_go2_nav2 simulation.launch.py -
Set a navigation goal in RViz2:
- Click the "Nav2 Goal" button in the RViz toolbar (or press
G) - Click on the map where you want the robot to go
- Drag to set the desired orientation (direction the robot should face)
- Release to send the goal
- Click the "Nav2 Goal" button in the RViz toolbar (or press
-
Watch the robot navigate:
- Nav2 will automatically plan a path (shown as a green line)
- The robot will avoid obstacles using the LiDAR sensor
- The local costmap (colored grid) shows detected obstacles
- SLAM Toolbox simultaneously builds the map as the robot explores
Tips:
- Start with nearby goals to see the robot in action
- The robot moves at ~0.5 m/s maximum speed (tuned for stability)
- If the robot gets stuck, set a new goal or wait for recovery behaviors
- The map will gradually improve as the robot explores more area
For direct control, use keyboard teleoperation:
-
Install teleop_twist_keyboard (if not already installed):
sudo apt install ros-jazzy-teleop-twist-keyboard
-
Launch teleoperation in a new terminal:
source install/setup.bash ros2 run teleop_twist_keyboard teleop_twist_keyboard -
Control the robot with keyboard:
i- Move forwardk- Stop,- Move backwardj- Turn leftl- Turn rightu/o- Move diagonallyq/z- Increase/decrease max speedsw/x- Increase/decrease only linear speede/c- Increase/decrease only angular speed
Note: Keep the teleop terminal focused (active window) for keyboard control to work.
Send velocity commands directly via topic:
# Move forward at 0.2 m/s
ros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.2, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}"
# Turn in place (0.3 rad/s counterclockwise)
ros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.0}, angular: {z: 0.3}}"
# Stop the robot
ros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.0}, angular: {z: 0.0}}"Or write your own Python/C++ node that publishes to /cmd_vel (type: geometry_msgs/msg/Twist).
| Topic | Message Type | Purpose | Example |
|---|---|---|---|
/cmd_vel |
geometry_msgs/Twist |
Velocity control (walking) | "{linear: {x: 0.2}}" |
/body_pose |
unitree_go2_msgs/Pose |
Body orientation/height | "{z: 0.05, pitch: 0.1}" |
Both topics can be used simultaneously for advanced control scenarios.
One of the powerful features of the CHAMP-based controller is dynamic body pose control. This allows you to adjust the robot's body orientation and height while standing or walking, which is essential for:
- Navigating uneven terrain or slopes
- Climbing stairs or ramps
- Demonstrating the controller's stability capabilities
- Research on legged locomotion and balance
The controller subscribes to /body_pose (type: unitree_go2_msgs/msg/Pose) with 6 degrees of freedom:
Translation (meters):
x- Forward/backward body shifty- Left/right body shiftz- Height adjustment (relative to nominal height)
Rotation (radians):
roll- Tilt left/rightpitch- Tilt forward/backwardyaw- Rotate body (while feet stay planted)
# Raise the body by 5cm (good for obstacles)
ros2 topic pub /body_pose unitree_go2_msgs/msg/Pose "{z: 0.05}"
# Lower the body by 3cm (more stable stance)
ros2 topic pub /body_pose unitree_go2_msgs/msg/Pose "{z: -0.03}"
# Tilt forward (pitch down, useful for climbing)
ros2 topic pub /body_pose unitree_go2_msgs/msg/Pose "{pitch: 0.15}"
# Tilt backward (pitch up)
ros2 topic pub /body_pose unitree_go2_msgs/msg/Pose "{pitch: -0.15}"
# Roll left (tilt sideways)
ros2 topic pub /body_pose unitree_go2_msgs/msg/Pose "{roll: 0.2}"
# Combine height and pitch (simulating climbing pose)
ros2 topic pub /body_pose unitree_go2_msgs/msg/Pose "{z: -0.02, pitch: 0.2}"
# Reset to neutral pose
ros2 topic pub /body_pose unitree_go2_msgs/msg/Pose "{x: 0.0, y: 0.0, z: 0.0, roll: 0.0, pitch: 0.0, yaw: 0.0}"Important: Body pose adjustments work in real-time and can be applied while the robot is moving! Try these:
# First, start the robot walking forward
ros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.2}}"
# Then in another terminal, tilt the body forward while walking
ros2 topic pub /body_pose unitree_go2_msgs/msg/Pose "{pitch: 0.1}"
# Or adjust height while moving
ros2 topic pub /body_pose unitree_go2_msgs/msg/Pose "{z: 0.03}"To showcase the controller's stability and adaptability:
-
Static Stability Test: Command different body orientations while standing
# Try various roll/pitch angles to see the legs compensate ros2 topic pub /body_pose unitree_go2_msgs/msg/Pose "{roll: 0.15, pitch: 0.1}"
-
Dynamic Stability Test: Walk with adjusted body pose
# Walk forward with lowered stance ros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.15}}" & ros2 topic pub /body_pose unitree_go2_msgs/msg/Pose "{z: -0.05}"
-
Terrain Adaptation Simulation: Add world with ramps/stairs and adjust pitch
# When approaching an incline, pitch forward ros2 topic pub /body_pose unitree_go2_msgs/msg/Pose "{pitch: 0.15, z: -0.02}"
For stable operation, stay within these ranges:
- Height (z): ±0.08m from nominal (default 0.225m)
- Pitch/Roll: ±0.3 radians (~±17 degrees)
- X/Y Translation: ±0.05m
Exceeding these limits may cause inverse kinematics failures or instability.
Want to see all the body pose capabilities in action? Run the automated demo script:
# Make sure the simulation is running first
ros2 launch unitree_go2_nav2 simulation.launch.py
# In a new terminal, run the demo
source install/setup.bash
ros2 run unitree_go2_nav2 body_pose_demoThe demo will automatically cycle through various poses including:
- Height adjustments (raising and lowering)
- Forward and backward pitch (climbing poses)
- Left and right roll (sideways tilt)
- Combined movements
Watch the robot in Gazebo or RViz as it demonstrates its stability and range of motion!
This workspace contains four ROS 2 packages:
Robot URDF/xacro model with Gazebo Harmonic integration.
- Complete kinematic model (12 DOF)
- Sensors: IMU, 2D LiDAR (270°)
- Realistic mass and inertia properties
CHAMP-based quadruped locomotion controller.
- Inverse kinematics solver
- Gait generation (trot, walk, etc.)
- Body pose stabilization
- Odometry estimation
Navigation and simulation launch files.
- Full simulation stack integration
- SLAM and localization modes
- Multiple pre-configured worlds
- Nav2 parameter tuning for quadrupeds
Custom message definitions.
Pose: 6-DOF body pose commandsVelocities: 3-DOF velocity commands
ros2 launch unitree_go2_nav2 simulation.launch.py use_rviz:=falseros2 launch unitree_go2_nav2 simulation.launch.py use_slam:=false map:=/path/to/map.yamlros2 launch unitree_go2_description display.launch.pyAfter running SLAM and mapping an environment:
ros2 run nav2_map_server map_saver_cli -f my_mapcolcon build --packages-select unitree_go2_description
colcon build --packages-select unitree_go2_controller
colcon build --packages-select unitree_go2_msgs
colcon build --packages-select unitree_go2_nav2# List all active topics
ros2 topic list
# Monitor odometry
ros2 topic echo /odom
# Monitor laser scans
ros2 topic echo /scanEdit src/unitree_go2_controller/config/kinematics_config.yaml:
gait.swing_height: 0.04 # Foot lift height (meters)
gait.stance_duration: 0.25 # Stance phase duration (seconds)
gait.nominal_height: 0.225 # Default body height (meters)- CLAUDE.md: Technical documentation for Claude Code AI assistant
- CREDITS.md: Attribution and licensing information
- Package READMEs: See individual package directories for detailed documentation
-
Check if the controller is running:
ros2 node list | grep quadruped_controller -
Verify velocity commands are being received:
ros2 topic echo /cmd_vel
Increase the transform tolerance in src/unitree_go2_nav2/config/nav2_sim_params_minimal.yaml:
bt_navigator:
ros__parameters:
transform_tolerance: 3.0 # Increase if neededEnsure Gazebo Harmonic is properly installed:
gz sim --version # Should show Gazebo HarmonicClean and rebuild:
rm -rf build/ install/ log/
colcon buildContributions are welcome! This project is designed for educational use and as a jumping-off point for further development.
- Additional gait patterns
- Terrain adaptation algorithms
- Advanced sensor integration
- Real robot hardware interface
- Multi-robot simulation
This project is licensed under the BSD-3-Clause License. See LICENSE for details.
This project incorporates code from:
- CHAMP by Juan Miguel Jimeno (BSD-3-Clause)
- Unitree Go2 robot assets from Unitree Robotics (BSD-3-Clause)
See CREDITS.md for complete attribution information.
If you use this simulation in your research, please cite:
@software{go2_quadruped_sim,
author = {O'Shei, Andrew},
title = {go2-quadruped-sim: Unitree Go2 ROS 2 Simulation},
year = {2024-2025},
url = {https://github.com/AOShei/go2-quadruped-sim}
}Special thanks to:
- Juan Miguel Jimeno for the CHAMP quadruped controller framework
- Unitree Robotics for the Go2 robot and specifications
- The ROS 2 and Gazebo communities
Educational Use: This simulation is specifically designed for learning robotics, testing algorithms, and developing new features for quadruped robots.