Add mj_setKeyframe function to save current state in k-th model keyframe.
Fixes #1719. Also improve documentation of `mju_sigmoid`, was previously only documented in changelog. PiperOrigin-RevId: 642637458 Change-Id: I811a0bf8f881c8b76c9a62d2faec8fdec4e7585b
This commit is contained in:
committed by
Copybara-Service
parent
f37f840880
commit
c9bcf8371e
@@ -27,6 +27,7 @@ import numpy as np
|
||||
TEST_XML = r"""
|
||||
<mujoco model="test">
|
||||
<compiler coordinate="local" angle="radian" eulerseq="xyz"/>
|
||||
<size nkey="2"/>
|
||||
<option timestep="0.002" gravity="0 0 -9.81"/>
|
||||
<visual>
|
||||
<global fovy="50" />
|
||||
@@ -745,6 +746,37 @@ class MuJoCoBindingsTest(parameterized.TestCase):
|
||||
# Expect next states to be equal.
|
||||
np.testing.assert_array_equal(state1a, state1b)
|
||||
|
||||
def test_mj_setKeyframe(self): # pylint: disable=invalid-name
|
||||
mujoco.mj_step(self.model, self.data)
|
||||
|
||||
# Test for invalid state spec
|
||||
invalid_key = 2
|
||||
expected_message = (
|
||||
f'mj_setKeyframe: index must be smaller than {invalid_key} (keyframes'
|
||||
' allocated in model)'
|
||||
)
|
||||
with self.assertRaisesWithLiteralMatch(mujoco.FatalError, expected_message):
|
||||
mujoco.mj_setKeyframe(self.model, self.data, invalid_key)
|
||||
|
||||
valid_key = 1
|
||||
time = self.data.time
|
||||
qpos = self.data.qpos.copy()
|
||||
qvel = self.data.qvel.copy()
|
||||
act = self.data.act.copy()
|
||||
mujoco.mj_setKeyframe(self.model, self.data, valid_key)
|
||||
|
||||
# Step, assert that time has changed.
|
||||
mujoco.mj_step(self.model, self.data)
|
||||
self.assertNotEqual(time, self.data.time)
|
||||
|
||||
# Reset to keyframe, assert that time, qpos, qvel, act are the same.
|
||||
mujoco.mj_resetDataKeyframe(self.model, self.data, valid_key)
|
||||
self.assertEqual(time, self.data.time)
|
||||
np.testing.assert_array_equal(qpos, self.data.qpos)
|
||||
np.testing.assert_array_equal(qvel, self.data.qvel)
|
||||
np.testing.assert_array_equal(act, self.data.act)
|
||||
|
||||
|
||||
def test_mj_angmomMat(self): # pylint: disable=invalid-name
|
||||
self.data.qvel = np.ones(self.model.nv, np.float64)
|
||||
mujoco.mj_forward(self.model, self.data)
|
||||
|
||||
@@ -302,6 +302,7 @@ PYBIND11_MODULE(_functions, pymodule) {
|
||||
}
|
||||
return InterceptMjErrors(::mj_setState)(m, d, state.data(), spec);
|
||||
});
|
||||
Def<traits::mj_setKeyframe>(pymodule);
|
||||
Def<traits::mj_addContact>(pymodule);
|
||||
Def<traits::mj_isPyramidal>(pymodule);
|
||||
Def<traits::mj_isSparse>(pymodule);
|
||||
|
||||
Reference in New Issue
Block a user