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

The Env: owns model/data, robots, scene slots and the viewer. More...

Classes

struct  mj_kdl::ResetOptions
struct  mj_kdl::ResetInfo
struct  mj_kdl::ResetContext
struct  mj_kdl::Env

Functions

Status mj_kdl::init_env (Env *env, const SceneSpec *spec)
ResetInfo mj_kdl::reset (Env *env, const ResetOptions *options=nullptr)
void mj_kdl::cleanup (Env *env)
bool mj_kdl::step (Env *env)
void mj_kdl::update (Env *env)
void mj_kdl::set_body_pose (Env *env, const char *body_name, const double pos[3], const double *quat=nullptr)

Detailed Description

The Env: owns model/data, robots, scene slots and the viewer.

init_env() builds it; step(), update() and reset() drive it; cleanup(Env *) frees it. reset() re-seeds every part it holds.

Function Documentation

◆ cleanup()

void mj_kdl::cleanup ( Env * env)

Close the viewer, free the model/data and forget the robots (which are not deleted).

◆ init_env()

◆ reset()

ResetInfo mj_kdl::reset ( Env * env,
const ResetOptions * options = nullptr )

Reset everything env holds: MuJoCo data to the keyframe (or the model default); every registered robot's ports (holding the reset pose, a requested ctrl_mode kept) and F/T readings, and every scene slot, re-seeded; then Env::on_reset; then measurements read from the result. The simulate UI's reset button does the same.

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

◆ set_body_pose()

void mj_kdl::set_body_pose ( Env * env,
const char * body_name,
const double pos[3],
const double * quat = nullptr )

Teleport a free-floating body to a world-frame position and optionally a world-frame orientation, then zero its velocity. body_name must identify a body that owns a mjJNT_FREE joint. quat is [x, y, z, w] like every quaternion in this API; nullptr sets identity.

Referenced by main(), and mj_kdl_examples::place_cube().

◆ step()

bool mj_kdl::step ( Env * env)

Advance env one timestep: mj_step2() then mj_step1() (MuJoCo's split mj_step()). Afterwards joint state, body frames and position/velocity sensors all describe the new state; force and acceleration sensors describe the step just taken. With the viewer open it also honours its pause, perturbation and recording, and does nothing while every robot is paused.

Returns
false once the viewer window is closed; always true headless.

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

◆ update()

void mj_kdl::update ( Env * env)

One control cycle for everything env holds: read, then apply. Robots: qpos -> jnt_pos_msr, qvel -> jnt_vel_msr, qfrc_actuator -> jnt_trq_msr (only the active mode's actuators produce force, so this is the drive torque in every mode), F/T wrenches; then the active mode's command to its actuators' ctrl (gear applied, ctrlrange clamped). If ctrl_mode was changed directly, the switch runs first (set_control_mode()). Outside TORQUE, gravity on the bodies a robot's joints carry is compensated (body_gravcomp), so a servo holds its setpoint; in TORQUE the command carries gravity itself. Scene slots: joints and free bodies sampled from qpos/qvel; wrenches into xfrc_applied (zeros included), actuator commands into ctrl.

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