Skip to content

actuator and sensor delays#1169

Open
thowell wants to merge 1 commit intogoogle-deepmind:mainfrom
thowell:delay
Open

actuator and sensor delays#1169
thowell wants to merge 1 commit intogoogle-deepmind:mainfrom
thowell:delay

Conversation

@thowell
Copy link
Collaborator

@thowell thowell commented Feb 18, 2026

actuator and sensor delays


MuJoCo vs MuJoCo Warp: Delay Implementation Differences

API Signature Differences

All shape changes are driven by GPU batching over nworld parallel worlds.

Parameter MuJoCo C MuJoCo Warp Reason
values 1D (nsample,) 2D (nworld, nsample) Per-world initial values
phase scalar float 1D (nworld,) Per-world phase
time scalar float 1D (nworld,) Per-world simulation time
result scalar return / output param (nworld,) or (nworld, dim) One result per world
interp default -1 no default Explicit specification required

Sensor Computation: Conditional vs Always-Compute

MuJoCo C: Conditional Computation

Each sensor goes through compute_or_read_sensor(), which skips computation for delayed sensors:

  • delay > 0: reads directly from history buffer, never calls mj_computeSensor
  • interval > 0, condition not met: reads stale value from buffer
  • interval > 0, condition met: computes fresh value

MuJoCo Warp: Always Compute, Then Overwrite

All sensors are computed unconditionally via a single kernel launch, then apply_sensor_delay() runs as a second pass:

  1. Compute all sensor values (including delayed ones)
  2. Insert fresh values into history buffers
  3. Overwrite sensordata with delayed values from history

Justification

GPU kernels execute uniformly across all threads — per-sensor branching (compute vs skip) creates warp divergence and is inefficient. Computing everything then overwriting is the standard GPU tradeoff: redundant computation is cheaper than divergent control flow. The final result is identical.

Public API Functions

MuJoCo C MuJoCo Warp Description
mj_readCtrl(m, d, id, time, interp) read_ctrl(m, d, ctrlid, time, interp, result) Read delayed ctrl for 1 actuator
mj_readSensor(m, d, id, time, buf, interp) read_sensor(m, d, sensorid, time, interp, result) Read delayed sensor for 1 sensor
mj_initCtrlHistory(m, d, id, times, values) init_ctrl_history(m, d, ctrlid, times, values) Initialize actuator history buffer
mj_initSensorHistory(m, d, id, times, values, phase) init_sensor_history(m, d, sensorid, times, values, phase) Initialize sensor history buffer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant