{"id":25833118,"url":"https://github.com/woolfrey/mujoco_ros2","last_synced_at":"2025-10-24T02:25:12.742Z","repository":{"id":251390113,"uuid":"835864444","full_name":"Woolfrey/mujoco_ros2","owner":"Woolfrey","description":"Allows for communication between MuJoCo and ROS2","archived":false,"fork":false,"pushed_at":"2025-02-20T12:54:44.000Z","size":3538,"stargazers_count":5,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-20T13:25:08.980Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Woolfrey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-30T17:19:52.000Z","updated_at":"2025-02-20T12:13:18.000Z","dependencies_parsed_at":"2024-12-18T14:29:24.806Z","dependency_job_id":"92e1aa4f-efaf-40cb-80df-5c2f9df1560b","html_url":"https://github.com/Woolfrey/mujoco_ros2","commit_stats":null,"previous_names":["woolfrey/interface_mujoco_ros2","woolfrey/mujoco_ros2"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Woolfrey%2Fmujoco_ros2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Woolfrey%2Fmujoco_ros2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Woolfrey%2Fmujoco_ros2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Woolfrey%2Fmujoco_ros2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Woolfrey","download_url":"https://codeload.github.com/Woolfrey/mujoco_ros2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241263695,"owners_count":19936058,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-28T22:47:07.918Z","updated_at":"2025-10-12T10:32:53.743Z","avatar_url":"https://github.com/Woolfrey.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# :bridge_at_night: MuJoCo - ROS2\n\nThis package enables a basic MuJoCo simulation environment with ROS2 communication channels for controlling a robot. It publishes a `sensor_msgs/msg/JointState` topic containing the position, velocity, and effort of the joints, and accepts commands via a `std_msgs::Float64MultiArray` topic. It can run in `POSITION`, `VELOCITY`, or `TORQUE` mode which can be set as a parameter in a launch file.\n\n\u003cp align=\"center\"\u003e\n   \u003cimg src=\"doc/mujoco_node.png\" width=\"600\" height=\"auto\" alt=\"Diagram showing interaction with mujoco node.\"/\u003e\n   \u003cbr\u003e\n   \u003cem\u003eFigure 1: Your custom control node can interact with the mujoco node through two topics.\u003c/em\u003e\n\u003c/p\u003e\n\n\u003e[!TIP]\n\u003e There are many robot models available in the [Google DeepMind MuJoCo Menagerie](https://github.com/google-deepmind/mujoco_menagerie.git).\n\n\u003cp align=\"center\"\u003e\n   \u003cimg src=\"doc/kuka.png\" width=\"800\" height=\"auto\" alt=\"A screenshot of the package running with a 3D model.\"/\u003e\n   \u003cbr\u003e\n   \u003cem\u003eFigure 2: The Kuka iiwa14 model from the MuJoCo Menagerie.\u003c/em\u003e\n\u003c/p\u003e\n\n#### :compass: Navigation\n\n- [Dependencies](#link-dependencies)\n- [Installation](#floppy_disk-installation)\n- [Launching the Simulation](#rocket-launching-the-simulation)\n- [Contributing](#handshake-contributing)\n- [License](#scroll-license)\n\n[:top: Back to top.](#bridge_at_night-mujoco---ros2)\n\n## :link: Dependencies\n\n- [Ubuntu 22.04](https://ubuntu.com/download/desktop) or later,\n- [ROS2](https://docs.ros.org/en/humble/index.html) (Humble Hawksbill or later)\n- [MuJoCo 3.2.0](https://mujoco.org/) or later, and\n- [GLFW](https://github.com/glfw/glfw) for visualisation.\n\n\u003e [!NOTE]\n\u003e This package was built and tested with Ubuntu 22.04, using ROS2 Humble Hawksbill, and MuJoCo 3.2.0.\n\n[:top: Back to top.](#bridge_at_night-mujoco---ros2)\n\n## :floppy_disk: Installation\n\n### Prerequisites\n\nEnsure that you have ROS2 and MuJoCo installed on your system.\n\n1. **Install ROS2:**\n   \n   Follow the [ROS2 installation guide](https://docs.ros.org/en/foxy/Installation.html) for your operating system.\n\n2. **Install MuJoCo:**\n   \n   Download and install MuJoCo from the [official website](https://mujoco.org/).\n\n   Mine is installed in `/opt/mujoco/mujoco-3.2.0`\n\n   Next, modify your `.bashrc` file:\n   ```\n   gedit ~/.bashrc\n   ```\n   Add the following lines of code at the bottom:\n   ```\n   export MUJOCO_PY_MUJOCO_PATH=/opt/mujoco/mujoco-3.2.0\n   export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/mujoco/mujoco-3.2.0/bin\n   export LD_LIBRARY_PATH=/opt/mujoco/mujoco-3.2.0/lib:$LD_LIBRARY_PATH\n   ```\n   Change all instances of `opt/mujoco/mujoco-3.2.0` to match your installation location, and your version.\n\n4. **Install GLFW:**\n```\n   sudo apt-get install libglfw3-dev\n```\n\n[:top: Back to top.](#bridge_at_night-mujoco---ros2)\n\n### Building the Project\n\nIn the `src/` directory of your ROS2 workspace, clone the repository:\n```\ngit clone https://github.com/Woolfrey/mujoco_ros2\n```\nYour directory structure should look something like this:\n```\nros2_workspace/\n├── build/\n├── install/\n├── log/\n└── src/\n    └── mujoco_ros2/\n        ├── include/\n        ├── launch/\n        ├── model/\n        ├── src/\n        ├── CMakeLists.txt\n        ├── LICENSE\n        ├── package.xml\n        └── README.md\n```\n\nIn `CMakeLists.txt` you need to tell the compiler where to find the MuJoCo header files:\n```\nset(MUJOCO_PATH \"/opt/mujoco/mujoco-3.2.0\") # UPDATE THIS TO YOUR MUJOCO PATH\ninclude_directories(${MUJOCO_PATH}/include/mujoco)                                                  # MuJoCo header files\ninclude_directories(${MUJOCO_PATH}/include)                                                         # Additional MuJoCo header files\nlink_directories(${MUJOCO_PATH}/lib)                                                                # Location of MuJoCo libraries\n```\nAs noted above, mine is installed in `/opt/mujoco/mujoco-3.2.0` but you should change it to match your directory and version.\n\nNavigate back to the root of your ROS2 workspace and build the package:\n```\ncolcon build --packages-select mujoco_ros2\n```\nSource the ROS2 workspace:\n```\nsource install/setup.bash\n```\n\n[:top: Back to top.](#bridge_at_night-mujoco---ros2)\n\n## :rocket: Launching the Simulation\n\nThere is a simple launch file that demonstrates how to run it in `mujoco_ros2/launch/example.py`. It launches the node:\n```\n    mujoco = Node(\n        package    = \"mujoco_ros2\",\n        executable = \"mujoco_node\",\n        output     = \"screen\",\n        arguments  = [xmlScenePath],\n        parameters = [   \n                        {\"joint_state_topic_name\" : \"joint_state\"},\n                        {\"joint_command_topic_name\" : \"joint_commands\"},\n                        {\"control_mode\" : \"VELOCITY\"},\n                        {\"simulation_frequency\" : 1000},\n                        {\"visualisation_frequency\" : 20},\n                        {\"camera_focal_point\": [0.0, 0.0, 0.25]},\n                        {\"camera_distance\": 2.5},\n                        {\"camera_azimuth\": 135.0},\n                        {\"camera_elevation\": -20.0},\n                        {\"camera_orthographic\": True}\n                     ]\n    )\n```\n\nThe `argument = [xmlScenePath]` requires a valid MuJoCo xml file. For this example, it utilizes the local `model/scene.xml` file. There are lots of other models in the [MuJoCo Menagerie](https://github.com/google-deepmind/mujoco_menagerie) that you can use.\n\nThe `parameter` argument can be changed based on your preferences:\n| Argument | Purpose |\n|----------|---------|\n| joint_state_topic_name | This sets the name of the topic for the joint state publisher. Your ROS2 robot control node should subscribe to this topic as a `sensor_msgs/JointState`. |\n| joint_command_topic_name | This sets the topic name that the node will subcsribe to for receiving joint commands. Your ROS2 robot control node should publish to this as a `std_msgs/Float64MultiArray`. |\n| control_mode | This is a string that sets what type of commands are sent to the joints. Options are POSITION, VELOCITY, or TORQUE. |\n| simulation_frequency | This is used to set the update rate of the underlying MuJoCo simulation. |\n| visualisation_frequency | This is how fast the 3D rendering should be refreshed. In general it should be much lower than the simulation frequency. |\n| camera_focal_point | A position in the 3D world that the camera looks at. |\n| camera_distance | How far the camera is from the focal point. |\n| camera_azimuth | A clockwise rotation of the camera viewing angle. |\n| camera_elevation | The tilt of the angle from the ground plane. |\n| cmaera_orthographic | Controls the type of projection. Can be `True` or `False`. |\n\nAfter you've installed the package, and sourced the workspace, you can run:\n```\nros2 launch mujoco_ros2 example.py\n```\n\nAnd you should see the following:\n\n\u003cp align=\"center\"\u003e\n   \u003cimg src=\"doc/example.png\" width=\"800\" height=\"auto\" alt=\"Diagram showing results of example launch file.\"/\u003e\n   \u003cbr\u003e\n   \u003cem\u003eFigure 3: Using the launch example generates a 2-link planar robot, with ROS2 communication channels.\u003c/em\u003e\n\u003c/p\u003e\n\nYou can check the topics are available, and see the output for the joint state being published:\n```\nros2 topic list\nros2 topic echo /joint_state\n```\n\nYou can alter the parameters to your liking.\n\n\u003e [!NOTE]\n\u003e So far I've only tested VELOCITY mode robustly. TORQUE mode did work, but my controller hadn't been properly tuned. It will be double-checked in the near future.\n\n[:top: Back to top.](#bridge_at_night-mujoco---ros2)\n\n## :handshake: Contributing\n\nContributions to this repositore are welcome! Feel free to:\n1. Fork the repository,\n2. Implement your changes / improvements, then\n3. Issue a pull request.\n\nIf you're looking for ideas, you can always check the [Issues tab](https://github.com/Woolfrey/mujoco_ros2/issues) for those with :raising_hand: [OPEN]. These are things I'd like to implement, but don't have time for. It'd be much appreciated, and you'll be tagged as a contributor :sunglasses:\n\n[:top: Back to top.](#building_construction-software-template-repository)\n\n## :scroll: License\n\nThis software package is licensed under the [GNU General Public License v3.0 (GPL-3.0)](https://choosealicense.com/licenses/gpl-3.0/). You are free to use, modify, and distribute this package, provided that any modified versions also comply with the GPL-3.0 license. All modified versions must make the source code available and be licensed under GPL-3.0. The license also ensures that the software remains free and prohibits the use of proprietary restrictions such as Digital Rights Management (DRM) and patent claims. For more details, please refer to the [full license text](LICENSE).\n\n[:top: Back to top.](#building_construction-software-template-repository)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwoolfrey%2Fmujoco_ros2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwoolfrey%2Fmujoco_ros2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwoolfrey%2Fmujoco_ros2/lists"}