Resizes keyframes before storing them during attach/detach.

Improve keyframe tests.

PiperOrigin-RevId: 685450257
Change-Id: I97aa129c4d7a66f613290605b85657e8081700b6
This commit is contained in:
Alessio Quaglino
2024-10-13 10:01:26 -07:00
committed by Copybara-Service
parent 534aedd47d
commit 52a0149cd1
6 changed files with 199 additions and 67 deletions
+43
View File
@@ -783,6 +783,10 @@ TEST_F(MujocoTest, AttachDifferent) {
<frame name="frame" pos=".1 0 0" euler="0 90 0"/>
</body>
</worldbody>
<keyframe>
<key name="one" time="1" qpos="1 1 1 1 0 0 0"/>
</keyframe>
</mujoco>)";
static constexpr char xml_result[] = R"(
@@ -837,6 +841,7 @@ TEST_F(MujocoTest, AttachDifferent) {
</contact>
<keyframe>
<key name="one" time="1" qpos="1 1 1 1 0 0 0 0"/>
<key name="attached-two-1" time="2" qpos="0 0 0 1 0 0 0 2" act="2 2" ctrl="2 2"/>
<key name="attached-three-1" time="3" qpos="0 0 0 1 0 0 0 3" act="3 3" ctrl="3 3"/>
</keyframe>
@@ -905,6 +910,10 @@ TEST_F(MujocoTest, AttachFrame) {
<frame name="frame" pos=".1 0 0" euler="0 90 0"/>
</body>
</worldbody>
<keyframe>
<key name="one" time="1" qpos="1 1 1 1 0 0 0"/>
</keyframe>
</mujoco>)";
static constexpr char xml_result[] = R"(
@@ -959,6 +968,7 @@ TEST_F(MujocoTest, AttachFrame) {
</contact>
<keyframe>
<key name="one" time="1" qpos="1 1 1 1 0 0 0 0"/>
<key name="attached-two-1" time="2" qpos="0 0 0 1 0 0 0 2" act="2 2" ctrl="2 2"/>
<key name="attached-three-1" time="3" qpos="0 0 0 1 0 0 0 3" act="3 3" ctrl="3 3"/>
</keyframe>
@@ -1356,6 +1366,39 @@ TEST_F(MujocoTest, AttachMocap) {
mj_deleteModel(m_expected);
}
TEST_F(MujocoTest, ReplicateKeyframe) {
static constexpr char xml[] = R"(
<mujoco>
<worldbody>
<replicate count="1" euler="0 0 1.8">
<body name="body" pos="0 -1 0">
<joint type="slide"/>
<geom name="g" size="1"/>
</body>
</replicate>
</worldbody>
<keyframe>
<key name="keyframe" qpos="1"/>
</keyframe>
</mujoco>
)";
std::array<char, 1024> error;
mjModel* m = LoadModelFromString(xml, error.data(), error.size());
EXPECT_THAT(m, testing::NotNull()) << error.data();
EXPECT_THAT(m->ngeom, 1);
EXPECT_THAT(m->nbody, 2);
// check that the keyframe is resized
EXPECT_THAT(m->nkey, 1);
EXPECT_THAT(m->nq, 1);
EXPECT_THAT(m->key_qpos[0], 0);
EXPECT_STREQ(mj_id2name(m, mjOBJ_KEY, 0), "keyframe");
mj_deleteModel(m);
}
TEST_F(MujocoTest, AttachUnnamedAssets) {
static constexpr char cube[] = R"(
v -1 -1 1
+24 -12
View File
@@ -1234,21 +1234,28 @@ TEST_F(XMLReaderTest, ParseReplicate) {
</asset>
<worldbody>
<replicate count="101" euler="0 0 1.8">
<body name="body" pos="0 -1 0">
<joint type="slide"/>
<geom name="g" size="1"/>
</body>
</replicate>
<replicate count="2" offset="1 0 0">
<replicate count="2" offset="0 1 0" sep="_">
<geom name="geom" size="1" pos="0 0 1" material="material"/>
<site name="site" pos="1 0 0"/>
</replicate>
</replicate>
<replicate count="101" euler="0 0 1.8">
<geom name="g" size="1" pos="0 -1 0"/>
</replicate>
</worldbody>
<sensor>
<framepos name="sensor" objtype="site" objname="site"/>
</sensor>
<keyframe>
<key name="keyframe" qpos="1"/>
</keyframe>
</mujoco>
)";
@@ -1287,14 +1294,19 @@ TEST_F(XMLReaderTest, ParseReplicate) {
}
// check that the final pose is correct
int n = 104;
EXPECT_NEAR(m->geom_pos[3*n+0], 0, 1e-8);
EXPECT_NEAR(m->geom_pos[3*n+1], 1, 1e-8);
EXPECT_EQ(m->geom_pos[3*n+2], 0);
EXPECT_NEAR(m->geom_quat[4*n+0], 0, 1e-8);
EXPECT_EQ(m->geom_quat[4*n+1], 0);
EXPECT_EQ(m->geom_quat[4*n+2], 0);
EXPECT_EQ(m->geom_quat[4*n+3], 1);
int n = m->nbody-1;
EXPECT_THAT(m->nbody, 102);
EXPECT_NEAR(m->body_pos[3*n+0], 0, 1e-8);
EXPECT_NEAR(m->body_pos[3*n+1], 1, 1e-8);
EXPECT_EQ(m->body_pos[3*n+2], 0);
EXPECT_NEAR(m->body_quat[4*n+0], 0, 1e-8);
EXPECT_EQ(m->body_quat[4*n+1], 0);
EXPECT_EQ(m->body_quat[4*n+2], 0);
EXPECT_EQ(m->body_quat[4*n+3], 1);
// check that the pending keyframes are lost while detaching
EXPECT_THAT(m->nkey, 0);
EXPECT_THAT(m->nq, 101);
mj_deleteModel(m);
}