For the complete documentation index, see llms.txt. This page is also available as Markdown.

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_mujoco

If you've already cloned the repo without --recurse-submodules, run git submodule update --init to pull the submodule.

Then, install this repo:

uv venv
uv pip install -e .

Lastly, run the simulation:

uv run launch_sim.py

To exit, press Ctrl+C in the terminal.

On MacOS, if mjpython fails to locate libpython3.10.dylib and libz.1.dylib, run these commands:

# Before proceeding, please reload your terminal and/or IDE window, to make sure the correct UV environment variables are loaded.

source .venv/bin/activate

# When `libpython3.12.dylib` is missing, run:
PYTHON_LIB_DIR=$(python3 -c 'from distutils.sysconfig import get_config_var; print(get_config_var("LIBDIR"))')
ln -s "$PYTHON_LIB_DIR/libpython3.12.dylib" ./.venv/lib/libpython3.12.dylib

# When `libz.1.dylib` is missing, run:
export DYLD_LIBRARY_PATH=/usr/lib:$DYLD_LIBRARY_PATH

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.

Grippers

Stretch 4 can be simulated with either of its grippers. Both carry the ArUco tags of the real fingertips (DICT_6X6_250, ID 200 on the left finger and 201 on the right), so marker detection on the gripper camera works in simulation.

Standard gripper (SG4), the default
Parallel jaw gripper (PG4)

The SG4 gripper in simulation

The PG4 gripper in simulation

Pass --parallel_gripper to run an example with the PG4:

In your own code, pick the gripper with tool_name:

Example Scripts

Drive Stretch from the keyboard. The controls are printed on startup; press I to set the eye colour and animation from a prompt.

Control Stretch in simulation using any xbox type gamepad (read through pygame/SDL2, so it works on Linux, macOS and Windows)

Mirror motion between the sim and a real Stretch 4 over the network. Commands issued in sim are forwarded to the robot as the same RobotClient command, and the robot's joint status is followed back into the sim, so moving either side moves the other.

The digital-twin extra is Linux-only.

Use --controller sim or --controller robot to mirror in one direction only (the default is bidirectional), and --joints to limit which joint groups are mirrored.

Demonstrate base and joint velocity control with set_velocity()

Ignore any warnings.

Spawn Stretch into a MolmoSpaces house. The molmo extra is Linux-only: one of its dependencies, eva-decord, has no macOS wheel or source distribution.

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

  • read 2D and 3D LiDAR point clouds

  • set the colour and animation of the head LED rings

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?