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
andmjData.qvel
. These can be manipulated directly.
- 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
andxmat
for bodies -
geom_xpos
andgeom_xmat
for geoms -
site_xpos
andsite_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.
This struct maintains contact related information for all relevant geom
pairs.
-
dist
: distance between the twogeoms
. It ispositive
if no contact,zero
if they touch andnegative
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, usemj_ContactForce
.
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.
- 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
andmjData.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 withmj_kinematics
ormj_fwdPosition
.
-
Quaternions:
(w, x, y, z)
-
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
-
utils.mjcf_utils
has methods to construct elements, joints, sites, bodies, etc.
-
MujocoXMLObject
stores object xml within a body with nameobject
. This gets renamed to<prefix>_main
in_get_object_subtree
whenget_obj()
is called for merging with another object.