Skip to content

feat: Add ROS2 simulation support#119

Open
fanyahao1 wants to merge 1 commit into
unitreerobotics:mainfrom
fanyahao1:main
Open

feat: Add ROS2 simulation support#119
fanyahao1 wants to merge 1 commit into
unitreerobotics:mainfrom
fanyahao1:main

Conversation

@fanyahao1
Copy link
Copy Markdown

Add ROS2 topic-based Unitree MuJoCo sim2sim bridge

Summary

This PR adds a ROS2 topic-based sim2sim path for Unitree MuJoCo, built on top of the existing Unitree ROS2 message interface and Unitree MuJoCo simulator.

The new implementation enables policies, controllers, and onboard ROS2 nodes that already communicate through Unitree low-level ROS2 topics to run directly against the MuJoCo simulator. This makes it possible to test the same ROS2 topic contract used on robot hardware in simulation, without requiring direct SDK-level integration in the policy code.

Motivation

Previously, sim-to-sim or simulation testing with Unitree MuJoCo required tighter coupling to the simulator-side Python bridge or SDK-style interfaces. For ROS2-based onboard stacks, this created a gap between:

  • the hardware execution path, which uses Unitree ROS2 low-level command/state topics;
  • and the simulation path, which used a simulator-specific bridge.

This PR closes that gap by introducing a ROS2 topic version of Unitree MuJoCo sim2sim, allowing the simulator to publish and consume Unitree-compatible ROS2 messages.

This is especially useful for:

  • validating ROS2 control nodes before running on hardware;
  • testing low-level command publication and state feedback loops in simulation;
  • debugging joint command/state mappings with MuJoCo visualization;
  • running onboard inference stacks against simulated Unitree robot dynamics;
  • reducing the difference between simulation and hardware communication paths.

What Changed

Added ROS2-based MuJoCo bridge

Introduces a ROS2 bridge under simulate_python_ros2 that connects Unitree MuJoCo simulation with ROS2 topics.

Key responsibilities include:

  • subscribing to Unitree low-level command topics;
  • publishing simulated low-level robot state;
  • translating between MuJoCo simulator data and Unitree ROS2 message structures;
  • preserving a topic-level interface similar to the real robot execution path.

Added simulator entry point

Adds a ROS2-enabled simulation entry point in unitree_mujoco_ros2.py.

This provides a runnable path for launching the MuJoCo simulation while exposing the robot through ROS2 topics.

Added ROS2 bridge logic

Adds the main ROS2 bridge implementation in unitree_ros2_bridge.py.

The bridge is responsible for the conversion and synchronization layer between:

  • MuJoCo joint state / actuator data;
  • Unitree-style low-level command messages;
  • Unitree-style low-level state messages;
  • ROS2 publishers and subscribers.

Design Notes

The implementation keeps the simulator bridge separate from the existing onboard agent and ROS node logic.

This preserves the current project architecture:

  • onboard agents remain responsible for observations and inference;
  • ROS-facing nodes remain responsible for robot I/O and command/state handling;
  • the MuJoCo ROS2 bridge acts as a simulator-side replacement for the physical Unitree robot topic interface.

This means existing ROS2 controllers can target either:

  1. real Unitree hardware, or
  2. the MuJoCo ROS2 simulator,

with minimal changes to the higher-level control stack.

Why This Is Useful

This PR enables a more realistic and convenient development workflow:

  1. Start the Unitree MuJoCo ROS2 simulator.
  2. Run the same ROS2 control or onboard inference node used for hardware.
  3. Inspect simulated robot behavior before deploying to the real robot.
  4. Debug command/state topic compatibility without hardware access.

This reduces iteration time and improves safety by allowing ROS2-level behavior to be tested in simulation first.

Validation

Suggested manual validation:

  1. Launch the ROS2-enabled Unitree MuJoCo simulator from unitree_mujoco_ros2.py.
  2. Confirm that the simulated low-level state topic is published.
  3. Publish or run a controller that sends Unitree low-level command messages.
  4. Verify that MuJoCo receives the commands and the simulated robot responds.
  5. Confirm that the ROS2 topic names and message types match the expected Unitree ROS2 interface.

Compatibility

This feature is intended for environments where the Unitree ROS2 message packages and MuJoCo Python simulation dependencies are available.

It should not affect the existing non-ROS2 Unitree MuJoCo simulation path or the onboard hardware execution path.

Risk / Notes

  • Correctness depends on the joint ordering and command/state mapping matching the Unitree robot model used by MuJoCo.
  • ROS2 message package availability is required at runtime.
  • This PR adds a simulation bridge and should not change hardware-side command semantics.
  • Users should still validate torque limits, command scaling, and joint mapping before using policies trained or tested through this path on real hardware.

Checklist

  • Added ROS2 topic-based Unitree MuJoCo sim2sim bridge.
  • Added simulator-side ROS2 entry point.
  • Kept simulation bridge separate from onboard runtime logic.
  • Preserved compatibility with the existing Unitree ROS2 topic workflow.

@fanyahao1
Copy link
Copy Markdown
Author

I have tested the ROS2 topic interface with:

ros2 topic echo /lowstate

The /lowstate topic is publishing correctly, and the echoed message fields look normal during the MuJoCo simulation run.

image

This confirms that the ROS2 topic-based Unitree MuJoCo bridge is able to publish simulated low-level robot state successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant