MuJoCo Playground Sim-to-Real Composition (playground_sim2real.py)
Compose live MuJoCo Studio visualization, perception, IK, collision-aware planning, and visual servoing on mujoco_playground's out-of-the-box so101 and yam 50 Hz DeviceLayer stacks with identical code in mode="sim" and mode="real":
-
Workspace Setup:
- Clone & sync:
git clone https://github.com/google-deepmind/mujoco_playground.git && cd mujoco_playground && make sync-cpu(ormake syncfor CUDA 13 /make sync-cu12for Linux CUDA 12; add--extra so101or--extra yamalongside the same--group, and pass--no-synctouv run). For composed skills, runuv pip install --python .venv/bin/python ruckig opencv-python-headless scipy mink daqp. SetMUJOCO_GL=osmesaonly on headless Linux (omit on macOS). - Hardware bringup & CLI (also runnable without cloning via
uvx --python 3.13 --from "playground[so101]>=1.1"): identify/calibrate SO-101 withuv run --no-sync python -m mujoco_playground.robots.so101.real.{get_ports --identify --roles=follower, get_cameras --identify, get_calibration --roles=follower}, and run tasks viauv run --no-sync playground <train|play|deploy|teleop|sysid|view_log>.
- Clone & sync:
-
Unified
sim/realDeviceLayerExecution (PlaygroundSim2Real):- Wrap
SO101Follower/SO101FollowerDevice(so101_aloha_table, arm inrad, gripper in[0, 100]) orYamFollower/YamFollowerDevice(yam_aloha_table, arm inrad, gripper in[0, 1]) viawith PlaygroundSim2Real(robot="yam", mode="sim", setup_scene=...) as env:, passingsetup_scene(spec)(mujoco-spec-editing/mujoco-python) to customize objects, containers, conveyors, or camera/base poses for any scene. - Never bypass the follower
DeviceLayeror read privileged objectmj_data.xposinside controllers;PlaygroundSim2Realsteps throughfollower/goal_position/*, readsfollower/joint_position/*+ camera streams, and cosine-interpolates safely toFOLLOWER_HOMEonclose().
- Wrap
-
Live MuJoCo Studio Visualization & Hot-Reload (
mujoco-studio-sidecar+mujoco-studio):- Load
mujoco-studio-sidecarandmujoco-studiowhenever interactively building scenes, controllers, or Studio UI panels. mujoco_playground/.venv/bin/pythonalready shipsmujoco.studio: publishbuild_playground_spec(robot="yam", setup_scene=...)from aSimPluginin<workspace_dir>/sim_plugin.py(on_load_modelcallingself.handle.set_model(spec)and returningTrue, plusif self in event.plugins: self.handle.reload()onHotReloadEvent), placeviewer_plugin.py/messages.pyalongside it, launchstudiod.pywith<playground_dir>/.venv/bin/python(<mujoco-studio-sidecar>/scripts/studiod.py --workspace_dir=<dir>,IsDaemon: true), include[MuJoCo Studio](sidecar://robotics/mujoco_studio/), and verify/_studio/statusafter edits (or streamPlaygroundSim2Realrollouts to a StudioViewerHandleviaenv.attach_studio(handle)).
- Load
-
Composing
roboticsPlugin Skills Zero-Shot (sim->real):rgb-object-localization: Callcam = env.camera_opencv("wrist_camera")(computesK,T_world_cam, andT_ee_camfrom measuredq_armviamj_kinematics+mj_camlightwith MuJoCo-to-OpenCVR @ diag([1, -1, -1])applied;cam["T_ee_cam"]isNonefor fixedextra_cameras) and pass(mask, cam["K"], cam["T_world_cam"], z_plane_m)(tabletop atz_plane_m = env.table_height_min Playground world frame plus object height offset) toray_plane_contour_poseor two views totriangulate_matched_points.i2rt-yam-ik& Arm IK: Onyam, map world targets into the arm base frame (computed dynamically fromenv.mj_modelviaenv.t_world_base) withp_b = env.world_to_base_point(p_w)beforeYamIk(xml_path=env.robot_xml_path).make_topdown_grasp_pose(*p_b)+ik.solve(...)(or transform full poses withenv.world_to_base_pose). On 5-DOFso101(or either arm), callenv.solve_arm_ik(pos_world, approach_dir_world=(0, 0, -1), jaw_yaw_rad=...).motion-planning(motion_plannermp): Transform world obstacles into the robot MJCF root frame viaenv.world_to_base_point/env.world_to_base_pose(tableatz = 0.0in base frame), plan free-space detours and linear Cartesian strokes withplanner = mp.RobotArmPlanner(mjcf_path=env.robot_xml_path, joint_names=env.arm_joint_names, gripper_cmd=env.gripper_normalized)(planner.plan_arm/planner.plan_cartesian_stroke,control_dt_s=env.control_period_s), and stream viaenv.execute_trajectory(res["q_trajectory"]).visual-servoing(Ibvs): Compute unoccluded hover height withIbvs.principal_ray_hover_distance(cam["T_ee_cam"], env.approach_axis_ee), refine wrist alignment at hover viaIbvs.ray_plane_contour_pose(mask, cam["fx_px"], cam["fy_px"], cam["cx_px"], cam["cy_px"], cam["T_world_cam"], z_plane_m)(or 6-DOFIbvs.compute_step), then descend, close gripper (env.set_gripper(...)), and lift.


