Add mjModel.tendon_armature (in preparation, not yet implemented)

PiperOrigin-RevId: 743649968
Change-Id: I1d893e3e06afc48b652575bc7837750ab3573670
This commit is contained in:
Yuval Tassa
2025-04-03 12:05:30 -07:00
committed by Copybara-Service
parent f96f3e1c22
commit e1f5ceb65a
14 changed files with 140 additions and 11 deletions
+84 -1
View File
@@ -15,6 +15,7 @@
// Tests for xml/xml_native_reader.cc.
#include <array>
#include <cmath>
#include <limits>
#include <memory>
#include <string>
@@ -1148,6 +1149,88 @@ TEST_F(XMLReaderTest, ParsePolycoef) {
mj_deleteModel(m);
}
TEST_F(XMLReaderTest, TendonArmature) {
static constexpr char xml[] = R"(
<mujoco>
<worldbody>
<site name="a"/>
<body pos="1 0 0">
<joint name="slide" type="slide"/>
<geom size=".1"/>
<site name="b"/>
</body>
</worldbody>
<tendon>
<spatial armature="1.5">
<site site="a"/>
<site site="b"/>
</spatial>
<fixed armature="2.5">
<joint joint="slide" coef="1"/>
</fixed>
<fixed>
<joint joint="slide" coef="2"/>
</fixed>
</tendon>
</mujoco>
)";
std::array<char, 1024> error;
mjModel* m = LoadModelFromString(xml, error.data(), error.size());
EXPECT_THAT(m, NotNull()) << error.data();
EXPECT_EQ(m->ntendon, 3);
EXPECT_FLOAT_EQ(m->tendon_armature[0], 1.5);
EXPECT_FLOAT_EQ(m->tendon_armature[1], 2.5);
EXPECT_FLOAT_EQ(m->tendon_armature[2], 0);
mj_deleteModel(m);
}
TEST_F(XMLReaderTest, TendonArmatureNegative) {
static constexpr char xml[] = R"(
<mujoco>
<worldbody>
<site name="a"/>
<site name="b" pos="1 0 0"/>
</worldbody>
<tendon>
<spatial armature="-1.5">
<site site="a"/>
<site site="b"/>
</spatial>
</tendon>
</mujoco>
)";
std::array<char, 1024> error;
mjModel* m = LoadModelFromString(xml, error.data(), error.size());
EXPECT_THAT(m, IsNull());
EXPECT_THAT(error.data(), HasSubstr("tendon armature cannot be negative"));
}
TEST_F(XMLReaderTest, TendonArmatureGeomWrap) {
static constexpr char xml[] = R"(
<mujoco>
<worldbody>
<site name="a"/>
<geom name="g" type="sphere" size=".1"/>
<site name="b" pos="1 0 0"/>
</worldbody>
<tendon>
<spatial armature="1.5">
<site site="a"/>
<geom geom="g"/>
<site site="b"/>
</spatial>
</tendon>
</mujoco>
)";
std::array<char, 1024> error;
mjModel* m = LoadModelFromString(xml, error.data(), error.size());
EXPECT_THAT(m, IsNull());
EXPECT_THAT(error.data(), HasSubstr("geom wrapping not supported"));
}
// ------------------------ test frame parsing ---------------------------------
TEST_F(XMLReaderTest, ParseFrame) {
static constexpr char xml[] = R"(
@@ -1862,7 +1945,7 @@ TEST_F(XMLReaderTest, CameraInvalidFovyAndSensorsize) {
EXPECT_THAT(error.data(), HasSubstr("line 6"));
}
TEST_F(XMLReaderTest, CameraPricipalRequiresSensorsize) {
TEST_F(XMLReaderTest, CameraPrincipalRequiresSensorsize) {
static constexpr char xml[] = R"(
<mujoco>
<worldbody>