Overview
TheKinCharModel class represents a kinematic character model with hierarchical joint structure. It provides functionality for loading character definitions from XML files, performing forward kinematics, converting between rotation representations, and managing joint constraints.
Enums
JointType
Defines the types of joints supported by the character model.GeomType
Defines the types of geometric shapes for collision and visualization.Classes
Joint
Represents a single joint in the character.Name of the joint.
Type of joint (ROOT, HINGE, SPHERICAL, or FIXED).
Axis of rotation for HINGE joints (None for other types).
Joint limits in radians.
Methods
get_dof_dim
Get the number of degrees of freedom for this joint.Number of DOFs (0 for ROOT/FIXED, 1 for HINGE, 3 for SPHERICAL).
dof_to_rot
Convert DOF values to quaternion rotation.rot_to_dof
Convert quaternion rotation to DOF values.Geom
Represents a geometric shape attached to a body.KinCharModel
Main class for kinematic character modeling.Initialization
Constructor
Device (CPU or GPU) for storing character data.
init
Initialize the character model with body hierarchy.Names of all bodies in the character.
Parent index for each body (-1 for root).
Local translation of each body relative to parent (shape: [num_bodies, 3]).
Local rotation of each body as quaternions (shape: [num_bodies, 4]).
Joint definitions for each body.
Geometric shapes for each body (for collision/visualization).
Names of bodies that can make contact. If None, all bodies are contact bodies.
load_char_file
Load character definition from a MuJoCo XML file.Path to the MuJoCo XML character definition file.
Core Methods
forward_kinematics
Compute world-space positions and rotations for all bodies.Root body position (shape: […, 3]).
Root body rotation as quaternion (shape: […, 4]).
Joint rotations as quaternions (shape: […, num_joints-1, 4]).
Tuple containing:
body_pos(torch.Tensor): World positions of all bodies (shape: […, num_bodies, 3])body_rot(torch.Tensor): World rotations of all bodies (shape: […, num_bodies, 4])
dof_to_rot
Convert DOF values to joint rotations.DOF values (shape: […, dof_size]).
Joint rotations as quaternions (shape: […, num_joints-1, 4]).
rot_to_dof
Convert joint rotations to DOF values.Joint rotations as quaternions (shape: […, num_joints-1, 4]).
DOF values (shape: […, dof_size]).
compute_dof_vel
Compute DOF velocities from two consecutive joint rotation frames.Joint rotations at time t (shape: […, num_joints-1, 4]).
Joint rotations at time t+dt (shape: […, num_joints-1, 4]).
Time step between frames.
DOF velocities (shape: […, dof_size]).
compute_frame_dof_vel
Compute DOF velocities for a sequence of motion frames.Sequence of joint rotations (shape: […, num_frames, num_joints-1, 4]).
Time step between frames.
DOF velocities for all frames (shape: […, num_frames, dof_size]).
apply_joint_dof_limits
Clamp DOF values to joint limits.DOF values to clamp (shape: […, dof_size]).
Clamped DOF values within joint limits.
construct_frame_data
Combine root and joint data into a single motion frame tensor.Root positions.
Root rotations as quaternions.
Joint rotations as quaternions.
Combined motion frame with root_pos, root_rot (exp map), and joint_dof.
Body and Joint Queries
get_num_bodies
Total number of bodies in the character.
get_num_joints
Total number of joints (including root).
get_num_non_root_joints
Number of non-root joints.
get_dof_size
Total number of degrees of freedom.
get_body_names
List of all body names.
get_body_name
Body index.
Name of the body.
get_body_id
Name of the body.
Index of the body.
get_joint_id
Name of the body.
Joint index (body index - 1, since joint arrays exclude root).
get_joint
Joint index (must be > 0).
Joint object at the specified index.
get_parent_id
Body/joint index.
Index of the parent body (-1 for root).
get_joint_dof_idx
Joint index.
Starting index of this joint’s DOFs in the DOF vector.
get_joint_dof_dim
Joint index.
Number of DOFs for this joint.
Contact Bodies
get_num_contact_bodies
Number of bodies designated for contact detection.
is_contact_body
Name of the body.
True if the body is a contact body.
get_contact_body_id
Name of the contact body.
Index within the contact body array.
get_contact_body_ids
Tensor of contact body indices.
get_contact_body_name
Contact body index.
Name of the contact body.
create_full_contact_tensor
Expand a contact tensor from contact bodies to all bodies.Contact labels for contact bodies (shape: […, num_contact_bodies]).
Contact labels for all bodies (shape: […, num_bodies]). Non-contact bodies have label 0.
Geometry Methods
get_geoms
Body index.
List of geometric shapes attached to the body.
get_body_geom_names
List of all geometry names in the character.
find_lowest_point
Find the lowest point on the character given body poses.World positions of all bodies (shape: […, num_bodies, 3]).
World rotations of all bodies (shape: […, num_bodies, 4]).
3D position of the lowest point (shape: […, 3]).
Bone Length Methods
get_bone_length
Get the length of a bone (distance from parent joint).Body index or name.
Length of the bone in meters.
set_bone_length
Set the length of a bone.Body index or name.
New bone length in meters.
Whether to update the stored original length.
Whether to scale attached geometries.
scale_bone_length
Scale the length of a bone by a multiplicative factor.Body index or name.
Multiplicative scale factor.
Whether to update the stored original length.
Whether to scale attached geometries.
Utility Methods
get_copy
Create a deep copy of the character model.Device for the copy. If None, uses the same device.
Deep copy of the character model.
output_xml
Export the character to a MuJoCo XML file.Path where the XML file should be written.