Mujoco KDL Wrapper  0.5.1
MuJoCo + KDL bridge for robot kinematics and dynamics
Loading...
Searching...
No Matches
Scene Building

Build and modify MuJoCo scenes from MJCF specifications. More...

Classes

struct  mj_kdl::SceneJointReading
struct  mj_kdl::SceneJointSlot
struct  mj_kdl::SceneFreeBodyReading
struct  mj_kdl::SceneFreeBodySlot
struct  mj_kdl::SceneWrenchCommand
struct  mj_kdl::SceneWrenchSlot
struct  mj_kdl::SceneActuatorCommand
struct  mj_kdl::SceneActuatorSlot
struct  mj_kdl::SceneState

Functions

Status mj_kdl::save_model_xml (const mjModel *model, const char *path)
Status mj_kdl::build_scene (mjModel **out_model, mjData **out_data, const SceneSpec *spec)
void mj_kdl::destroy_scene (mjModel *model, mjData *data)
SceneJointSlot * mj_kdl::bind_scene_joint (SceneState *s, const char *joint_name)
SceneFreeBodySlot * mj_kdl::bind_scene_free_body (SceneState *s, const char *body_name)
SceneWrenchSlot * mj_kdl::bind_scene_wrench (SceneState *s, const char *body_name)
SceneActuatorSlot * mj_kdl::bind_scene_actuator (SceneState *s, const char *name)
Status mj_kdl::scene_add_object (Env *env, const SceneObject &obj)
Status mj_kdl::scene_remove_object (Env *env, const std::string &name)
bool mj_kdl::get_site_frame (Env *env, const char *site_name, KDL::Frame *out)
bool mj_kdl::get_body_frame (Env *env, const char *body_name, KDL::Frame *out)

Detailed Description

Build and modify MuJoCo scenes from MJCF specifications.

init_env() builds the scene into an Env. Use scene_add_object() and scene_remove_object() to modify a running Env; bind scene slots (joints, free bodies, wrenches, actuators outside a Robot chain) with bind_scene_*().

Function Documentation

◆ bind_scene_actuator()

SceneActuatorSlot * mj_kdl::bind_scene_actuator ( SceneState * s,
const char * name )

Resolve the actuator named, or the one driving the joint of that name, and keep a slot for its command. Rejects a name that reaches no actuator, and a name already bound.

Returns
the slot, or nullptr on failure. The address stays valid across further binds.

Referenced by main(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ bind_scene_free_body()

SceneFreeBodySlot * mj_kdl::bind_scene_free_body ( SceneState * s,
const char * body_name )

Resolve a free-floating body by name and keep a slot for its pose. Rejects an unknown name, a body that owns no mjJNT_FREE joint, and a name already bound.

Returns
the slot, or nullptr on failure. The address stays valid across further binds.

Referenced by main(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ bind_scene_joint()

SceneJointSlot * mj_kdl::bind_scene_joint ( SceneState * s,
const char * joint_name )

Resolve a scalar joint by name and keep a slot for it. Rejects an unknown name, a free or ball joint, and a name already bound.

Returns
the slot, or nullptr on failure. The address stays valid across further binds.

Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ bind_scene_wrench()

SceneWrenchSlot * mj_kdl::bind_scene_wrench ( SceneState * s,
const char * body_name )

Resolve a body by name and keep a slot for the wrench applied to it. Rejects an unknown name and a name already bound.

Returns
the slot, or nullptr on failure. The address stays valid across further binds.

Referenced by main(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ build_scene()

Status 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 mjs_attach 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.

Parameters
[out]out_modelNewly allocated MuJoCo model; caller frees via destroy_scene().
[out]out_dataNewly allocated MuJoCo data; caller frees via destroy_scene().
[in]specScene description: robots (with attachment chains), objects, sites, cameras, timestep, gravity, floor, skybox.
Returns
an empty Status on success, else the error.

Referenced by TEST(), TEST(), TEST(), and TEST_F().

◆ destroy_scene()

void mj_kdl::destroy_scene ( mjModel * model,
mjData * data )

Free a model/data pair allocated by any scene-building function.

Parameters
[in]modelModel to free (may be null).
[in]dataData to free (may be null).

Referenced by TEST(), TEST(), TEST(), TEST(), and TEST_F().

◆ get_body_frame()

bool mj_kdl::get_body_frame ( Env * env,
const char * body_name,
KDL::Frame * out )

Read a named MuJoCo body as a world-frame KDL frame, as get_site_frame() does.

Referenced by main(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ get_site_frame()

bool mj_kdl::get_site_frame ( Env * env,
const char * site_name,
KDL::Frame * out )

Read a named MuJoCo site as a world-frame KDL frame. Recomputes the kinematics only when the state has changed since they were last computed (a direct qpos write included).

Referenced by main(), TableSceneTest::SetUp(), TEST(), TEST(), TEST_F(), TEST_F(), and TEST_F().

◆ save_model_xml()

Status mj_kdl::save_model_xml ( const mjModel * model,
const char * path )

Save a model to an MJCF XML file, including runtime changes to its real-valued fields. Works for any live model from build_scene() or init_env() (adopted ones too), and for the last model loaded with mj_loadXML. Typical use: build a combined scene once, save it, reload it later.

Parameters
modelModel to save.
pathOutput path for the MJCF XML file.
Returns
an empty Status on success, else the error.

Referenced by TEST(), and TEST_F().

◆ scene_add_object()

Status mj_kdl::scene_add_object ( Env * env,
const SceneObject & obj )

Append obj to env->spec.objects and rebuild. Time, and qpos/qvel/act/ctrl of every joint and actuator whose name survives, carry over; robots, scene slots, recorders and the viewer follow the new model; a slot whose name is gone is unbound and skipped.

Returns
an error on failure (a robot or F/T sensor that no longer resolves), env unchanged.

Referenced by TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ scene_remove_object()

Status mj_kdl::scene_remove_object ( Env * env,
const std::string & name )

Remove the named object from env->spec.objects and rebuild, as scene_add_object() does.

Returns
an error if name is not found or the rebuild fails, env unchanged.

Referenced by TEST_F(), TEST_F(), TEST_F(), and TEST_F().