From 981fa22302fd1686db4ca50ac6e370a0b000fa86 Mon Sep 17 00:00:00 2001 From: Yuval Tassa Date: Sat, 28 May 2022 06:42:48 -0700 Subject: [PATCH] Don't enforce minimum inertia at mesh loading. Inertias of moving bodies are enforced to be greater mjMINVAL at model compilation, there is no need to enforce inertias at mesh load time. Tiny meshes could be static or part of a larger geom assembly, in which case their tiny inertia is not a problem. Also, make error message for small masses/inertias more precise. PiperOrigin-RevId: 451625216 Change-Id: I4b48d7a881e620d6fbb591ec77fbdacc7c03496c --- src/user/user_mesh.cc | 4 +-- src/user/user_model.cc | 2 +- test/user/user_mesh_test.cc | 62 +++++++++++++++++++++++++++++++++++-- 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/src/user/user_mesh.cc b/src/user/user_mesh.cc index e0d6f938..8d99c79f 100644 --- a/src/user/user_mesh.cc +++ b/src/user/user_mesh.cc @@ -1014,8 +1014,8 @@ void mjCMesh::Process(void) { mju_eig3(eigval, eigvec, quattmp, full); // check eigval - SHOULD NOT OCCUR - if (eigval[2] + + + + + + + + )"; + mjModel* model = LoadModelFromString(xml, 0, 0); + ASSERT_THAT(model, testing::NotNull()); + mj_deleteModel(model); +} + +TEST_F(MujocoTest, SmallInertiaLoads) { + static constexpr char xml[] = R"( + + + + + + + + + + + + + )"; + mjModel* model = LoadModelFromString(xml, 0, 0); + ASSERT_THAT(model, testing::NotNull()); + mj_deleteModel(model); +} + +TEST_F(MujocoTest, TinyInertiaFails) { + static constexpr char xml[] = R"( + + + + + + + + + + + + )"; + std::array error; + LoadModelFromString(xml, error.data(), error.size()); + EXPECT_THAT( + error.data(), + HasSubstr( + "mass and inertia of moving bodies must be larger than mjMINVAL")); +} + } // namespace } // namespace mujoco