|
mj-kdl-wrapper
0.1.0
MuJoCo + KDL bridge for robot kinematics and dynamics
|
A C++ library bridging MuJoCo 3.6 physics simulation with KDL for robot kinematics and dynamics.
![]() ex_init — Single arm loaded from MJCF | ![]() ex_table_scene — Arm + table + scene objects |
![]() ex_pick — Pick-and-place with Robotiq 2F-85 | ![]() ex_dual_arm — Dual arm + grippers |
build_scene() accepts MJCF files and builds floor, skybox, table, and objects via mjSpec with no intermediate XML filesAttachmentSpec attaches any MJCF body (mount, FT sensor, gripper, arm on a mobile base) under any named body; chains of arbitrary length are applied in declaration orderSceneSpec::robotsinit_robot_from_mjcf() builds a KDL chain directly from a compiled MuJoCo modelupdate() reads qpos/qvel/qfrc_bias into *_msr and applies *_cmd in POSITION, VELOCITY, or TORQUE modeinit_window_sim() + tick() gives your code the control loop while the MuJoCo simulate UI runs in a background render threadVideoRecorder uses EGL offscreen rendering and an ffmpeg pipe to record MP4s without a display| Dependency | Version | Install |
|---|---|---|
| MuJoCo | 3.6.0 | download to /opt/mujoco-3.6.0 |
| GLFW | 3.x | sudo apt install libglfw3-dev |
| OpenGL / EGL | – | sudo apt install libgl-dev libegl-dev |
| orocos-kdl | – | sudo apt install liborocos-kdl-dev |
| ffmpeg | – | sudo apt install ffmpeg (for VideoRecorder) |
Then add -DCMAKE_PREFIX_PATH=~/ws/install to the build below.
Optional flags:
| Flag | Default | Description |
|---|---|---|
FETCH_LODEPNG=ON | ON | Download real lodepng so the UI screenshot button saves PNGs |
BUILD_RECORDER=ON | ON | Enable VideoRecorder (EGL + ffmpeg headless recording) |
FETCH_MENAGERIE=ON | OFF | Download MuJoCo Menagerie robot models |
BUILD_TESTS=ON | ON | Build and register GoogleTest tests with CTest |
BUILD_DOCS=ON | OFF | Generate Doxygen HTML docs (cmake --build build --target docs) |
When a tool (gripper) is attached, pass its root body as tool_body so KDL dynamics include the full tool inertia:
Chains are supported: push multiple AttachmentSpec entries in order (mount -> FT sensor -> gripper).
| Input | Action |
|---|---|
| Left drag | Orbit camera |
| Right drag | Pan camera |
| Scroll | Zoom |
| Double-click body | Select body for perturbation |
| Left drag (selected) | Apply translational force |
| Right drag (selected) | Apply torque |
D | Deselect body |
Space | Pause / resume |
All other controls (reset, quit, rendering flags) are in the MuJoCo left panel.
All tests self-skip when third_party/menagerie is absent (requires -DFETCH_MENAGERIE=ON):
| Test | What it covers |
|---|---|
test_init | build_scene, init_robot_from_mjcf, cleanup |
test_dual_arm | multi-robot scene, independent KDL chains |
test_table_scene | TableSpec, SceneObject, runtime add/remove |
test_mjcf_load | arm-only model (nv=7) + arm+gripper model (nq>=13) |
test_mjcf_pos_ctrl | position trajectory tracking |
test_mjcf_vel_ctrl | velocity convergence to target |
test_mjcf_trq_ctrl | gravity accuracy with gripper mass, impedance drift |
test_mjcf_pick | full pick-and-place with gripper: cube lifted > 0.20 m |
See src/examples/README.md for the full list of examples.
| Path | Description |
|---|---|
third_party/menagerie/kinova_gen3/gen3.xml | Kinova GEN3 7-DOF arm (MuJoCo Menagerie) |
third_party/menagerie/robotiq_2f85/2f85.xml | Robotiq 2F-85 gripper (MuJoCo Menagerie) |