This repository realizes a lightweight ROS interface called mujoco_ros, which can be integrated with any version of MuJoCo without modifying its code or CMake configurations. This interface allows MuJoCo to function as a ROS node (e.g., /mujoco_sim), transferring the simulated robot state to a ROS topic (e.g., /ambot_v2/states) and executing commands from another ROS topic (e.g.,/ambot_v2/action ) generated by a custom controller ROS Node (e.g., /controller_node).
The controller callback function of mujoco was realized in rosinterface/rosinterface.cc The rostopic utilizes a message named ambot_msgs, which have RobotState and RobotAction for defining the robot states and commands. This repository integrated this rosinterface into mujoco when compile it.
mkdir build cd build && cmake .. && cmake --build .
cd _dep/ambot_msgs-build && make
cd ../../
cmake --build .
- open a terminal and run
roscore
- open a terminal and run
cd ./build/bin/ &&./ros_simulate [your_robot_model.xml] [your_command_topic_name]
- compile error: mujoco_ros/rosinterface/rosinterface.h:40:10: fatal error: ambot_msgs/RobotState.h: No such file or directory 40 | #include <ambot_msgs/RobotState.h> | ^~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated.
- solution:
go to build/_deps/ambot_msgs-build/ and run make, and then cd ./../../ to run cmake --build .
cd _deps/ambot_msgs-build/ && make && cd ./../../ && cmake --build .