Skip to content

Commit 0b1925e

Browse files
committed
delay
1 parent e48bce0 commit 0b1925e

7 files changed

Lines changed: 2095 additions & 3 deletions

File tree

mujoco_warp/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
from mujoco_warp._src.forward import rungekutta4 as rungekutta4
4848
from mujoco_warp._src.forward import step1 as step1
4949
from mujoco_warp._src.forward import step2 as step2
50+
from mujoco_warp._src.history import init_ctrl_history as init_ctrl_history
51+
from mujoco_warp._src.history import init_sensor_history as init_sensor_history
52+
from mujoco_warp._src.history import read_ctrl as read_ctrl
53+
from mujoco_warp._src.history import read_sensor as read_sensor
5054
from mujoco_warp._src.inverse import inverse as inverse
5155
from mujoco_warp._src.io import create_render_context as create_render_context
5256
from mujoco_warp._src.io import get_data_into as get_data_into

mujoco_warp/_src/derivative.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,12 @@ def deriv_smooth_vel(m: Model, d: Data, out: wp.array2d[float]):
654654
m: The model containing kinematic and dynamic information (device).
655655
d: The data object containing the current state and output arrays (device).
656656
out: qM - dt * qDeriv (derivatives of smooth forces w.r.t velocities).
657+
658+
Raises:
659+
NotImplementedError: If model has delay history buffers (nhistory > 0).
657660
"""
661+
if m.nhistory > 0:
662+
raise NotImplementedError("derivatives are not supported for models with delays")
658663
qMi = m.qM_fullm_i
659664
qMj = m.qM_fullm_j
660665

mujoco_warp/_src/forward.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from mujoco_warp._src import collision_driver
2121
from mujoco_warp._src import constraint
2222
from mujoco_warp._src import derivative
23+
from mujoco_warp._src import history
2324
from mujoco_warp._src import island
2425
from mujoco_warp._src import math
2526
from mujoco_warp._src import passive
@@ -302,6 +303,9 @@ def _advance(m: Model, d: Data, qacc: wp.array, qvel: Optional[wp.array] = None)
302303
outputs=[d.qpos],
303304
)
304305

306+
# advance history buffers before time advance
307+
history.insert_ctrl_history(m, d)
308+
305309
wp.launch(
306310
_next_time,
307311
dim=d.nworld,
@@ -1098,6 +1102,13 @@ def fwd_actuation(m: Model, d: Data):
10981102
d.actuator_force.zero_()
10991103
return
11001104

1105+
# read delayed ctrl (or direct copy if no delay)
1106+
if m.nhistory > 0:
1107+
ctrl = wp.empty((d.nworld, m.nu), dtype=float)
1108+
history.read_ctrl_delayed(m, d, ctrl)
1109+
else:
1110+
ctrl = d.ctrl
1111+
11011112
wp.launch(
11021113
_actuator_force,
11031114
dim=(d.nworld, m.nu),
@@ -1122,7 +1133,7 @@ def fwd_actuation(m: Model, d: Data):
11221133
m.actuator_acc0,
11231134
m.actuator_lengthrange,
11241135
d.act,
1125-
d.ctrl,
1136+
ctrl,
11261137
d.actuator_length,
11271138
d.actuator_velocity,
11281139
m.opt.disableflags & DisableBit.CLAMPCTRL,

0 commit comments

Comments
 (0)