Overview
This repo provides a simulation stack for Stretch 4, built on MuJoCo. The simulation for Stretch 3 can be found in the stretch_mujoco repo. The simulation includes position control for the arm and gripper joints, velocity control for mobile base, calibrated camera RGB + depth imagery, 3D lidar clouds, and more. There is a visualizer that supports user interaction, or a more efficient headless mode. There is a ROS2 package, built on this library, that works with Nav2 and more. There is 100s of permutations of Robocasa-provided kitchen environments that Stretch can spawn into. The MuJoCo API can be used for features like deformables, procedural model generation, SDF collisions, cloth simulation, and more.
Check out a video of Stretch 4 in Robocasa environments in Mujoco:
https://github.com/user-attachments/assets/ea683561-998b-44d3-9d45-41ab1b1664ab
Getting Started
First, install uv. Uv is a package manager that we'll use to run this project.
Then, clone this repo:
git clone https://github.com/hello-robot/stretch4_mujoco --recurse-submodules
cd stretch4_mujocoIf you've already cloned the repo without
--recurse-submodules, rungit submodule update --initto pull the submodule.
Then, install this repo:
uv venv
uv pip install -e .Lastly, run the simulation:
uv run launch_sim.pyNote: If you see a build error mentioning
evdevon linux, please runsudo apt install python3-dev.
To exit, press Ctrl+C in the terminal.
On MacOS, if
mjpythonfails to locatelibpython3.10.dylibandlibz.1.dylib, run these commands:
GPU Acceleration
On Linux, by default, the Python code will attempt to use GPU acceleration by setting the necessary environment variables at runtime. However, if you are running examples outside the typical Python execution flow or need to ensure these are set system-wide, you can manually export the following environment variables:
These variables ensure that MuJoCo and any associated rendering libraries utilize hardware acceleration, which is highly recommended for performance when working with cameras or complex scenes.
Example Scripts
Control Stretch in simulation using any xbox type gamepad (uses xinput)
Ignore any warnings.
Writing Code
Use the Stretch4MujocoSimulator class to:
start the simulation
position control the robot's ranged joints
velocity control the robot's mobile base
read joint states
read camera imagery
Try the code below using uv run ipython. For advanced Mujoco users, the class also exposes the mjModel and mjData. See the official Mujoco documentation.
Loading Robocasa Kitchen Scenes
The stretch4_mujoco.robocasa_gen.model_generation_wizard() method gives you:
Wizard/API to generate a kitchen model for a given task, layout, and style.
If layout and style are not provided, it will take you through a wizard to choose them in the terminal.
If robot_spawn_pose is not provided, it will spawn the robot to the default pose from robocasa fixtures.
You can also write the generated xml model with absolutepaths to a file.
ROS2
You can use this simulation in ROS2 using the stretch_simulation package in stretch4_ros2.
Docs
Check out the following documentation resources:
Feature Requests and Bug reporting
All the enhancements/bugfixes are tracked by Github Issues filed. Please feel free to file an issue if you would like to report a bug or request a feature addition.
Acknowledgment
The assets in this repository contain significant contributions and efforts from Kevin Zakka and Google Deepmind, along with others in Hello Robot Inc. who helped us in modeling Stretch in Mujoco. Thank you for your contributions.
License
The license covering the code and assets in this repo can be found in the LICENSE file.
Last updated
Was this helpful?
