Mujoco - shivamvats/notes GitHub Wiki

  • Mujoco used generalized coordinates meaning I cannot directly set the Cartesian coordinates of a body, the end-effector, for example. I would need to first do inverse kinematics.
  • Floating Bodies: are connected to the world with a free joint and are represented with mjData.qpos and mjData.qvel. These can be manipulated directly.

Kinematics

  • Bodies Bodies are used to construct the kinematic tree and are containers for other elements, including geoms and sites. They have inertial properties but don't have appearance or collision geometry.
  • Geoms are used to specify appearance and collision geometry.
  • Sites are light geoms. They have the same appearance but do not participate in collisions. They can be used to specify points or frame of interest.
  • The results of forward kinematics are available in mjData as
    • xpos, xquat and xmat for bodies
    • geom_xpos and geom_xmat for geoms
    • site_xpos and site_xmat for sites
  • Coordinate Frames MJCF file always expresses coordinate frames in the local frame. The frame of a body is expressed relative to its parent and the frame of a geom, site, etc, is expressed relative to the body that owns it. See Coordinate Frames for details.

Contacts

This struct maintains contact related information for all relevant geom pairs.

  • dist: distance between the two geoms. It is positive if no contact, zero if they touch and negative if they penetrate each other.
  • cfrc_ext: 6D spatial vector that stores the [torque, force] in that order w.r.t subtree-com. To get the forces w.r.t the world, use mj_ContactForce.

XML

Actuator

MJCF model has only one general actuator type. However, mujoco provides shortcuts to create general actuators.

Four shortcuts are of my interest:

  • position: creates a position servo with a gain kp.
  • velocity: creates a velocity servo. I need to define two actuators: position and velocity to create a PD controller.
  • motor: this creates a direct-drive actuator.
  • damper: produces a force proportional to both velocity and control.

API

  • State vector represents a generalized state x = (mjData.time, mjData.qpos, mjData.qvel, mjData.act). mjData.act is used only for modelling actuators.
  • Frame orientations are stored as 3x3 matrices: xmat.
  • mjData.qpos and mjData.qvel: joint position and velocity
  • Quantities that start with x are expressed in global coordinate frame. eg, mjData.xpos, mjData.xquat, etc. These are computed by forward kinematics with mj_kinematics or mj_fwdPosition.
  • Quaternions: (w, x, y, z)

Viewer Shortcuts

  • TAB: Switch between cameras
  • SPC: Pause/unpause simulation
  • right-arrow: Forward simulation by one step
  • E: View transforms
  • V: Start/end video recording (saves in /tmp/video_*)
  • T: Take screenshot (saves in /tmp/frame_*)
  • H: Show help menu

Robosuite

MJCF

  • utils.mjcf_utils has methods to construct elements, joints, sites, bodies, etc.

Objects

  • MujocoXMLObject stores object xml within a body with name object. This gets renamed to <prefix>_main in _get_object_subtree when get_obj() is called for merging with another object.
⚠️ **GitHub.com Fallback** ⚠️