|
Mujoco KDL Wrapper
0.1.0
MuJoCo + KDL bridge for robot kinematics and dynamics
|
Build and modify MuJoCo scenes from MJCF specifications. More...
Functions | |
| bool | mj_kdl::save_model_xml (const mjModel *model, const char *path) |
| bool | mj_kdl::attach_to_spec (mjSpec *robot_spec, const AttachmentSpec *a) |
| bool | mj_kdl::build_scene (mjModel **out_model, mjData **out_data, const SceneSpec *spec) |
| void | mj_kdl::destroy_scene (mjModel *model, mjData *data) |
| bool | mj_kdl::scene_add_object (mjModel **model, mjData **data, SceneSpec *spec, const SceneObject &obj) |
| bool | mj_kdl::scene_add_object (Env *env, const SceneObject &obj) |
| bool | mj_kdl::scene_remove_object (mjModel **model, mjData **data, SceneSpec *spec, const std::string &name) |
| bool | mj_kdl::scene_remove_object (Env *env, const std::string &name) |
| std::string | mj_kdl::scene_object_site_name (const SceneObject &obj, const char *site_name) |
| bool | mj_kdl::get_site_frame (const mjModel *model, mjData *data, const char *site_name, KDL::Frame *out) |
| bool | mj_kdl::get_body_frame (const mjModel *model, mjData *data, const char *body_name, KDL::Frame *out) |
| std::vector< std::string > | mj_kdl::get_camera_names (const mjModel *model) |
Build and modify MuJoCo scenes from MJCF specifications.
The primary entry point is build_scene(). Use scene_add_object() and scene_remove_object() to dynamically modify a running scene.
| bool mj_kdl::attach_to_spec | ( | mjSpec * | robot_spec, |
| const AttachmentSpec * | a | ||
| ) |
Apply one attachment to an arm spec using the MuJoCo spec API (mjs_attach). Parses a->mjcf_path, attaches its first root body under a->attach_to with the given pos/euler offset, prefixes all element names with a->prefix, and registers contact exclusions via mjs_addExclude. Can be called repeatedly to build a chain: each subsequent a->attach_to may reference any body added by prior calls.
| [in,out] | robot_spec | Accumulated robot spec to attach into. |
| [in] | a | Attachment; a->mjcf_path must not be null. |
| bool mj_kdl::build_scene | ( | mjModel ** | out_model, |
| mjData ** | out_data, | ||
| const SceneSpec * | spec | ||
| ) |
Build a MuJoCo scene from one or more robots using the MuJoCo spec API. This is the primary scene-building function.
For each RobotSpec: mj_parseXML loads the root MJCF, then attach_to_spec() applies each entry in RobotSpec::attachments in order (mount, sensor, gripper, etc.), and mjs_attach places the complete robot spec at the given position. A single mj_compile produces the final model – no intermediate XML files are written.
| [out] | out_model | Newly allocated MuJoCo model; caller frees via destroy_scene(). |
| [out] | out_data | Newly allocated MuJoCo data; caller frees via destroy_scene(). |
| [in] | spec | Scene description: robots (with attachment chains), table, objects, timestep, gravity, floor, skybox. |
Referenced by main(), main(), DualArmTest::SetUp(), InitTest::SetUp(), MjcfLoadTest::SetUp(), MjcfGripperTest::SetUp(), MjcfPickTest::SetUp(), MjcfPosCtrlTest::SetUp(), MjcfTrqCtrlTest::SetUp(), MjcfVelCtrlTest::SetUp(), and TableSceneTest::SetUp().
| void mj_kdl::destroy_scene | ( | mjModel * | model, |
| mjData * | data | ||
| ) |
Free a model/data pair allocated by any scene-building function.
| [in] | model | Model to free (may be null). |
| [in] | data | Data to free (may be null). |
Referenced by main(), main(), DualArmTest::TearDown(), InitTest::TearDown(), MjcfLoadTest::TearDown(), MjcfGripperTest::TearDown(), MjcfPickTest::TearDown(), MjcfPosCtrlTest::TearDown(), MjcfTrqCtrlTest::TearDown(), MjcfVelCtrlTest::TearDown(), and TableSceneTest::TearDown().
| bool mj_kdl::get_body_frame | ( | const mjModel * | model, |
| mjData * | data, | ||
| const char * | body_name, | ||
| KDL::Frame * | out | ||
| ) |
Read a named MuJoCo body as a world-frame KDL frame. Calls mj_forward() before reading xpos/xmat.
| std::vector< std::string > mj_kdl::get_camera_names | ( | const mjModel * | model | ) |
Return the names of all cameras in a compiled model. Includes cameras from robot MJCFs (e.g. the Kinova wrist camera) and any cameras added via SceneSpec::cameras.
Referenced by main().
| bool mj_kdl::get_site_frame | ( | const mjModel * | model, |
| mjData * | data, | ||
| const char * | site_name, | ||
| KDL::Frame * | out | ||
| ) |
Read a named MuJoCo site as a world-frame KDL frame. Calls mj_forward() before reading site_xpos/site_xmat.
Referenced by main(), and TableSceneTest::SetUp().
| bool mj_kdl::save_model_xml | ( | const mjModel * | model, |
| const char * | path | ||
| ) |
Save the compiled model to an MJCF XML file for later reloading via build_scene(). Must be called with the model returned by the most recent build_scene() call - MuJoCo only retains the last compiled model's XML internally. Typical use: build a combined scene (dual-arm, arm+gripper, ...) once, save it, then reload via build_scene() in subsequent runs to skip all build steps.
| model | Model to save; must be the most recently compiled model. |
| path | Output path for the MJCF XML file. |
| bool mj_kdl::scene_add_object | ( | Env * | env, |
| const SceneObject & | obj | ||
| ) |
| bool mj_kdl::scene_add_object | ( | mjModel ** | model, |
| mjData ** | data, | ||
| SceneSpec * | spec, | ||
| const SceneObject & | obj | ||
| ) |
Add an object to the scene by appending it to spec->objects and rebuilding the model. The old model/data are freed; new ones replace them. Any Robot handles sharing the old model/data become stale - call init_robot() again on the new model/data after this call.
| [in,out] | model | Current model pointer; updated to new model on success. |
| [in,out] | data | Current data pointer; updated to new data on success. |
| [in,out] | spec | Scene spec; obj is appended to spec->objects. |
| [in] | obj | Object to add. |
| std::string mj_kdl::scene_object_site_name | ( | const SceneObject & | obj, |
| const char * | site_name | ||
| ) |
Return the compiled MuJoCo name for a site inside an MJCF-backed SceneObject. build_scene() prefixes all MJCF asset element names with obj.name + "_".
Referenced by main(), and TableSceneTest::SetUp().
| bool mj_kdl::scene_remove_object | ( | Env * | env, |
| const std::string & | name | ||
| ) |
| bool mj_kdl::scene_remove_object | ( | mjModel ** | model, |
| mjData ** | data, | ||
| SceneSpec * | spec, | ||
| const std::string & | name | ||
| ) |
Remove a named object from the scene by erasing it from spec->objects and rebuilding the model. The old model/data are freed; new ones replace them. Any Robot handles sharing the old model/data become stale - call init_robot() again on the new model/data after this call.
| [in,out] | model | Current model pointer; updated to new model on success. |
| [in,out] | data | Current data pointer; updated to new data on success. |
| [in,out] | spec | Scene spec; named object removed from spec->objects. |
| [in] | name | Name of the object to remove. |