Implementation:Google deepmind Mujoco Engine Sensor
| Knowledge Sources | |
|---|---|
| Domains | Physics Simulation, Sensor Simulation, Energy Computation |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Computes all sensor readings and energy quantities at each stage of the simulation pipeline.
Description
engine_sensor.c implements the sensor computation subsystem for MuJoCo. It evaluates all built-in sensor types organized by their dependency stage: position-dependent sensors (mj_sensorPos), velocity-dependent sensors (mj_sensorVel), and acceleration-dependent sensors (mj_sensorAcc). Supported sensor types include joint position/velocity/force, body position/orientation, site/geom frame data, tendon length, actuator state, touch/contact sensors with partial sorting, rangefinder (ray-based), camera projection, IMU-like sensors (accelerometer, gyro, magnetometer), and flexible body vertex sensors. The file also computes potential and kinetic energy (mj_energyPos, mj_energyVel) and handles user-defined and plugin-based sensors through callbacks.
Usage
Called at each stage of the forward or inverse dynamics pipeline: mj_sensorPos() after position computations, mj_sensorVel() after velocity computations, and mj_sensorAcc() after acceleration/force computations. Sensor values are written to the d->sensordata buffer at addresses specified by the model.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: src/engine/engine_sensor.c
- Lines: 1-1739
Key Functions
// compute position-dependent sensors
void mj_sensorPos(const mjModel* m, mjData* d);
// compute velocity-dependent sensors
void mj_sensorVel(const mjModel* m, mjData* d);
// compute acceleration-dependent sensors
void mj_sensorAcc(const mjModel* m, mjData* d);
// compute a single sensor by index
void mj_computeSensor(const mjModel* m, mjData* d, int i, mjtNum* sensordata);
// stage-specific computation helpers
static void mj_computeSensorPos(const mjModel* m, mjData* d, int i, mjtNum* sensordata);
static void mj_computeSensorVel(const mjModel* m, mjData* d, int i, mjtNum* sensordata);
static void mj_computeSensorAcc(const mjModel* m, mjData* d, int i, mjtNum* sensordata);
// energy computations
void mj_energyPos(const mjModel* m, mjData* d);
void mj_energyVel(const mjModel* m, mjData* d);
// user and plugin sensor callbacks
static void compute_user_sensors(const mjModel* m, mjData* d, mjtStage stage);
static void compute_plugin_sensors(const mjModel* m, mjData* d, mjtStage stage);
// utility: apply cutoff to sensor data
static void apply_cutoff(const mjModel* m, int i, mjtNum* data);
Import
#include "engine/engine_sensor.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| m | const mjModel* | Yes | Physics model with sensor definitions |
| d | mjData* | Yes | Simulation state with computed kinematics/dynamics |
| i | int | Yes (computeSensor) | Sensor index to compute |
Outputs
| Name | Type | Description |
|---|---|---|
| d->sensordata | mjtNum* | Buffer with all computed sensor readings |
| d->energy[0] | mjtNum | Potential energy (from mj_energyPos) |
| d->energy[1] | mjtNum | Kinetic energy (from mj_energyVel) |
| sensordata | mjtNum* | Single sensor output (for mj_computeSensor) |