Repository navigation
Conversation
…ee Go2 first cvc::physics::mujoco_robot owns one robot's mjModel and mjData, built from an MJCF file (the Menagerie's unitree_go2/scene.xml) with its floor replaced by a cvc::height_field. MuJoCo's hfield has the height field's layout and diagonal, so the robot stands on field->height(x, y). It steps at a fixed dt and takes position targets (MuJoCo-side servos, written into its own model) or torques per actuator. It applies wrenches for pushes, reads qpos, qvel, actuator forces and contacts, and reads MuJoCo's own energies (mjENBL_ENERGY) next to books of the work each kind of force did. It also saves and restores snapshots. No process-wide state: no mju_user_* handlers, no plugin registration. CVC_WITH_MUJOCO is off by default. MuJoCo 4 is found in the deps prefix only (cvcpkg's mujoco), never the system's paths. As with Jolt, the MuJoCo TU is its own private target (cvc_physics_mujoco); a shared libcvc links the shared libmujoco and exports none of it. run_mujoco_trial and `cvc mujoco info|stand` run a standing and push trial. The new CI job `mujoco` builds a minimal libcvc with the option on, from cvcpkg's mujoco and mujoco-menagerie, and runs the tests: - the Go2 stands on flat ground and on 10 degree slopes; - a 60 N push perturbs it and it recovers, and 300 N knocks it over; - MuJoCo's energy change matches the books to 2e-5 of the gross work, and the residual halves with the step; - two runs, a run read every step, and a restored snapshot all end on the same bits. The legged plant kind (legged:go2 in plant_host) is left for later: nav's command(steer, accel) needs a locomotion policy to become leg motion (docs/MUJOCO.md).
This was referenced Nov 15, 2026
transfix
enabled auto-merge (squash)
November 15, 2026 08:48
transfix
added a commit
that referenced
this pull request
Nov 15, 2026
…d on #1266) (#1268) * physics: MuJoCo robots on libcvc terrain (CVC_WITH_MUJOCO), the Unitree Go2 first cvc::physics::mujoco_robot owns one robot's mjModel and mjData, built from an MJCF file (the Menagerie's unitree_go2/scene.xml) with its floor replaced by a cvc::height_field. MuJoCo's hfield has the height field's layout and diagonal, so the robot stands on field->height(x, y). It steps at a fixed dt and takes position targets (MuJoCo-side servos, written into its own model) or torques per actuator. It applies wrenches for pushes, reads qpos, qvel, actuator forces and contacts, and reads MuJoCo's own energies (mjENBL_ENERGY) next to books of the work each kind of force did. It also saves and restores snapshots. No process-wide state: no mju_user_* handlers, no plugin registration. CVC_WITH_MUJOCO is off by default. MuJoCo 4 is found in the deps prefix only (cvcpkg's mujoco), never the system's paths. As with Jolt, the MuJoCo TU is its own private target (cvc_physics_mujoco); a shared libcvc links the shared libmujoco and exports none of it. run_mujoco_trial and `cvc mujoco info|stand` run a standing and push trial. The new CI job `mujoco` builds a minimal libcvc with the option on, from cvcpkg's mujoco and mujoco-menagerie, and runs the tests: - the Go2 stands on flat ground and on 10 degree slopes; - a 60 N push perturbs it and it recovers, and 300 N knocks it over; - MuJoCo's energy change matches the books to 2e-5 of the gross work, and the residual halves with the step; - two runs, a run read every step, and a restored snapshot all end on the same bits. The legged plant kind (legged:go2 in plant_host) is left for later: nav's command(steer, accel) needs a locomotion policy to become leg motion (docs/MUJOCO.md). * pycvc: mujoco_robot from Python (the Go2 gym's reset and step) pycvc_mujoco.i puts cvc::physics::mujoco_robot in every pycvc: pycvc.mujoco_robot(model, terrain=height_field, ...) with the C++ options as keywords. It binds the commands (position or torque, per actuator or all), pushes, step() (without the GIL), the readouts (qpos, qvel, commands and actuator forces as read-only float64 numpy copies; base() and contacts() as dicts), energy() and books(), save/restore, and run_mujoco_trial as a dict. Without CVC_WITH_MUJOCO, mujoco_available() is False and the constructor raises. mujoco_robot::reset() goes back to the robot as built (state, modes, gains and books), for a gym's reset. ResetReplaysAFreshRobot checks it to the bit. test_pycvc_mujoco.py has 112 checks. The push moves the Go2 1.66 cm, as in C++. The books close to 2.9e-5 J of 5.9 J. reset() and a restored snapshot replay an episode bitwise, and another thread runs while step() does. The CI job `mujoco` now also builds pycvc (Python 3.12, numpy and SWIG from cvcpkg) and runs it, failing if it skips.
transfix
disabled auto-merge
November 15, 2026 14:04
Owner
Author
|
Its commit (2837de0) is on master, inside #1268's squash commit 76b1988: #1268 was stacked on this PR and merged first, once its CI was green. That run included the MuJoCo job, which ran all 11 C++ tests, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds MuJoCo to libcvc as an optional physics backend. The Unitree Go2 runs on the libcvc terrain. This is the base for the C-PHAST lab (Phase 6 of PH-COMPOSE-ROADMAP.md on #1227), where MuJoCo is the ground truth that C-PHAST's predicted futures and energy books are checked against.
What's in it
cvc::physics::mujoco_robot(inc/cvc/physics/mujoco_robot.h) owns one robot'smjModelandmjData.unitree_go2/scene.xml), with the scene'sfloorreplaced by acvc::height_field. MuJoCo's hfield turned out to have the height field's layout and diagonal split, so the robot stands onfield->height(x, y).apply_wrench,apply_force_at).mjENBL_ENERGY), plus books of the work each kind of force did: actuators, pushes, contacts, joint friction, limits, damping.save/restoresnapshots.mju_user_*handlers and no plugin registration: everything lives on the object. Reading a robot never changes its trajectory. The writable-data scan finds nothing in the new objects.CVC_WITH_MUJOCO, off by default.mujoco), never in system paths. If it isn't found, configure fails.mujoco-menagerie, so the tests never skip quietly.cvc_physics_mujoco, followingCVC_WITH_JOLT's pattern. No public header names a MuJoCo type.NEEDED libmujoco.so.4.0.0and exports no MuJoCo symbol, and configure refuses a static MuJoCo there. Whether the two can ship together still needs checking, as with cvc::ph composition: compositional port-Hamiltonian systems (C-PHAST, Phase 1) #1227. This is noted in THIRD_PARTY_NOTICES.md and docs/MUJOCO.md.run_mujoco_trialandcvc mujoco info|standrun a stand-and-push trial on a sloped plane and print JSON. The logic lives in the library.mujocojob ("MuJoCo robot (Go2, linux)") on ubuntu-24.04.physics_mujoco_robot_testand fails if any test skips.cvc mujoco stand --slope 10 --push 0,60,0and requires that the Go2 recovers.cgal-ab.Measured (Linux x86_64, GCC 13, Release, MuJoCo 4.0.0 from cvcpkg)
Also built locally with MuJoCo off (clang 18): the stub path and the skips work, and
cvc mujocoreports that MuJoCo is missing. The new files compile without warnings under clang 18-Wall -Wextra -Wpedantic.Not here, and why
leggedplant kind (legged:go2inplant_host) is left for later. nav's plant takescommand(steer, accel)for a bicycle. Turning that into leg motion needs a locomotion policy that maps (vx, yaw rate) to joint targets, and none exists yet. Without one, alegged:go2agent would stand still while nav plans as if it were driving.mujocofor all of them, but only Linux x86_64 is built and tested here.No merge without Joe's OK.