Skip to content

Commit f8f3f2f

Browse files
committed
delay
1 parent ea7f05b commit f8f3f2f

6 files changed

Lines changed: 1455 additions & 1 deletion

File tree

mujoco_warp/__init__.py

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

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
@@ -251,6 +252,9 @@ def _advance(m: Model, d: Data, qacc: wp.array, qvel: Optional[wp.array] = None)
251252
outputs=[d.qpos],
252253
)
253254

255+
# advance history buffers before time advance
256+
history.insert_ctrl_history(m, d)
257+
254258
wp.launch(
255259
_next_time,
256260
dim=d.nworld,
@@ -841,6 +845,13 @@ def fwd_actuation(m: Model, d: Data):
841845
d.qfrc_actuator.zero_()
842846
return
843847

848+
# read delayed ctrl (or direct copy if no delay)
849+
if m.nhistory > 0:
850+
ctrl = wp.empty((d.nworld, m.nu), dtype=float)
851+
history.read_ctrl_delayed(m, d, ctrl)
852+
else:
853+
ctrl = d.ctrl
854+
844855
wp.launch(
845856
_actuator_force,
846857
dim=(d.nworld, m.nu),
@@ -865,7 +876,7 @@ def fwd_actuation(m: Model, d: Data):
865876
m.actuator_acc0,
866877
m.actuator_lengthrange,
867878
d.act,
868-
d.ctrl,
879+
ctrl,
869880
d.actuator_length,
870881
d.actuator_velocity,
871882
m.opt.disableflags & DisableBit.CLAMPCTRL,

0 commit comments

Comments
 (0)