Support joint actuator authoring in Mjcf SdfFileFormat plugin.
PiperOrigin-RevId: 776202325 Change-Id: I8503dd98c1b64502550b879e70039ae568517508
This commit is contained in:
committed by
Copybara-Service
parent
21bae3a388
commit
1e319aebed
@@ -171,6 +171,7 @@ class ModelWriter {
|
|||||||
: spec_(spec), model_(model), data_(data), class_path_("/Bad_Path") {
|
: spec_(spec), model_(model), data_(data), class_path_("/Bad_Path") {
|
||||||
body_paths_ = std::vector<pxr::SdfPath>(model->nbody);
|
body_paths_ = std::vector<pxr::SdfPath>(model->nbody);
|
||||||
site_paths_ = std::vector<pxr::SdfPath>(model->nsite);
|
site_paths_ = std::vector<pxr::SdfPath>(model->nsite);
|
||||||
|
joint_paths_ = std::vector<pxr::SdfPath>(model->njnt);
|
||||||
}
|
}
|
||||||
~ModelWriter() { mj_deleteModel(model_); }
|
~ModelWriter() { mj_deleteModel(model_); }
|
||||||
|
|
||||||
@@ -221,6 +222,8 @@ class ModelWriter {
|
|||||||
std::vector<pxr::SdfPath> body_paths_;
|
std::vector<pxr::SdfPath> body_paths_;
|
||||||
// Mapping from Mujoco site id to SdfPath.
|
// Mapping from Mujoco site id to SdfPath.
|
||||||
std::vector<pxr::SdfPath> site_paths_;
|
std::vector<pxr::SdfPath> site_paths_;
|
||||||
|
// Mapping from Mujoco joint id to SdfPath.
|
||||||
|
std::vector<pxr::SdfPath> joint_paths_;
|
||||||
// Mapping from mesh names to Mesh prim path.
|
// Mapping from mesh names to Mesh prim path.
|
||||||
std::unordered_map<std::string, pxr::SdfPath> mesh_paths_;
|
std::unordered_map<std::string, pxr::SdfPath> mesh_paths_;
|
||||||
// Whether to write physics data.
|
// Whether to write physics data.
|
||||||
@@ -935,6 +938,9 @@ class ModelWriter {
|
|||||||
actuator->trntype == mjtTrn::mjTRN_SLIDERCRANK) {
|
actuator->trntype == mjtTrn::mjTRN_SLIDERCRANK) {
|
||||||
int site_id = mj_name2id(model_, mjOBJ_SITE, actuator->target->c_str());
|
int site_id = mj_name2id(model_, mjOBJ_SITE, actuator->target->c_str());
|
||||||
transmission_path = site_paths_[site_id];
|
transmission_path = site_paths_[site_id];
|
||||||
|
} else if (actuator->trntype == mjtTrn::mjTRN_JOINT) {
|
||||||
|
int joint_id = mj_name2id(model_, mjOBJ_JOINT, actuator->target->c_str());
|
||||||
|
transmission_path = joint_paths_[joint_id];
|
||||||
} else {
|
} else {
|
||||||
TF_WARN(UnsupportedActuatorTypeError,
|
TF_WARN(UnsupportedActuatorTypeError,
|
||||||
"Unsupported actuator type for actuator %d",
|
"Unsupported actuator type for actuator %d",
|
||||||
@@ -1711,6 +1717,9 @@ class ModelWriter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (joint_id >= 0) {
|
||||||
|
joint_paths_[joint_id] = joint_path;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteCamera(mjsCamera *spec_cam, const mjsBody *body) {
|
void WriteCamera(mjsCamera *spec_cam, const mjsBody *body) {
|
||||||
|
|||||||
@@ -1503,6 +1503,31 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestMjcPhysicsActuatorGeneral) {
|
|||||||
pxr::VtDoubleArray{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}});
|
pxr::VtDoubleArray{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(MjcfSdfFileFormatPluginTest, TestMjcPhysicsJointActuator) {
|
||||||
|
static constexpr char xml[] = R"(
|
||||||
|
<mujoco model="test">
|
||||||
|
<worldbody>
|
||||||
|
<body name="axle">
|
||||||
|
<body name="rod">
|
||||||
|
<joint name="rod_hinge" type="hinge"/>
|
||||||
|
<geom name="box" type="box" size=".05 .05 .05" density="1234"/>
|
||||||
|
</body>
|
||||||
|
</body>
|
||||||
|
</worldbody>
|
||||||
|
<actuator>
|
||||||
|
<general
|
||||||
|
name="general"
|
||||||
|
joint="rod_hinge"
|
||||||
|
/>
|
||||||
|
</actuator>
|
||||||
|
</mujoco>
|
||||||
|
)";
|
||||||
|
auto stage = OpenStageWithPhysics(xml);
|
||||||
|
|
||||||
|
EXPECT_PRIM_API_APPLIED(stage, "/test/axle/rod/rod_hinge",
|
||||||
|
pxr::MjcPhysicsActuatorAPI);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(MjcfSdfFileFormatPluginTest, TestMjcPhysicsBodyActuator) {
|
TEST_F(MjcfSdfFileFormatPluginTest, TestMjcPhysicsBodyActuator) {
|
||||||
static constexpr char xml[] = R"(
|
static constexpr char xml[] = R"(
|
||||||
<mujoco model="test">
|
<mujoco model="test">
|
||||||
|
|||||||
Reference in New Issue
Block a user