Fix tactile sensor body validation.
PiperOrigin-RevId: 914870657 Change-Id: I57565b4975e0cd7eb1b1ffa199e451a5c5bc0a6e
This commit is contained in:
committed by
Copybara-Service
parent
17fbc0aeef
commit
e1f5534b5f
@@ -2072,8 +2072,7 @@ const char* mj_validateReferences(const mjModel* m) {
|
|||||||
return "Invalid model: invalid sensor_refid";
|
return "Invalid model: invalid sensor_refid";
|
||||||
}
|
}
|
||||||
if (sensor_type == mjSENS_TACTILE) {
|
if (sensor_type == mjSENS_TACTILE) {
|
||||||
int obj_id = m->sensor_objid[i];
|
int parent_body = m->geom_bodyid[m->sensor_refid[i]];
|
||||||
int parent_body = m->geom_bodyid[obj_id];
|
|
||||||
int collision_geoms = 0;
|
int collision_geoms = 0;
|
||||||
for (int b = 0; b < m->body_geomnum[parent_body]; ++b) {
|
for (int b = 0; b < m->body_geomnum[parent_body]; ++b) {
|
||||||
int geom_id = m->body_geomadr[parent_body]+b;
|
int geom_id = m->body_geomadr[parent_body]+b;
|
||||||
|
|||||||
@@ -1784,5 +1784,34 @@ TEST_F(SensorTest, InsideSiteFlexBody) {
|
|||||||
mj_deleteModel(m);
|
mj_deleteModel(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test that a tactile sensor's compile-time body-collision check correctly
|
||||||
|
// uses the referenced Geom ID instead of mistakenly indexing by Mesh ID.
|
||||||
|
TEST_F(SensorTest, TactileMeshIdMismatchedValidator) {
|
||||||
|
static constexpr char xml[] = R"(
|
||||||
|
<mujoco>
|
||||||
|
<asset>
|
||||||
|
<mesh name="sensor_mesh" builtin="sphere" params="0"/>
|
||||||
|
</asset>
|
||||||
|
<worldbody>
|
||||||
|
<body>
|
||||||
|
<geom size="0.1" contype="0" conaffinity="0"/>
|
||||||
|
</body>
|
||||||
|
<body>
|
||||||
|
<geom name="sensor_geom" type="mesh" mesh="sensor_mesh"/>
|
||||||
|
</body>
|
||||||
|
</worldbody>
|
||||||
|
<sensor>
|
||||||
|
<tactile geom="sensor_geom" mesh="sensor_mesh"/>
|
||||||
|
</sensor>
|
||||||
|
</mujoco>
|
||||||
|
)";
|
||||||
|
|
||||||
|
char error[1024] = {0};
|
||||||
|
mjModel* m = LoadModelFromString(xml, error, sizeof(error));
|
||||||
|
ASSERT_THAT(m, NotNull()) << error;
|
||||||
|
|
||||||
|
mj_deleteModel(m);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace mujoco
|
} // namespace mujoco
|
||||||
|
|||||||
Reference in New Issue
Block a user