Implementation:Google deepmind Mujoco Engine Util Misc
| Knowledge Sources | |
|---|---|
| Domains | Physics Simulation, Utility Functions |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Implements miscellaneous utility functions for the MuJoCo engine, including tendon wrapping, muscle dynamics, contact force encoding, history buffers, type conversion, and general-purpose numerical helpers.
Description
This large utility file contains a diverse collection of functions used across the MuJoCo engine. Key subsystems include tendon wrapping around spheres and cylinders with 2D circle/line intersection calculations, muscle gain/bias/dynamics computations, contact force pyramid encoding and decoding, history buffer management for time-series interpolation, and type conversion between mjtNum, float, and double. It also provides general-purpose functions such as min/max/clip/sign, sorting, random number generation, gather/scatter operations, Base64 encoding/decoding, and formatted matrix printing.
Usage
These utility functions are called throughout the engine for tendon path computation, actuator force generation, contact processing, data type conversions, and various numerical helper operations.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: src/engine/engine_util_misc.c
- Lines: 1-1900
Key Functions
// Tendon wrapping
mjtNum mju_wrap(mjtNum wpnt[6], const mjtNum x0[3], const mjtNum x1[3],
const mjtNum xpos[3], const mjtNum xmat[9],
mjtNum radius, int type, const mjtNum side[3]);
// Muscle dynamics
mjtNum mju_muscleGain(mjtNum len, mjtNum vel, const mjtNum lengthrange[2],
mjtNum acc0, const mjtNum prm[9]);
mjtNum mju_muscleBias(mjtNum len, const mjtNum lengthrange[2],
mjtNum acc0, const mjtNum prm[9]);
mjtNum mju_muscleDynamics(mjtNum ctrl, mjtNum act, const mjtNum prm[3]);
// Contact force encoding
void mju_encodePyramid(mjtNum* pyramid, const mjtNum* force,
const mjtNum* mu, int dim);
void mju_decodePyramid(mjtNum* force, const mjtNum* pyramid,
const mjtNum* mu, int dim);
// History buffers
void mju_historyInit(mjtNum* buf, int n, int dim,
const mjtNum* times, const mjtNum* values, mjtNum user);
mjtNum* mju_historyInsert(mjtNum* buf, int n, int dim, mjtNum t);
// Miscellaneous
mjtNum mju_min(mjtNum a, mjtNum b);
mjtNum mju_max(mjtNum a, mjtNum b);
mjtNum mju_clip(mjtNum x, mjtNum min, mjtNum max);
const char* mju_type2Str(int type);
int mju_str2Type(const char* str);
Import
#include "engine/engine_util_misc.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| x0, x1, xpos | mjtNum[3] | Yes | 3D positions for wrapping endpoints and obstacle center |
| radius | mjtNum | Yes | Radius for wrapping sphere or cylinder |
| len, vel | mjtNum | Yes | Muscle length and velocity for dynamics |
| prm | mjtNum* | Yes | Parameter arrays for muscle or spring-damper models |
| type | int | Yes | Object type identifier (mjtObj enum value) |
Outputs
| Name | Type | Description |
|---|---|---|
| wpnt | mjtNum[6] | Computed wrapping points (pair of 3D points) |
| return value | mjtNum | Computed wrapping length, muscle force, or utility result |
| pyramid, force | mjtNum* | Encoded/decoded contact force representation |