motrixsim#

Exceptions:

ActuatorOverrideDampingTypeError

Raised when the requested damping override does not match the actuator damping type

ActuatorOverrideError

Base class for actuator parameter override errors

ActuatorOverrideInvalidValueError

Raised when an actuator override value is outside the valid domain

ActuatorOverrideUnsupportedTypeError

Raised when an actuator type does not support the requested override

Classes:

Actuator

The base Actuator class provides access to common actuator properties and control.

AdhesionActuator

Adhesion actuator (MJCF <adhesion>).

Body

The Body object represents a rigid body in the scene.

Camera

The Camera object in the scene.

CameraMgr

ContactQuery

DisjointIndices(indices)

FloatingBase

The FloatingBase object represents a floating base in the scene.

GeneralActuator

General actuator (MJCF <general>).

Geom

The Geom object represents a geometry in the scene.

GeomCapsule

Capsule geometry.

GeomCuboid

Cuboid (box) geometry.

GeomCylinder

Cylinder geometry.

GeomEllipsoid

Ellipsoid geometry.

GeomHField

Height field geometry.

GeomInfinitePlane

Infinite plane geometry.

GeomMesh

Mesh geometry.

GeomPlane

Sized plane geometry.

GeomSphere

Sphere geometry.

HField

The HField object represents a height field terrain in the scene.

Joint

The Joint object represents a joint in the scene.

Keyframe

The Keyframe object represents a keyframe in the scene.

Link

The Link object represents a kinematic link in the scene.

Mocap

The Mocap object represents a motion capture body in the scene.

MotorActuator

Motor actuator (MJCF <motor>).

Options

The Options object represents the simulation options.

PositionActuator

Position actuator (MJCF <position>).

SceneData(model[, batch])

The SceneData object represents the simulation state.

SceneModel

The SceneModel object represents the entire simulation world.

Shape

The source shape type of a high-level geometry.

Site

The Site object represents a reference point or marker in the scene.

TerrainScanner(terrain, frame, offsets[, ...])

A scanner object for batched frame-relative terrain height sampling.

VelocityActuator

Velocity actuator (MJCF <velocity>).

Functions:

forward_kinematic(model, data)

Run forward kinematic only.

load_mjcf_str(mjcf)

Load a model from a string containing MJCF data.

load_model(path)

Load a model from the given file path.

step(model, data)

Advance the simulation by one step.

exception motrixsim.ActuatorOverrideDampingTypeError#

基类:ActuatorOverrideError

Raised when the requested damping override does not match the actuator damping type

exception motrixsim.ActuatorOverrideError#

基类:ValueError

Base class for actuator parameter override errors

exception motrixsim.ActuatorOverrideInvalidValueError#

基类:ActuatorOverrideError

Raised when an actuator override value is outside the valid domain

exception motrixsim.ActuatorOverrideUnsupportedTypeError#

基类:ActuatorOverrideError

Raised when an actuator type does not support the requested override

class motrixsim.Actuator#

基类:object

The base Actuator class provides access to common actuator properties and control.

All actuator types share the same underlying force generation equation:

force = gain * activation + bias - stiffness * position - damping * velocity

where activation is derived from the control signal (possibly filtered by activation dynamics), and position / velocity are the current state of the actuator target (e.g., joint angle and joint velocity).

Typed subclasses provide type-specific parameter override methods:

Methods:

get_ctrl(data)

Get the control value of the actuator.

set_ctrl(data, ctrl)

Set the control value of the actuator.

Attributes:

ctrl_range

The control range of the actuator.

damping_type

The damping parameterization used by this actuator.

index

The index of the actuator in the simulation world.

name

The name of the actuator.

target_name

The name of the actuator target.

target_type

The type of the actuator target.

typ

The type of the actuator.

get_ctrl(data)#

Get the control value of the actuator.

参数:

data (SceneData) -- The scene data.

返回:

The current control value of the actuator. Shape: (*data.shape, )

返回类型:

NDArray[float]

set_ctrl(data, ctrl)#

Set the control value of the actuator.

参数:
  • data (SceneData) -- The scene data to store the control value.

  • ctrl (float | NDArray[float]) -- The control value to set. - Shape (): Single value applied to all batches - Shape: (*data.shape,): Per-batch values

ctrl_range#

The control range of the actuator.

Returns None if not set.

Type:

Optional[Tuple[float, float]]

damping_type#

The damping parameterization used by this actuator.

DampingType.Kv means absolute damping coefficient, and DampingType.Dampratio means damping ratio relative to critical damping.

Type:

DampingType

index#

The index of the actuator in the simulation world.

Type:

int

name#

The name of the actuator.

Return "None" if not set.

Type:

Optional[str]

target_name#

The name of the actuator target. (e.g., joint name, tendon name).

Type:

str

target_type#

The type of the actuator target.

valid values are:

  • "floating_base": For floating base actuators.

  • "joint": For joint actuators.

  • "tendon": For tendon actuators.

Type:

str

typ#

The type of the actuator.

valid values are:

  • "general": General actuator.

  • "position": Position servo. The ctrl represents the target position

  • "velocity": Velocity servo. The ctrl represents the target velocity

  • "motor": The ctrl represents the torque or force

Type:

str

class motrixsim.AdhesionActuator#

基类:Actuator

Adhesion actuator (MJCF <adhesion>). Generates adhesion force on contact surfaces.

No additional parameter override methods. The control value scales the adhesion force.

class motrixsim.Body#

基类:object

The Body object represents a rigid body in the scene.

This class provides access to the properties and state of a rigid body in the simulation. It allows you to retrieve information about the body's name, floating base, pose, and DoF positions and velocities.

Methods:

get_dof_pos_indices([include_floatingbase])

Get the indices of the DoF positions of the body.

get_dof_vel_indices([include_floatingbase])

Get the indices of the DoF velocities of the body.

get_joint_dof_pos(data)

Get the DoF positions of all joints on the body.

get_joint_dof_vel(data)

Get the DoF velocities of all joints on the body.

get_pose(data)

Get the world pose of the body.

get_position(data)

Get the world position of the body.

get_rotation(data)

Get the world rotation of the body as a quaternion.

get_rotation_mat(data)

Get the world rotation of the body as a rotation matrix.

set_actuator_ctrls(data, ctrls)

Set the control values for all actuators on this body.

set_dof_pos(data, dof_pos[, ...])

Set the DoF positions of the body.

set_dof_vel(data, dof_vel[, ...])

Set the DoF velocities of the body.

Attributes:

actuators

The list of actuators associated with this body.

base_link

The base link of this body.

floatingbase

The floating base object.

index

is_mocap

Whether the body is a mocap (kinematic) body.

mocap

Convert this body to a mocap object if it is a mocap body.

model

name

The name of the body.

num_actuators

The number of actuators associated with this body.

num_joint_dof_pos

The number of DoF positions of all joints on the body.

num_joint_dof_vel

The number of DoF velocities of all joints on the body.

num_joints

The number of joints that belong to this body.

num_links

The number of links that belong to this body.

get_dof_pos_indices(include_floatingbase=True)#

Get the indices of the DoF positions of the body.

参数:

include_floatingbase (bool) -- Whether to include the floating base DoF positions indices. If False, only the joint DoF positions indices are returned.

返回:

The DoF position indices. if include_floatingbase is true, shape =

(num_joint_dof_pos() + 6,), else shape = (num_joint_dof_pos(),).

返回类型:

NDArray[int]

get_dof_vel_indices(include_floatingbase=True)#

Get the indices of the DoF velocities of the body.

参数:

include_floatingbase (bool) -- Whether to include the floating base DoF velocities indices. If False, only the joint DoF velocities indices are returned.

返回:

The DoF velocity indices. if include_floatingbase is true, shape =

(num_joint_dof_vel() + 6,), else shape = (num_joint_dof_vel(),).

返回类型:

NDArray[int]

get_joint_dof_pos(data)#

Get the DoF positions of all joints on the body.

参数:

data (SceneData) -- The scene data to query.

返回:

The DoF positions. shape = (*data.shape, num_joint_dof_pos()).

返回类型:

NDArray[float]

备注

If the body has floating base, the floating base DoF positions are NOT included.

get_joint_dof_vel(data)#

Get the DoF velocities of all joints on the body.

参数:

data (SceneData) -- The scene data to query.

返回:

The DoF velocities. shape = (*data.shape,:meth:

body.num_joint_dof_vel).

返回类型:

NDArray[float]

备注

If the body has floating base, the floating base DoF velocities are NOT included.

get_pose(data)#

Get the world pose of the body.

参数:

data (SceneData) -- The scene data to query.

返回:

Shape: (*data.shape, 7). Each pose is a 7-element array with `[x,

返回类型:

NDArray[float]

y, z, i, j, k, w]`.

get_position(data)#

Get the world position of the body.

参数:

data (SceneData) -- The scene data to query.

返回:

Shape: (*data.shape, 3).

返回类型:

NDArray[float]

get_rotation(data)#

Get the world rotation of the body as a quaternion.

参数:

data (SceneData) -- The scene data to query.

返回:

Shape: (*data.shape, 4). Each rotation is a 4-element array with

返回类型:

NDArray[float]

[i, j, k, w].

get_rotation_mat(data)#

Get the world rotation of the body as a rotation matrix.

参数:

data (SceneData) -- The scene data to query.

返回:

Shape: (*data.shape, 3, 3).

返回类型:

NDArray[float]

set_actuator_ctrls(data, ctrls)#

Set the control values for all actuators on this body.

参数:
  • data (SceneData) -- The scene data to modify.

  • ctrls (NDArray[float]) -- The control values to set. Shape = (len(body.actuators),). If the data has batch dimension, ctrls must have the same shape as the data.

备注

The number of control values must match the number of actuators on the body. Use body.actuators to get the list of actuators and their count.

Example:

# For a body with 3 actuators:
body.set_actuator_ctrls(data, [1.0, 0.5, -0.3])  # Set controls for all 3 actuators
set_dof_pos(data, dof_pos, include_floatingbase=True)#

Set the DoF positions of the body.

参数:
  • data (SceneData) -- The scene data to modify.

  • dof_pos (NDArray[float]) -- The DoF positions to set. Shape = (num_joint_dof_pos + 7,) if include_floatingbase is True, else shape = (num_joint_dof_pos,).

  • include_floatingbase (bool) -- Whether the provided dof_pos includes the floating base DoF positions. If True, the first 7 elements of dof_pos are treated as the floating base DoF positions.

set_dof_vel(data, dof_vel, include_floatingbase=True)#

Set the DoF velocities of the body.

参数:
  • data (SceneData) -- The scene data to modify.

  • dof_vel (NDArray[float]) -- The DoF velocities to set. Shape = (num_joint_dof_vel() + 6,) if include_floatingbase is True, else shape =(num_joint_dof_vel(),).

  • include_floatingbase (bool) -- Whether the provided dof_vel includes the floating base DoF velocities. If True, the first 6 elements of dof_vel are treated as the floating base DoF velocities.

actuators#

The list of actuators associated with this body.

Returns an empty list if the body has no actuators.

备注

Actuators are associated with a body through the joints on the body. Each actuator targets a specific joint, and this method returns all actuators that target joints belonging to this body.

Type:

List[Actuator]

The base link of this body.

Type:

Link

floatingbase#

The floating base object.

Return None if not present.

备注

In mjcf, a body is free moving if it has <freejoint>

Type:

Optional[FloatingBase]

index#
is_mocap#

Whether the body is a mocap (kinematic) body.

Return True if the body has no joints and fixed to the world, False otherwise.

Type:

bool

mocap#

Convert this body to a mocap object if it is a mocap body.

返回:

The mocap object if this body is a mocap, None otherwise.

返回类型:

Optional[PyMocap]

model#
name#

The name of the body.

Return None if not present.

Type:

Optional[str]

num_actuators#

The number of actuators associated with this body.

Type:

int

num_joint_dof_pos#

The number of DoF positions of all joints on the body.

备注

If the body has floating base, the floating base DoF positions are NOT included

Type:

int

num_joint_dof_vel#

The number of DoF velocities of all joints on the body.

备注

If the body has floating base, the floating base DoF velocities are NOT included

Type:

int

num_joints#

The number of joints that belong to this body.

备注

The <freejoint> is not counted as a joint in motrixsim but a floating base.

Type:

int

The number of links that belong to this body.

Type:

int

class motrixsim.Camera#

基类:object

The Camera object in the scene.

Methods:

get_pose(data)

Get the world pose of the camera.

set_near_far(near, far)

Set the near and far plane of the camera.

set_render_target(target[, w, h])

Set the render target of the camera.

Attributes:

depth_only

Whether the camera is in depth-only mode.

far_plane

Get the far plane distance of the camera.

fovy

Get the vertical field of view of the camera in degrees.

index

The index of the camera in the motrixsim.SceneModel.cameras().

link

Get the link that this camera is attached to.

model

The scene model that this camera belongs to.

name

Get the name of the camera.

near_plane

Get the far plane distance of the camera.

position_track

Get or set the position track mode of the camera.

render_target

Get the render target of the camera, either "window" or "image".

rotation_track

Get or set the rotation track mode of the camera.

track_target_link

Get or set the link that the camera looks at.

get_pose(data)#

Get the world pose of the camera.

参数:

data (SceneData) -- The scene data to query.

返回:

Shape: (*data.shape, 7). Each pose is represented as a 7 elements

array with [x, y, z, qx, qy, qz,qw] format.

返回类型:

NDArray[float]

set_near_far(near, far)#

Set the near and far plane of the camera.

参数:
  • near (float) -- The near plane distance. Must be positive.

  • far (float) -- The far plane distance. Must be larger than near.

set_render_target(target, w=400, h=300)#

Set the render target of the camera.

参数:
  • target (str) -- The render target, either "window" or "image".

  • w (int) -- The width of the image if the target is "image". ignored if the target is

  • "window".

  • h (int) -- The height of the image if the target is "image". ignored if the target is

  • "window".

备注

This method must be called before you launch the render application.

depth_only#

Whether the camera is in depth-only mode.

备注

This attribute must be set before you launch the render application.

Type:

bool

far_plane#

Get the far plane distance of the camera.

Type:

float

fovy#

Get the vertical field of view of the camera in degrees.

Type:

float

index#

The index of the camera in the motrixsim.SceneModel.cameras().

Type:

int

Get the link that this camera is attached to.

备注

Returns None if the camera is not attached to any link (i.e., it's a world space camera).

Type:

Optional[Link]

model#

The scene model that this camera belongs to.

Type:

SceneModel

name#

Get the name of the camera.

Type:

Option[str]

near_plane#

Get the far plane distance of the camera.

Type:

float

position_track#

Get or set the position track mode of the camera.

Possible values are:

  • "free": Free to move in all directions.

  • "fixed_local": Fixed the relative position to parent in local frame.

  • "fixed_world": Fixed the relative position to parent in world frame.

Type:

str

render_target#

Get the render target of the camera, either "window" or "image".

Type:

str

rotation_track#

Get or set the rotation track mode of the camera.

Possible values are:

  • "free": Free to rotate.

  • "fixed_local": Fixed the relative rotation to parent in local frame.

  • "fixed_world": Fixed the relative rotation to parent in world frame.

  • "look_at_link": Always look at the target link. This mode requires setting the track_target_link attribute.

Type:

str

Get or set the link that the camera looks at.

备注

This attribute is only valid when the rotation track mode is "look_at_link".

Type:

Optional[Link]

class motrixsim.CameraMgr#

基类:object

Methods:

__getitem__(key, /)

Return self[key].

get_index(name)

Get the camera index by name.

set_system_render_target(target[, w, h])

Set the render target of the system camera.

tolist()

Convert the camera manager to a list of cameras.

Attributes:

cameras

All the cameras defined in the model.

model

The scene model that this camera manager belongs to.

system_render_target

Get the render target of the system camera, either "window" or "image".

__getitem__(key, /)#

Return self[key].

get_index(name)#

Get the camera index by name.

参数:

name (str) -- The name of the camera.

返回:

The index of the camera.

返回类型:

int

Panics:

If the camera name does not exist.

set_system_render_target(target, w=400, h=300)#

Set the render target of the system camera.

参数:
  • target (str) -- The render target, either "window" or "image".

  • w (int) -- The width of the image if the target is "image". ignored if the target is

  • "window".

  • h (int) -- The height of the image if the target is "image". ignored if the target is

  • "window".

备注

This method must be called before you launch the render application.

tolist()#

Convert the camera manager to a list of cameras.

cameras#

All the cameras defined in the model.

Type:

List[Camera]

model#

The scene model that this camera manager belongs to.

Type:

SceneModel

system_render_target#

Get the render target of the system camera, either "window" or "image".

Type:

str

class motrixsim.ContactQuery#

基类:object

Methods:

is_colliding(geom_pairs)

Given a list of geometry pairs, check if they are colliding.

Attributes:

num_contacts

The number of contacts in the world.

is_colliding(geom_pairs)#

Given a list of geometry pairs, check if they are colliding.

参数:

geom_pairs (NDArray[u32]) -- Pairs of geometry indices to check for collision. Shape = (N, 2) where N is the number of pairs.

返回:

Array of booleans indicating whether each pair is colliding.

返回类型:

NDArray[bool]

num_contacts#

The number of contacts in the world.

Type:

int

class motrixsim.DisjointIndices(indices)#

基类:object

Attributes:

size

The number of elements in the disjoint index set.

size#

The number of elements in the disjoint index set. Alias to len(set).

class motrixsim.FloatingBase#

基类:object

The FloatingBase object represents a floating base in the scene.

This class provides access to the properties and state of a floating base in the scene. It allows you to retrieve information about the base's name, DoF velocities and positions, and to set its world translation and rotation.

Methods:

get_dof_pos(data)

Get the DoF positions of the floating base.

get_dof_vel(data)

Get the DoF velocities of the floating base.

get_global_angular_velocity(data)

Extract the world angular velocity of the floating base from the dof velocity array.

get_global_linear_velocity(data)

Extract the world linear velocity of the floating base from the dof velocity array.

get_local_angular_velocity(data)

Extract the local angular velocity of the floating base from the dof velocity array.

get_rotation(data)

Extract the world rotation of the floating base from the dof position array.

get_translation(data)

Extract the world translation of the floating base from the dof position array.

set_global_angular_velocity(data, vel)

Set the global angular velocity of the floating base to dof velocity array directly.

set_global_linear_velocity(data, vel)

Set the global linear velocity of the floating base to dof velocity array directly.

set_local_angular_velocity(data, vel)

Set the local angular velocity of the floating base to dof velocity array directly.

set_rotation(data, quat)

Set the world rotation of the floating base.

set_translation(data, translation)

Set the world translation of the floating base.

Attributes:

dof_pos_indices

The DoF position indices of the floating base.

dof_pos_start

The DoF position address of the floating base in the motrixsim.SceneData.dof_pos().

dof_vel_indices

The DoF velocity indices of the floating base.

dof_vel_start

The DoF velocity address of the floating base in the motrixsim.SceneData.dof_vel().

index

The index of the floatingbase in the motrixsim.SceneModel.floating_bases().

model

The scene model this floating base belongs to.

name

The name of the floating base.

get_dof_pos(data)#

Get the DoF positions of the floating base.

参数:

data (SceneData) -- The scene data to query.

返回:

The DoF positions with (x,y,z, i,j,k,w) format. shape = (data.shape, 7).

返回类型:

NDArray[float]

get_dof_vel(data)#

Get the DoF velocities of the floating base.

参数:

data (SceneData) -- The scene data to query.

返回:

The DoF velocities with (vx,vy,vz wx,wy,wz) format. shape = (data.shape, 6).

返回类型:

NDArray[float]

get_global_angular_velocity(data)#

Extract the world angular velocity of the floating base from the dof velocity array.

参数:

data (SceneData) -- The scene data to query.

返回:

The world angular velocity. shape = (data.shape, 3)

返回类型:

NDArray[float]

get_global_linear_velocity(data)#

Extract the world linear velocity of the floating base from the dof velocity array.

参数:

data (SceneData) -- The scene data to query.

返回:

The world linear velocity. shape = (data.shape, 3)

返回类型:

NDArray[float]

get_local_angular_velocity(data)#

Extract the local angular velocity of the floating base from the dof velocity array.

参数:

data (SceneData) -- The scene data to query.

返回:

The local angular velocity. shape = (data.shape, 3)

返回类型:

NDArray(float)

get_rotation(data)#

Extract the world rotation of the floating base from the dof position array.

参数:

data (SceneData) -- The scene data.

返回:

A quaternion representing the rotation in the format [i, j, k, w].

返回类型:

NDArray[float]

get_translation(data)#

Extract the world translation of the floating base from the dof position array.

参数:

data (SceneData) -- The scene data to query.

返回:

The world translation. shape = (data.shape, 3)

返回类型:

NDArray[float]

set_global_angular_velocity(data, vel)#

Set the global angular velocity of the floating base to dof velocity array directly.

参数:
  • data (SceneData) -- The scene data to store the velocity.

  • vel (ArrayLink[float]) -- The global angular velocity to set. shape = (data.shape, 3)

备注

This method only updates the dof velocity array.

set_global_linear_velocity(data, vel)#

Set the global linear velocity of the floating base to dof velocity array directly.

参数:
  • data (SceneData) -- The scene data to store the velocity.

  • vel (ArrayLink[float]) -- The world linear velocity to set. shape = (data.shape, 3)

备注

This method only updates the dof velocity array.

set_local_angular_velocity(data, vel)#

Set the local angular velocity of the floating base to dof velocity array directly.

参数:
  • data (SceneData) -- The scene data to store the velocity.

  • vel (ArrayLink(float)) -- The local angular velocity, shape = (data.shape, 3).

备注

This method only updates the dof velocity array.

set_rotation(data, quat)#

Set the world rotation of the floating base.

参数:
  • data (SceneData) -- The scene data to store the rotation.

  • quat (NDArray[float]) -- The quaternion [i, j, k, w]. shape = (data.shape, 4).

备注

This function only updates the DoF position of the floating base. The actual rotation is updated through the forward kinematic phase.

set_translation(data, translation)#

Set the world translation of the floating base.

参数:
  • data (SceneData) -- The scene data to store the translation.

  • translation (NDArray[float]) -- The translation [x, y, z]. shape = (data.shape, 3).

备注

This function only updates the DoF position of the floating base. The actual translation of links is updated through the forward kinematic phase.

dof_pos_indices#

The DoF position indices of the floating base. size = 7.

Type:

List[int]

dof_pos_start#

The DoF position address of the floating base in the motrixsim.SceneData.dof_pos().

Type:

int

dof_vel_indices#

The DoF velocity indices of the floating base. size = 6.

Type:

List[int]

dof_vel_start#

The DoF velocity address of the floating base in the motrixsim.SceneData.dof_vel().

Type:

int

index#

The index of the floatingbase in the motrixsim.SceneModel.floating_bases().

Type:

int

model#

The scene model this floating base belongs to.

Type:

SceneModel

name#

The name of the floating base.

Return None if not set.

Type:

Optional[str]

class motrixsim.GeneralActuator#

基类:Actuator

General actuator (MJCF <general>).

MJCF parameter mapping (assumes gaintype="fixed" and biastype="affine"):

  • gainprm[0] -> gain

  • biasprm[0] -> bias

  • -biasprm[1] -> stiffness (sign is negated because the force equation subtracts stiffness * position)

  • -biasprm[2] -> damping (sign is negated because the force equation subtracts damping * velocity)

Methods:

get_bias_override(data)

Get the bias override value from the scene data.

get_damping_override(data)

Get the damping override value from the scene data.

get_gain_override(data)

Get the gain override value from the scene data.

get_stiffness_override(data)

Get the stiffness override value from the scene data.

set_bias_override(data, bias)

Override the bias value of the actuator.

set_damping_override(data, damping)

Override the damping value of the actuator.

set_gain_override(data, gain)

Override the gain value of the actuator.

set_stiffness_override(data, stiffness)

Override the stiffness value of the actuator.

get_bias_override(data)#

Get the bias override value from the scene data.

参数:

data (SceneData) -- The scene data to query.

返回:

The bias value. Shape: (*data.shape,)

返回类型:

NDArray[float]

get_damping_override(data)#

Get the damping override value from the scene data.

参数:

data (SceneData) -- The scene data to query.

返回:

The damping value. Shape: (*data.shape,)

返回类型:

NDArray[float]

get_gain_override(data)#

Get the gain override value from the scene data.

参数:

data (SceneData) -- The scene data to query.

返回:

The gain value. Shape: (*data.shape,)

返回类型:

NDArray[float]

get_stiffness_override(data)#

Get the stiffness override value from the scene data.

参数:

data (SceneData) -- The scene data to query.

返回:

The stiffness value. Shape: (*data.shape,)

返回类型:

NDArray[float]

set_bias_override(data, bias)#

Override the bias value of the actuator.

参数:
  • data (SceneData) -- The scene data to modify.

  • bias (NDArray[float]) -- The new bias value. - Shape (): Single value applied to all batches - Shape: (*data.shape,): Per-batch values

备注

Raises ValueError if the bias is NaN or infinite.

set_damping_override(data, damping)#

Override the damping value of the actuator.

参数:
  • data (SceneData) -- The scene data to modify.

  • damping (NDArray[float]) -- The new damping value. - Shape (): Single value applied to all batches - Shape: (*data.shape,): Per-batch values

备注

Raises ValueError if the damping is negative, NaN, or infinite.

set_gain_override(data, gain)#

Override the gain value of the actuator.

参数:
  • data (SceneData) -- The scene data to modify.

  • gain (NDArray[float]) -- The new gain value. - Shape (): Single value applied to all batches - Shape: (*data.shape,): Per-batch values

备注

Raises ValueError if the gain is NaN or infinite.

set_stiffness_override(data, stiffness)#

Override the stiffness value of the actuator.

参数:
  • data (SceneData) -- The scene data to modify.

  • stiffness (NDArray[float]) -- The new stiffness value. - Shape (): Single value applied to all batches - Shape: (*data.shape,): Per-batch values

备注

Raises ValueError if the stiffness is negative, NaN, or infinite.

class motrixsim.Geom#

基类:object

The Geom object represents a geometry in the scene.

This class provides access to the properties and state of a geometry in the scene. It allows you to retrieve information about the geom and colliders belong to it.

Typed subclasses provide shape-specific properties:

Methods:

get_angular_velocity(data)

Get the world angular velocity of the geom.

get_friction_override(data)

Get the friction override value from the scene data.

get_linear_velocity(data)

Get the world linear velocity of the geom.

get_pose(data)

Get the world pose of the geom.

set_friction_override(data, friction)

Override the friction value of the geom.

Attributes:

collision_affinity

The collision affinity of the geom.

collision_group

The collision group of the geom.

gap

The contact gap of the geom.

hfield

The height field associated with this geom.

index

The index of the geom in the motrixsim.SceneModel.geoms().

link

The parent link this geometry is attached to.

local_pose

The local pose of the geom relative to its parent link or world.

margin

The contact margin of the geom.

model

The scene model that this geom belongs to.

name

The name of the geom.

shape

The shape type of the geom.

size

The size parameters of the geom.

get_angular_velocity(data)#

Get the world angular velocity of the geom.

参数:

data (SceneData) -- The scene data to query.

返回:

Shape: (*data.shape, 3). The last axis is the angular velocity with

[wx, wy, wz] format.

返回类型:

NDArray[float]

get_friction_override(data)#

Get the friction override value from the scene data.

参数:

data (SceneData) -- The scene data to query.

返回:

The friction override value. shape = (*data.shape, 3).

The last axis is [slide, spin, roll].

返回类型:

NDArray[float]

get_linear_velocity(data)#

Get the world linear velocity of the geom.

参数:

data (SceneData) -- The scene data to query.

返回:

Shape: (*data.shape, 3). The last axis is the linear velocity with

[vx, vy, vz] format.

返回类型:

NDArray[float]

get_pose(data)#

Get the world pose of the geom.

参数:

data (SceneData) -- The scene data to query.

返回:

Shape: (*data.shape, 7). Each pose is represented as a 7 elements

with [x, y, z, i, j, k, w] format.

返回类型:

NDArray[float]

set_friction_override(data, friction)#

Override the friction value of the geom.

参数:
  • data (SceneData) -- The scene data to modify.

  • friction (NDArray[float]) -- The new friction values [slide, spin, roll]. - Shape (3,): Single value applied to all batches - Shape (*data.shape, 3): Per-batch values

备注

If any friction component is negative, NaN, or infinite, the override will be ignored.

collision_affinity#

The collision affinity of the geom.

返回:

The collision affinity mask.

返回类型:

int

备注

The collision affinity (also called collide_with) is a bitmask that specifies which collision groups this geom can collide with. Two geoms will collide if (geom1.collision_group & geom2.collision_affinity) != 0 or (geom1.collision_affinity & geom2.collision_group) != 0.

collision_group#

The collision group of the geom.

返回:

The collision group identifier.

返回类型:

int

备注

The collision group is used to filter which geometries can collide with each other. Two geoms will collide if (geom1.collision_group & geom2.collision_affinity) != 0 or (geom1.collision_affinity & geom2.collision_group) != 0.

gap#

The contact gap of the geom.

返回:

The distance band that determines which contacts generate solver constraints.

返回类型:

float

备注

The gap controls the distance threshold for generating solver constraints. Contacts within this distance will generate constraints in the physics solver. This can be tuned to balance stability and performance.

hfield#

The height field associated with this geom.

返回:

The HField object if this geom is a height field

geometry, otherwise None.

返回类型:

Optional[HField]

备注

This is a convenience accessor on the base Geom class so that code iterating over model.geoms can check g.hfield is not None without first testing the concrete subclass type. The same property is also available on GeomHField.

index#

The index of the geom in the motrixsim.SceneModel.geoms().

Type:

int

The parent link this geometry is attached to. None if it is a world geometry.

Type:

Link

local_pose#

The local pose of the geom relative to its parent link or world.

返回:

The local pose as a numpy array of shape (7,)

with [x, y, z, i, j, k, w] format where the first 3 elements are translation and the last 4 are quaternion rotation.

返回类型:

NDArray[float]

备注

The local pose represents the position and orientation of the geom in its parent frame. If the geom is attached to a link, this is relative to that link's frame. If the geom is a world geom (no parent link), this is in world coordinates.

margin#

The contact margin of the geom.

返回:

The distance threshold for detecting contacts.

返回类型:

float

备注

The margin is used to control when contact constraints are generated. A larger margin will detect contacts earlier, potentially improving stability but may also increase computational cost.

model#

The scene model that this geom belongs to.

Type:

SceneModel

name#

The name of the geom. Must be unique within the scene.

返回:

The name of the geom, or "None" if not set.

返回类型:

Optional[str]

shape#

The shape type of the geom.

返回:

The source shape type of the geom.

返回类型:

Shape

备注

The high-level shape type determines the source geometric representation of the geom. Possible values include: Sphere, Cylinder, Capsule, Cuboid, InfinitePlane, HField, Mesh, and Plane. Each shape type has different parameters and may lower to different low-level runtime collider shapes.

size#

The size parameters of the geom.

返回:

The size parameters as a numpy array of shape (3,)

with [s0, s1, s2].

返回类型:

NDArray[float]

备注

The size represents half-size parameters for different shape types:

  • Sphere: [radius, 0.0, 0.0] - spherical radius

  • Capsule: [radius, half_height, 0.0] - radius and half-height

  • Cylinder: [radius, half_height, 0.0] - radius and half-height

  • Cuboid: [half_x, half_y, half_z] - half-extents in each axis

  • Plane: [half_x, half_y, 0.0] - half-extents in x and y directions

  • Mesh/HField/InfinitePlane: [0.0, 0.0, 0.0] - size is ignored for these types

When a primitive shape references a mesh file, the size is automatically computed from the mesh geometry and the geom size parameters are ignored.

class motrixsim.GeomCapsule#

基类:Geom

Capsule geometry.

A capsule shape defined by a radius and half-height. The total height of the capsule is 2 * half_height + 2 * radius.

Methods:

get_size_override(data)

Get the effective size override for this capsule.

set_size_override(data, size)

Override the size of this capsule.

Attributes:

half_height

The half-height of the cylindrical part of the capsule.

radius

The radius of the capsule.

get_size_override(data)#

Get the effective size override for this capsule.

参数:

data (SceneData) -- The scene data to query.

返回:

Shape (*data.shape, 2). The effective [radius, half_height].

返回类型:

NDArray[float]

set_size_override(data, size)#

Override the size of this capsule.

参数:
  • data (SceneData) -- The scene data to modify.

  • size (NDArray[float]) -- The new size [radius, half_height]. - Shape (2,): Single value applied to all batches. - Shape (*data.shape, 2): Per-batch values.

备注

If any component is non-positive, NaN, or infinite, the override is silently ignored.

half_height#

The half-height of the cylindrical part of the capsule.

返回:

The half-height of the capsule cylinder.

返回类型:

float

radius#

The radius of the capsule.

返回:

The capsule radius.

返回类型:

float

class motrixsim.GeomCuboid#

基类:Geom

Cuboid (box) geometry.

A box shape defined by half-extents in each axis direction.

Methods:

get_size_override(data)

Get the effective size override for this cuboid.

set_size_override(data, size)

Override the size of this cuboid.

Attributes:

half_extents

The half-extents of the cuboid.

get_size_override(data)#

Get the effective size override for this cuboid.

参数:

data (SceneData) -- The scene data to query.

返回:

Shape (*data.shape, 3). The effective

[half_x, half_y, half_z].

返回类型:

NDArray[float]

set_size_override(data, size)#

Override the size of this cuboid.

参数:
  • data (SceneData) -- The scene data to modify.

  • size (NDArray[float]) -- The new half-extents [half_x, half_y, half_z]. - Shape (3,): Single value applied to all batches. - Shape (*data.shape, 3): Per-batch values.

备注

If any component is non-positive, NaN, or infinite, the override is silently ignored.

half_extents#

The half-extents of the cuboid.

返回:

A numpy array of shape (3,) with [half_x, half_y, half_z].

返回类型:

NDArray[float]

class motrixsim.GeomCylinder#

基类:Geom

Cylinder geometry.

A cylindrical shape defined by a radius and half-height.

Methods:

get_size_override(data)

Get the effective size override for this cylinder.

set_size_override(data, size)

Override the size of this cylinder.

Attributes:

half_height

The half-height of the cylinder.

radius

The radius of the cylinder.

get_size_override(data)#

Get the effective size override for this cylinder.

参数:

data (SceneData) -- The scene data to query.

返回:

Shape (*data.shape, 2). The effective [radius, half_height].

返回类型:

NDArray[float]

set_size_override(data, size)#

Override the size of this cylinder.

参数:
  • data (SceneData) -- The scene data to modify.

  • size (NDArray[float]) -- The new size [radius, half_height]. - Shape (2,): Single value applied to all batches. - Shape (*data.shape, 2): Per-batch values.

备注

If any component is non-positive, NaN, or infinite, the override is silently ignored.

half_height#

The half-height of the cylinder.

返回:

The cylinder half-height.

返回类型:

float

radius#

The radius of the cylinder.

返回:

The cylinder radius.

返回类型:

float

class motrixsim.GeomEllipsoid#

基类:Geom

Ellipsoid geometry.

An ellipsoidal shape defined by semi-axis lengths in each direction.

Methods:

get_size_override(data)

Get the effective size override for this ellipsoid.

set_size_override(data, size)

Override the size of this ellipsoid.

Attributes:

half_extents

The half-extents (semi-axis lengths) of the ellipsoid.

get_size_override(data)#

Get the effective size override for this ellipsoid.

参数:

data (SceneData) -- The scene data to query.

返回:

Shape (*data.shape, 3). The effective semi-axis lengths

[semi_x, semi_y, semi_z].

返回类型:

NDArray[float]

set_size_override(data, size)#

Override the size of this ellipsoid.

参数:
  • data (SceneData) -- The scene data to modify.

  • size (NDArray[float]) -- The new semi-axis lengths [semi_x, semi_y, semi_z]. - Shape (3,): Single value applied to all batches. - Shape (*data.shape, 3): Per-batch values.

备注

If any component is non-positive, NaN, or infinite, the override is silently ignored.

half_extents#

The half-extents (semi-axis lengths) of the ellipsoid.

返回:

A numpy array of shape (3,) with [semi_x, semi_y, semi_z].

返回类型:

NDArray[float]

class motrixsim.GeomHField#

基类:Geom

Height field geometry.

A geometry defined by a height field asset, used for terrain and elevation data.

Methods:

sample_height(data, xy[, out])

Sample the terrain surface height at world-space XY coordinates.

Attributes:

hfield

The height field associated with this geom.

sample_height(data, xy, out=None)#

Sample the terrain surface height at world-space XY coordinates.

Transforms the given world XY points into the height field's local frame, performs bilinear interpolation on the grid, and returns the world-space Z height for each query point.

参数:
  • data (SceneData) -- The scene data (provides current geom world pose).

  • xy (NDArray[float]) -- World-space XY coordinates. - Shape (N, 2): N query points shared across all batches. - Shape (*data.shape, N, 2): per-batch query points.

  • out (Optional[NDArray[float]]) -- Pre-allocated output array of shape (*data.shape, N). When provided the result is written into this array and returned directly, avoiding an internal allocation.

返回:

World-space surface heights.

Shape (*data.shape, N).

返回类型:

NDArray[float]

备注

Points that fall outside the height field boundary are clamped to the nearest edge cell.

hfield#

The height field associated with this geom.

返回:

The HField object if this geom has an associated

height field, otherwise None.

返回类型:

Optional[HField]

class motrixsim.GeomInfinitePlane#

基类:Geom

Infinite plane geometry.

An unbounded plane, typically used as a ground surface.

class motrixsim.GeomMesh#

基类:Geom

Mesh geometry.

A geometry defined by a triangle mesh asset. The mesh can optionally be scaled.

Attributes:

mesh_name

The name of the referenced mesh asset.

mesh_scale

The scale applied to the mesh.

mesh_name#

The name of the referenced mesh asset.

返回:

The mesh asset name, or None if not set.

返回类型:

Optional[str]

mesh_scale#

The scale applied to the mesh.

返回:

A numpy array of shape (3,) with [sx, sy, sz],

or None if no scaling is applied.

返回类型:

Optional[NDArray[float]]

class motrixsim.GeomPlane#

基类:Geom

Sized plane geometry.

A finite rectangular plane defined by half-extents in x and y directions.

class motrixsim.GeomSphere#

基类:Geom

Sphere geometry.

A spherical shape defined by a single radius parameter.

Methods:

get_size_override(data)

Get the effective size override for this sphere.

set_size_override(data, size)

Override the size of this sphere.

Attributes:

radius

The radius of the sphere.

get_size_override(data)#

Get the effective size override for this sphere.

Returns the overridden radius if a size override has been set, otherwise returns the model's original radius.

参数:

data (SceneData) -- The scene data to query.

返回:

Shape (*data.shape, 1). The effective [radius].

返回类型:

NDArray[float]

set_size_override(data, size)#

Override the size of this sphere.

参数:
  • data (SceneData) -- The scene data to modify.

  • size (NDArray[float]) -- The new size [radius]. - Shape (1,): Single value applied to all batches. - Shape (*data.shape, 1): Per-batch values.

备注

If the radius is non-positive, NaN, or infinite, the override is silently ignored.

radius#

The radius of the sphere.

返回:

The sphere radius.

返回类型:

float

class motrixsim.HField#

基类:object

The HField object represents a height field terrain in the scene.

This class provides access to height field (terrain) data used for ground interactions, terrain following, and surface-based physics. Height fields provide an efficient way to represent large terrain surfaces with elevation data.

Methods:

get(row, col)

Get the height value at the specified row and column.

Attributes:

bound

Get the bounding box of the height field in local space.

height_matrix

Get the height matrix data as a numpy array.

index

The index of the hfield in the scene.

model

The scene model that this hfield belongs to.

name

The name of the hfield.

ncol

The number of columns in the height field grid.

nrow

The number of rows in the height field grid.

get(row, col)#

Get the height value at the specified row and column.

参数:
  • row (int) -- The row index (0-based).

  • col (int) -- The column index (0-based).

返回:

The height value at the specified grid cell.

返回类型:

float

bound#

Get the bounding box of the height field in local space.

返回:

A 1D numpy array of shape (6,) representing the bounding box

in the format [-extent_x, -extent_y, 0, extent_x, extent_y, size_z].

返回类型:

NDArray[float]

height_matrix#

Get the height matrix data as a numpy array.

备注

The returned array is a copy of the internal data. Modifying it will not affect the hfield.

返回:

A 2D numpy array of shape (nrow, ncol) containing the height values. Row 0 is the -Y side, matching MuJoCo's compiled hfield data order.

返回类型:

NDArray[float]

index#

The index of the hfield in the scene.

Type:

int

model#

The scene model that this hfield belongs to.

Type:

SceneModel

name#

The name of the hfield. Must be unique within the scene.

返回:

The name of the hfield, or "None" if not set.

返回类型:

Optional[str]

ncol#

The number of columns in the height field grid.

Type:

int

nrow#

The number of rows in the height field grid.

Type:

int

class motrixsim.Joint#

基类:object

The Joint object represents a joint in the scene.

This class provides access to the properties and state of a joint in the scene. It allows you to retrieve information about the joint's name, link index, number of DoF velocities and positions, and DoF velocity and position addresses.

Methods:

get_armature_override(data)

Get the armature override value from the scene data.

get_dof_pos(data)

Get the DoF positions of the joint.

get_dof_vel(data)

Get the DoF velocities of the joint.

get_frictionloss_override(data)

Get the friction loss override value from the scene data.

set_armature_override(data, armature)

Override the armature value of the joint.

set_dof_pos(data, position)

Set the DoF positions of the joint.

set_dof_vel(data, velocity)

Set the DoF velocities of the joint.

set_frictionloss_override(data, frictionloss)

Override the friction loss value of the joint.

Attributes:

armature

The model armature value of the joint.

axis

The motion axis of the joint.

dof_pos_index

The position DoF address of the joint.

dof_vel_index

The velocity DoF address of the joint.

frictionloss

The model friction loss value of the joint.

index

The index of the joint in the motrixsim.SceneModel.joints().

link

The link this joint is attached to.

link_index

The index of the link this joint is attached to.

model

The scene model this joint belongs to.

name

The name of the joint.

num_dof_pos

The number of position DoFs of the joint.

num_dof_vel

The number of velocity DoFs of the joint.

range

The range limits of the joint.

get_armature_override(data)#

Get the armature override value from the scene data.

参数:

data (SceneData) -- The scene data to query.

返回:

The armature override value. Shape: (*data.shape,)

返回类型:

NDArray[float]

get_dof_pos(data)#

Get the DoF positions of the joint.

参数:

data (SceneData) -- The scene data to query.

返回:

The DoF positions. shape = (data.shape, num_dof_pos())

返回类型:

NDArray[float]

get_dof_vel(data)#

Get the DoF velocities of the joint.

参数:

data (SceneData) -- The scene data to query.

返回:

The DoF velocities. shape = (data.shape, num_dof_vel())

返回类型:

NDArray[float]

get_frictionloss_override(data)#

Get the friction loss override value from the scene data.

参数:

data (SceneData) -- The scene data to query.

返回:

The friction loss override value. Shape: (*data.shape,)

返回类型:

NDArray[float]

set_armature_override(data, armature)#

Override the armature value of the joint.

参数:
  • data (SceneData) -- The scene data to modify.

  • armature (NDArray[float]) -- The new armature value. - Shape (): Single value applied to all batches - Shape: (*data.shape,): Per-batch values

备注

If the armature is negative, NaN, or infinite, the override will be ignored.

set_dof_pos(data, position)#

Set the DoF positions of the joint.

参数:
  • data (SceneData) -- The scene data to store the new positions.

  • position (NDArray[float]) -- The new DoF positions. shape = (data.shape, num_dof_pos())

set_dof_vel(data, velocity)#

Set the DoF velocities of the joint.

参数:
  • data (SceneData) -- The scene data to store the new velocities.

  • velocity (NDArray[float]) -- The new DoF velocities. shape = (data.shape, num_dof_vel())

set_frictionloss_override(data, frictionloss)#

Override the friction loss value of the joint.

参数:
  • data (SceneData) -- The scene data to modify.

  • frictionloss (NDArray[float]) -- The new friction loss value. - Shape (): Single value applied to all batches - Shape: (*data.shape,): Per-batch values

备注

If the value is negative, NaN, or infinite, the override will be ignored.

armature#

The model armature value of the joint.

Type:

float

axis#

The motion axis of the joint.

Returns a 3-element array representing the motion axis of the joint in the successor body coordinate frame. This is primarily used for hinge and slide joints.

备注

The axis is normalized automatically when the joint is created. For spherical joints, the axis concept doesn't apply in the same way as they have full rotational freedom.

Type:

NDArray[float]

dof_pos_index#

The position DoF address of the joint.

Return the starting index of the position DoFs.

Type:

int

dof_vel_index#

The velocity DoF address of the joint.

Return the starting index of the velocity DoFs.

Type:

int

frictionloss#

The model friction loss value of the joint.

Type:

float

index#

The index of the joint in the motrixsim.SceneModel.joints().

Type:

int

The link this joint is attached to.

Type:

Link

The index of the link this joint is attached to.

Type:

int

model#

The scene model this joint belongs to.

Type:

SceneModel

name#

The name of the joint.

Return the name of the joint, or None if not set.

Type:

Optional[str]

num_dof_pos#

The number of position DoFs of the joint.

Type:

int

num_dof_vel#

The number of velocity DoFs of the joint.

Type:

int

range#

The range limits of the joint.

Returns a 2-element array containing the lower and upper bounds of the joint range. Array format: [lower_bound, upper_bound] If the joint has no limits, returns [f32::NEG_INFINITY, f32::INFINITY].

Example:

joint.range
# array([[-1.57,  1.57]])  # Hinge joint with ±π/2 limits
Type:

NDArray[float]

class motrixsim.Keyframe#

基类:object

The Keyframe object represents a keyframe in the scene.

This class provides access to the properties of a keyframe, including its name, simulation time, joint positions, velocities, and control values.

Methods:

apply(data)

Apply the keyframe to scene data.

Attributes:

ctrl

The actuator control values of the keyframe.

dof_pos

The dof positions of the keyframe.

dof_vel

The joint velocities of the keyframe.

index

The index of the keyframe in the keyframe list.

model

The scene model this keyframe belongs to.

name

The name of the keyframe, or None if not set.

time

The simulation time of the keyframe, or None if not set.

apply(data)#

Apply the keyframe to scene data.

参数:

data (SceneData) -- Scene data to apply the keyframe to.

备注

This method does NOT automatically call forward_kinematic. Users should call model.forward_kinematic(data) after applying the keyframe if they need to update the scene transforms (e.g., for visualization or getting correct link poses).

Example:

model = motrixsim.load_model("scene.xml")
data = motrixsim.SceneData(model)
# Apply first keyframe
model.keyframes[0].apply(data)
model.forward_kinematic(data)
ctrl#

The actuator control values of the keyframe.

Returns a numpy array with shape (num_actuators,) containing the actuator control values for all actuators in the scene.

Type:

NDArray[float]

dof_pos#

The dof positions of the keyframe.

Returns a numpy array with shape (num_dof_pos,) containing the dof positions for all degrees of freedom in the scene.

Type:

NDArray[float]

dof_vel#

The joint velocities of the keyframe.

Returns a numpy array with shape (num_dof_vel,) containing the joint velocities for all degrees of freedom in the scene.

Type:

NDArray[float]

index#

The index of the keyframe in the keyframe list.

Type:

int

model#

The scene model this keyframe belongs to.

Type:

SceneModel

name#

The name of the keyframe, or None if not set.

Type:

Optional[str]

time#

The simulation time of the keyframe, or None if not set.

Type:

float

基类:object

The Link object represents a kinematic link in the scene.

This class provides access to the properties and state of a kinematic link in the scene. It allows you to retrieve information about the link's name, index, joint indices, number of joints, and the joints associated with the link.

Methods:

add_external_force(data, force[, point, local])

Add an external force to the link.

add_external_torque(data, torque[, local])

Add an external torque to the link.

get_angular_velocity(data)

Get the world angular velocity of the link.

get_center_of_mass_override(data)

Get the center of mass override of the link in the link local frame.

get_joint(index)

Get the joint at the specified index if the link has multiple joints.

get_linear_velocity(data)

Get the world linear velocity of the link.

get_mass_override(data)

Get the overrided mass of the link in the scene data.

get_pose(data)

Get the world pose of the link.

get_position(data)

Get the world position of the link.

get_rotation(data)

Get the world rotation of the link as a quaternion (i, j, k, w).

get_rotation_mat(data)

Get the world rotation matrix of the link.

joints()

The joints associated with this link.

set_center_of_mass_override(data, center_of_mass)

Override the center of mass of the link.

set_mass_override(data, mass)

Override the mass of the link.

Attributes:

center_of_mass

Get the center of mass of the link in the link local frame.

geoms

The geometries directly attached to this link.

index

The index of the link in the motrixsim.SceneModel.links().

joint_indices

The joint indices of this link in the motrixsim.SceneModel.joints().

mass

Get the mass of the link in the model.

model

The scene model that this link belongs to.

name

The name of the link.

num_joints

The number of joints associated with this link.

add_external_force(data, force, point=None, local=True)#

Add an external force to the link.

参数:
  • data (SceneData) -- The scene data to modify.

  • force (NDArray[float]) -- The force vector. - Shape: (*data.shape, 3): Per-batch force vectors

  • point (NDArray[float], optional) -- Application point. - Shape: (*data.shape, 3): Per-batch points

  • local (bool) -- Whether the force and point are in local coordinates. Default: True.

备注

The force is applied at the specified point in link coordinates. If point is None, force is applied at the link's center of mass. Forces applied to mocap-type links will be ignored.

add_external_torque(data, torque, local=True)#

Add an external torque to the link.

参数:
  • data (SceneData) -- The scene data to modify.

  • torque (NDArray[float]) -- The torque vector. - Shape: (*data.shape, 3): Per-batch torque vectors

  • local (bool) -- Whether the torque is in local coordinates. Default: True.

备注

Torques applied to mocap-type links will be ignored.

get_angular_velocity(data)#

Get the world angular velocity of the link.

参数:

data (SceneData) -- The scene data to query.

返回:

Shape: (*data.shape, 3). The last axis is the angular velocity with

[wx, wy, wz] format.

返回类型:

NDArray[float]

get_center_of_mass_override(data)#

Get the center of mass override of the link in the link local frame.

参数:

data (SceneData) -- The scene data to query.

返回:

Shape: (*data.shape, 3). The center of mass override value.

返回类型:

NDArray[float]

get_joint(index)#

Get the joint at the specified index if the link has multiple joints.

参数:

index (int) -- The local index of the joint.

返回:

The joint object, or "None" if not found.

返回类型:

Optional[Joint]

get_linear_velocity(data)#

Get the world linear velocity of the link.

参数:

data (SceneData) -- The scene data to query.

返回:

Shape: (*data.shape, 3). The last axis is the linear velocity with

[vx, vy, vz] format.

返回类型:

NDArray[float]

get_mass_override(data)#

Get the overrided mass of the link in the scene data.

参数:

data (SceneData) -- The scene data to query.

返回:

shape = (1,). The mass override value.

返回类型:

NDArray[float]

get_pose(data)#

Get the world pose of the link.

参数:

data (SceneData) -- The scene data to query.

返回:

Shape: (*data.shape, 7). Each pose is represented as a 7 elements

with [x, y, z, i, j, k, w] format.

返回类型:

NDArray[float]

get_position(data)#

Get the world position of the link.

参数:

data (SceneData) -- The scene data to query.

返回:

Shape: (*data.shape, 3).

返回类型:

NDArray[float]

get_rotation(data)#

Get the world rotation of the link as a quaternion (i, j, k, w).

参数:

data (SceneData) -- The scene data to query.

返回:

A numpy array with shape (*data.shape, 4).

返回类型:

NDArray[float]

get_rotation_mat(data)#

Get the world rotation matrix of the link.

参数:

data (SceneData) -- The scene data to query.

返回:

A numpy array with shape (*data.shape, 3, 3).

返回类型:

NDArray[float]

joints()#

The joints associated with this link.

返回:

A list of joint objects.

返回类型:

List[Joint]

set_center_of_mass_override(data, center_of_mass)#

Override the center of mass of the link.

参数:
  • data (SceneData) -- The scene data to modify.

  • center_of_mass (NDArray[float]) -- The new center of mass. - Shape (3,): Single center of mass value applied to all batches - Shape: (*data.shape, 3): Per-batch center of mass vectors

备注

If the center_of_mass components are not finite (NaN or infinity), or the link is mocap type, or the link is fixed to world, the override will be ignored.

set_mass_override(data, mass)#

Override the mass of the link.

参数:
  • data (SceneData) -- The scene data to modify.

  • mass (NDArray[float]) -- The new mass. - Shape (): Single mass value applied to all batches - Shape: (*data.shape,): Per-batch mass values

备注

If the mass is non-positive or the link is mocap type, or the link is fixed to world, the override will be ignored.

center_of_mass#

Get the center of mass of the link in the link local frame.

返回:

shape = (3,). The center of mass position

返回类型:

NDArray[float]

geoms#

The geometries directly attached to this link.

返回:

A list of geometry objects whose parent link is this link.

返回类型:

List[Geom]

index#

The index of the link in the motrixsim.SceneModel.links().

Type:

int

joint_indices#

The joint indices of this link in the motrixsim.SceneModel.joints().

返回:

The size of the list must be equal to num_joints()

返回类型:

List[int]

mass#

Get the mass of the link in the model.

返回:

The mass of the link.

返回类型:

Real

model#

The scene model that this link belongs to.

Type:

SceneModel

name#

The name of the link. Must be unique within the scene.

返回:

The name of the link, or "None" if not set.

返回类型:

Optional[str]

num_joints#

The number of joints associated with this link.

返回:

number of joints associated with this link.

返回类型:

int

class motrixsim.Mocap#

基类:object

The Mocap object represents a motion capture body in the scene. it can will participate in the collision and apply force to other bodies, but will not be affected by the physics simulation.

Methods:

set_pose(data, pose)

Set the pose of the mocap.

Attributes:

body

The body associated with this mocap.

model

The scene model this mocap belongs to.

set_pose(data, pose)#

Set the pose of the mocap.

参数:
  • data (SceneData) -- The scene data to store the pose.

  • pose (NDArray[float]) -- The pose to set, as a 7-element array (x, y, z, qx, qy, qz, qw). shape = (data.shape,7)

body#

The body associated with this mocap.

Type:

Body

model#

The scene model this mocap belongs to.

Type:

SceneModel

class motrixsim.MotorActuator#

基类:Actuator

Motor actuator (MJCF <motor>). Direct torque/force control with fixed gain = 1.0.

No additional parameter override methods. The control value is applied directly as force.

class motrixsim.Options#

基类:object

The Options object represents the simulation options.

This class is used to configure the simulation options. You can access it through model.options.

Attributes:

disable_contacts

Is all contact constraints disabled in the simulation?

disable_gravity

Is the gravity disabled in the simulation?

gravity

The gravity vector applied to the simulation.

max_iterations

The maximum number of iterations for the solver.

solver_tolerance

The tolerance for the solver.

timestep

The delta time for each simulation step.

disable_contacts#

Is all contact constraints disabled in the simulation?

Type:

bool

disable_gravity#

Is the gravity disabled in the simulation?

Type:

bool

gravity#

The gravity vector applied to the simulation.

A numpy array of shape (3,) or a list of three floats representing the gravity vector.

Type:

NDArray[float]

max_iterations#

The maximum number of iterations for the solver.

抛出:

ValueError -- The set max iterations is zero.

Type:

int

solver_tolerance#

The tolerance for the solver.

抛出:

ValueError -- The set tolerance is not positive.

Type:

float

timestep#

The delta time for each simulation step.

抛出:

ValueError -- The set timestep is not positive.

Type:

float

class motrixsim.PositionActuator#

基类:Actuator

Position actuator (MJCF <position>).

MJCF parameter mapping:

  • kp -> kp (writes both gain and stiffness internally)

  • kv -> kd (writes damping internally, defaults to 0)

Methods:

get_dampratio_override(data)

Get the dampratio override value from the scene data.

get_kd_override(data)

Get the kd override value from the scene data.

get_kp_override(data)

Get the kp override value from the scene data.

set_damping_override(data, damping)

Override the damping value for a position actuator.

set_kp_override(data, kp)

Override the kp value for a position actuator.

get_dampratio_override(data)#

Get the dampratio override value from the scene data.

参数:

data (SceneData) -- The scene data to query.

返回:

The dampratio value. Shape: (*data.shape,).

Returns None when this actuator stores DampingType.Kv in the model.

返回类型:

Optional[NDArray[float]]

get_kd_override(data)#

Get the kd override value from the scene data.

参数:

data (SceneData) -- The scene data to query.

返回:

The kd value. Shape: (*data.shape,).

Returns None when this actuator stores DampingType.Dampratio in the model.

返回类型:

Optional[NDArray[float]]

get_kp_override(data)#

Get the kp override value from the scene data.

参数:

data (SceneData) -- The scene data to query.

返回:

The kp value. Shape: (*data.shape,)

返回类型:

NDArray[float]

set_damping_override(data, damping)#

Override the damping value for a position actuator.

The meaning of the damping value depends on the actuator's damping_type:

  • DampingType.Kv: The value is the absolute damping coefficient (kv).

  • DampingType.Dampratio: The value is the damping ratio relative to critical damping.

参数:
  • data (SceneData) -- The scene data to modify.

  • damping (NDArray[float]) -- The new damping value. - Shape (): Single value applied to all batches - Shape: (*data.shape,): Per-batch values

备注

if the value is negative, NaN, infinite, or the actuator type does not support independent damping overrides, the override will be ignored.

set_kp_override(data, kp)#

Override the kp value for a position actuator. Writes both gain and stiffness.

参数:
  • data (SceneData) -- The scene data to modify.

  • kp (NDArray[float]) -- The new kp value. - Shape (): Single value applied to all batches - Shape: (*data.shape,): Per-batch values

备注

if the value is negative, NaN, infinite, or the actuator is not a position actuator, the override will be ignored.

class motrixsim.SceneData(model, batch=Ellipsis)#

基类:object

The SceneData object represents the simulation state.

This class provides access to the dynamic state of the simulation, including joint positions, velocities, and other runtime data. Users can query or modify the simulation state, reset the scene to its initial state, and access low-level simulation data for advanced use cases. The state can be accessed via properties such as qpos, qvel, and via methods like reset(). For advanced control, the low property exposes the low-level data object.

Methods:

__getitem__(key, /)

Return self[key].

get(index)

Get sub-data by index.

reset(model)

Reset the scene data with the given model.

set_dof_pos(dof_pos, model)

Set the dof position for the whole world data.

set_dof_vel(dof_vel)

Set the dof velocity for the whole world data.

Attributes:

actuator_ctrls

The all the actuator control values.

dof_pos

The dof position array of the world.

dof_vel

The dof velocity array of the world.

low

The low-level data object for advanced simulation control.

ndim

The number of dimensions of the data.

shape

The shape of the data.

__getitem__(key, /)#

Return self[key].

get(index)#

Get sub-data by index. Alias to __getitem__

参数:

index (int | ndarray[bool] | DisjointIndices) -- The index to select. Following types are

supported:
  • int: Select a single element. Raise error if the data has no batch dimension.

  • ndarray[bool]: Select multiple elements based on a boolean mask.

  • DisjointIndices: Select multiple non-contiguous elements.

reset(model)#

Reset the scene data with the given model.

Reinitializes all simulation state variables using the provided model.

参数:

model (SceneModel) -- The scene model to reset the data with.

set_dof_pos(dof_pos, model)#

Set the dof position for the whole world data.

参数:
  • dof_pos (NDArray[float]) -- The dof position array to set. If Shape: (*data.shape, num_dof_pos), each data will use the corresponding slice. If Shape: (num_dof_pos,), all data will use the same dof position.

  • model (SceneModel) -- The scene model to validate the dof position.

抛出:

Exception -- When the dof position data is invalid.(e.g. quaternion not normalized)

备注

The dof_pos array must follow the same format as the getter method:

  • Floating base/free body: 7 elements [tx, ty, tz, qx, qy, qz, qw]

  • Ball joint: 4 elements [qx, qy, qz, qw] for quaternion rotation

  • Hinge joint: 1 element for angular position

  • Slide joint: 1 element for linear position

Elements should be concatenated in order: [floating_base_dofs..., joint1_dofs..., joint2_dofs..., ...]

set_dof_vel(dof_vel)#

Set the dof velocity for the whole world data.

参数:

dof_vel (NDArray[float]) -- The dof velocity array to set. Shape: ``(*data.shape,

num_dof_vel)``.

actuator_ctrls#

The all the actuator control values. (Get&Set)

Array of actuator control values. Shape: (*data.shape, num_ctrls).

备注

If the model is created from MJCF, the order of the control values matches the order of actuators in the MJCF file.

抛出:

TypeError -- When the shape of the setted values is not invalid.

Type:

NDArray[float]

dof_pos#

The dof position array of the world.

Array of DoF positions. Shape: (*data.shape, num_dof_pos)

备注

The dof_pos array contains position coordinates for all degrees of freedom in the simulation, with format varying by joint type:

  • Floating base/free body: 7 elements [tx, ty, tz, qx, qy, qz, qw]

  • Ball joint: 4 elements [qx, qy, qz, qw] for quaternion rotation

  • Hinge joint: 1 element for angular position

  • Slide joint: 1 element for linear position

Elements are concatenated in order: [floating_base_dofs..., joint1_dofs..., joint2_dofs..., ...]

Type:

NDArray[float]

dof_vel#

The dof velocity array of the world.

Array of DoF velocities. Shape: (*data.shape, num_dof_vel).

Type:

NDArray[float]

low#

The low-level data object for advanced simulation control.

备注

Only modify the low-level data if you understand the implications. Incorrect modifications may lead to unstable simulation behavior.

Type:

LowData

ndim#

The number of dimensions of the data.

Type:

int

shape#

The shape of the data.

If the data is batched, the shape is (batch_size,). If not batched, the shape is ().

Type:

Tuple[int]

class motrixsim.SceneModel#

基类:object

The SceneModel object represents the entire simulation world.

This class provides a high-level interface to access and manipulate the simulation world model, including all bodies, joints, actuators, links, and sites. Users can query the scene structure and configuration, modify simulation options, and access components through properties (joints, options) or methods (get_body(), get_sensor_values()).

Methods:

compute_init_dof_pos()

Compute the initial DoF positions for the world.

enable_constraints_report()

Enable constraint report generation for subsequent simulation steps.

forward_kinematic(data)

Perform forward kinematic calculations using the current model and data.

get_actuator(arg)

Get an actuator by name or index.

get_actuator_ctrls(data)

Alias to SceneData.actuator_ctrls()

get_actuator_index(name)

Get actuator index by its name.

get_body(key)

Get a body by name or index.

get_body_index(name)

Get the body index by its name.

get_camera_poses(data)

Get the world poses of all cameras.

get_contact_query(data)

Get a contact query object for the current model and data.

get_geom(arg)

Get a geom by name or index.

get_geom_index(name)

Get the geometry index by its name.

get_gravity_override(data)

Get the effective gravity override from the scene data.

get_hfield(arg)

Get an hfield by name or index.

get_hfield_index(name)

Get hfield index by its name.

get_joint(key)

Get a joint by name or index.

get_joint_index(name)

Get the joint index by its name.

get_link(arg)

Get a link by name or index.

get_link_angular_velocities(data)

Get the world angular velocities of all links.

get_link_index(name)

Get the link index by its name.

get_link_linear_velocities(data)

Get the world linear velocities of all links.

get_link_poses(data)

Get the world poses of all links.

get_link_rotation_mats(data)

Get all link rotation matrices.

get_link_velocities(data)

Get the world velocities (linear and angular) of all links.

get_sensor_value(id, data)

Get the value of a specific sensor by its ID.

get_sensor_values(names, data)

Get the values of multiple sensors by their names, concatenated into a single array.

get_site(key)

Get a site by name or index.

get_site_index(name)

Get site index by name.

set_gravity_override(data, gravity)

Override the gravity vector for the scene data.

step(data)

Advance the simulation by one step using the current model and data.

step_n(data, n)

Advance the simulation by n steps using the current model and data.

Attributes:

actuator_ctrl_limits

The actuator control ranges.

actuator_names

The list of actuator names in the world.

actuators

Get all actuators defined in the model.

bodies

The list of all bodies in the world.

body_names

The list of all body names in the world.

cameras

The camera manager for accessing cameras by name.

floating_bases

The list of all floating bases in the world.

geom_names

The list of all geoms names in the world.

geoms

The list of all geoms in the world.

joint_dof_pos_indices

The start dof index for each joint in the dof positions array.

joint_dof_pos_nums

The number of DoF positions for each joint.

joint_dof_vel_indices

The start dof index for each joint in the dof velocities array.

joint_dof_vel_nums

The size of DoF velocities of each joint.

joint_limits

The joint position limits for each joint.

joint_names

The list of all joint names in the world.

joints

The list of all joints in the world.

keyframes

The list of all keyframes in the model.

link_names

The list of all link names in the world.

links

The list of all links in the world.

low

The low-level model for advanced or internal simulation access.

num_actuators

The number of actuators in the world.

num_bodies

The number of bodies in the world.

num_dof_pos

The number of DoF positions in the world.

num_dof_vel

The number of DoF velocities in the world.

num_geoms

The number of geoms in the world.

num_hfields

The number of height fields in the world.

num_joints

The number of joints in the world.

num_keyframes

The number of keyframes in the model.

num_links

The number of links in the world.

num_sensors

The number of sensors in the world.

num_sites

The number of sites in the world.

options

The simulation options of the model.

site_names

The list of all site names in the world.

sites

The list of all sites in the world.

compute_init_dof_pos()#

Compute the initial DoF positions for the world.

返回:

shape=(num_dof_pos,). Initial DoF positions.

返回类型:

NDArray[float]

enable_constraints_report()#

Enable constraint report generation for subsequent simulation steps.

备注

This is a model-wide persistent switch shared by all report consumers.

forward_kinematic(data)#

Perform forward kinematic calculations using the current model and data.

备注

This method only updates the world poses of all links and bodies based on the current joint positions.

get_actuator(arg)#

Get an actuator by name or index.

参数:

key (str or int) -- Name or index of the actuator.

返回:

The actuator object, or None if not found.

返回类型:

Optional[Actuator]

get_actuator_ctrls(data)#

Alias to SceneData.actuator_ctrls()

get_actuator_index(name)#

Get actuator index by its name.

参数:

name (str) -- Name of the actuator.

返回:

Index of the actuator, or None if not found.

返回类型:

Optional[int]

get_body(key)#

Get a body by name or index.

参数:

key (str or int) -- Name or index of the body.

返回:

The body object, or None if not found.

返回类型:

Optional[Body]

get_body_index(name)#

Get the body index by its name.

参数:

name (str) -- Name of the body.

返回:

Index of the body, or None if not found.

返回类型:

Optional[int]

get_camera_poses(data)#

Get the world poses of all cameras.

参数:

data (SceneData) -- Scene data.

返回:

A numpy array with shape (*data.shape,num_cameras, 7). Each pose is composed of [x, y, z, qx, qy, qz, qw],

返回类型:

NDArray[float]

备注

If there are no cameras in the scene, returns an array with shape (*data.shape, 0, 7).

get_contact_query(data)#

Get a contact query object for the current model and data.

参数:

data (SceneData) -- Scene data.

返回:

A contact query object that can be used to query contacts in the world.

返回类型:

ContactQuery

get_geom(arg)#

Get a geom by name or index.

参数:

key (str or int) -- Name or index of the geom.

返回:

The geom object, or None if not found.

返回类型:

Optional[Geom]

get_geom_index(name)#

Get the geometry index by its name.

参数:

name (str) -- Name of the geometry.

返回:

Index of the geometry, or None if not found.

返回类型:

Optional[int]

get_gravity_override(data)#

Get the effective gravity override from the scene data.

参数:

data (SceneData) -- Scene data.

返回:

Gravity vector. Shape: (*data.shape, 3).

返回类型:

NDArray[float]

get_hfield(arg)#

Get an hfield by name or index.

参数:

key (str or int) -- Name or index of the hfield.

返回:

The hfield object, or None if not found.

返回类型:

Optional[HField]

get_hfield_index(name)#

Get hfield index by its name.

参数:

name (str) -- Name of the hfield.

返回:

Index of the hfield, or None if not found.

返回类型:

Optional[int]

get_joint(key)#

Get a joint by name or index.

参数:

key (str or int) -- Name or index of the joint.

返回:

The joint object, or None if not found.

返回类型:

Optional[Joint]

get_joint_index(name)#

Get the joint index by its name.

参数:

name (str) -- Name of the joint.

返回:

Index of the joint, or None if not found.

返回类型:

Optional[int]

Get a link by name or index.

参数:

key (str or int) -- Name or index of the link.

返回:

The link object, or None if not found.

返回类型:

Optional[Link]

Get the world angular velocities of all links.

参数:

data (SceneData) -- Scene data.

返回:

A numpy array with shape (*data.shape, num_links, 3). Each velocity is composed of [wx, wy, wz].

返回类型:

NDArray[float]

Get the link index by its name.

参数:

name (str) -- Name of the link.

返回:

Index of the link, or None if not found.

返回类型:

Optional[int]

Get the world linear velocities of all links.

参数:

data (SceneData) -- Scene data.

返回:

A numpy array with shape (*data.shape, num_links, 3). Each velocity is composed of [vx, vy, vz].

返回类型:

NDArray[float]

Get the world poses of all links.

参数:

data (SceneData) -- Scene data.

返回:

A numpy array with shape (*data.shape,num_links, 7). Each pose is composed of [x, y, z, i, j, k, w],

返回类型:

NDArray[float]

Get all link rotation matrices.

参数:

data (SceneData) -- Scene data.

返回:

A numpy array with shape (*data.shape,num_links, 3, 3). Each rotation

返回类型:

NDArray[float]

matrix is in column-major order.

Get the world velocities (linear and angular) of all links.

参数:

data (SceneData) -- Scene data.

返回:

A numpy array with shape (*data.shape, num_links, 6). Each velocity is composed of [vx, vy, vz, wx, wy, wz].

返回类型:

NDArray[float]

get_sensor_value(id, data)#

Get the value of a specific sensor by its ID.

参数:
  • id (str) -- Sensor ID.

  • data (SceneData) -- Scene data.

返回:

Sensor values. Shape: (*data.shape, sensor_value_size)

返回类型:

NDArray[float]

get_sensor_values(names, data)#

Get the values of multiple sensors by their names, concatenated into a single array.

参数:
  • names (List[str]) -- List of sensor names.

  • data (SceneData) -- Scene data.

返回:

Concatenated sensor values with shape (*data.shape, total_sensor_values) where total_sensor_values is the sum of all queried sensors' value sizes.

返回类型:

NDArray[float]

get_site(key)#

Get a site by name or index.

参数:

key (str or int) -- Name or index of the site.

返回:

The site object, or None if not found.

返回类型:

Optional[Site]

get_site_index(name)#

Get site index by name.

参数:

name (str) -- Name of the site.

返回:

Index of the site, or None if not found.

返回类型:

Optional[int]

set_gravity_override(data, gravity)#

Override the gravity vector for the scene data.

参数:
  • data (SceneData) -- Scene data to modify.

  • gravity (NDArray[float]) -- The new gravity vector. - Shape (3,): Single value applied to all batches - Shape (*data.shape, 3): Per-batch values

备注

If any gravity component is NaN or infinite, the override will be ignored.

step(data)#

Advance the simulation by one step using the current model and data.

备注

If the data has batch dimension, motrixsim will run simulation in parallel

step_n(data, n)#

Advance the simulation by n steps using the current model and data.

参数:
  • data (SceneData) -- Scene data.

  • n (int) -- Number of steps to advance the simulation.

备注

This method can skip the python overhead when stepping multiple times.

actuator_ctrl_limits#

The actuator control ranges.

Return a 2-dimensional numpy array with shape (2, num_actuators). The first dimension is the minimum control value, and the second dimension is the maximum control value. If the limits do not set for a actuator, (-inf, inf) will be used as the limits.

Type:

NDArray[float]

actuator_names#

The list of actuator names in the world.

Return list of actuator names, can be None if the actuator does not have a name.

Type:

List[Optional[str]]

actuators#

Get all actuators defined in the model.

返回:

A list of all actuator objects in the world.

返回类型:

List[Actuator]

bodies#

The list of all bodies in the world.

备注

don't confuse the body in motrixsim with the body in mjcf. See 🤖 刚体 for more details.

Type:

List[Body]

body_names#

The list of all body names in the world.

Return list of body names, can be None if the body does not have a name.

Type:

List[Optional[str]]

cameras#

The camera manager for accessing cameras by name.

Type:

CameraMgr

floating_bases#

The list of all floating bases in the world.

Type:

List[FloatingBase]

geom_names#

The list of all geoms names in the world.

A list of geom names, can be None if the geom does not have a name.

Type:

List[Optional[str]]

geoms#

The list of all geoms in the world.

Type:

List[Geom]

joint_dof_pos_indices#

The start dof index for each joint in the dof positions array.

A list of start indices for each joint's dof positions in the dof positions array. size = num_joints.

备注

The DoF of floating base is not included.

Type:

List[int]

joint_dof_pos_nums#

The number of DoF positions for each joint.

List of position DoF sizes for each joint. size = num_joints

Type:

List[int]

joint_dof_vel_indices#

The start dof index for each joint in the dof velocities array.

A list of start indices for each joint's dof velocities in the dof velocities array.

备注

The DoF of floating base is not included.

Type:

List[int]

joint_dof_vel_nums#

The size of DoF velocities of each joint.

List of velocity DoF sizes for each joint. size = num_joints.

Type:

List[int]

joint_limits#

The joint position limits for each joint.

A 2-dimensional numpy array with shape (2, num_joints).

The first dimension is the minimum position limit, and the second dimension is the maximum position limit. If the limits are not set for a joint, -inf, inf will be used as the limits.

Type:

NDArray[float]

joint_names#

The list of all joint names in the world.

Return list of joint names, can be None if the joint does not have a name.

Type:

List[Optional[str]]

joints#

The list of all joints in the world.

Type:

List[Joint]

keyframes#

The list of all keyframes in the model.

Type:

List[Keyframe]

The list of all link names in the world.

A list of link names, can be None if the link does not have a name.

Type:

List[Optional[str]]

The list of all links in the world.

Type:

List[Link]

low#

The low-level model for advanced or internal simulation access.

This property exposes the underlying low-level scene model, which provides direct access to internal simulation data and advanced features.

备注

Do not use this property unless you know what you are doing.

Type:

LowSceneModel

num_actuators#

The number of actuators in the world.

Type:

int

num_bodies#

The number of bodies in the world.

Type:

int

num_dof_pos#

The number of DoF positions in the world.

Type:

int

num_dof_vel#

The number of DoF velocities in the world.

备注

This value may be different from the [num_dof_pos] because for some joint (like ball joint), we use Quaternion to represent the rotation, which has 4 components.

Type:

int

num_geoms#

The number of geoms in the world.

Type:

int

num_hfields#

The number of height fields in the world.

Type:

int

num_joints#

The number of joints in the world.

备注

freejoint in MJCF is not considered as a joint but a floating base.

Type:

int

num_keyframes#

The number of keyframes in the model.

Type:

int

The number of links in the world.

备注

The worldbody in MJCF is not considered as a link.

Type:

int

num_sensors#

The number of sensors in the world.

Type:

int

num_sites#

The number of sites in the world.

Type:

int

options#

The simulation options of the model.

Type:

Options

site_names#

The list of all site names in the world.

Type:

List[str]

sites#

The list of all sites in the world.

Type:

List[Site]

class motrixsim.Shape#

基类:object

The source shape type of a high-level geometry.

This mirrors Rust's msd::geom::ShapeType / GeometryShape and describes the user-facing geometry before compile-time lowering. A mesh high-level shape may lower to one or more low-level runtime collider shapes.

Methods:

type_names()

Returns all high-level source shape type names as a list of strings.

types()

Returns all high-level source shape types as a list.

Attributes:

static type_names()#

Returns all high-level source shape type names as a list of strings.

返回:

All high-level source shape type names.

返回类型:

List[str]

static types()#

Returns all high-level source shape types as a list.

返回:

All high-level source shape types.

返回类型:

List[Shape]

Capsule = Shape.Capsule#
Cuboid = Shape.Cuboid#
Cylinder = Shape.Cylinder#
Ellipsoid = Shape.Ellipsoid#
HField = Shape.HField#
InfinitePlane = Shape.InfinitePlane#
Mesh = Shape.Mesh#
Plane = Shape.Plane#
Sphere = Shape.Sphere#
class motrixsim.Site#

基类:object

The Site object represents a reference point or marker in the scene.

Methods:

get_jacobian(data)

Get the compact Jacobian matrix of the site.

get_pose(data)

Get the pose of the site in the world frame.

get_position(data)

Get the position of the site in the world frame.

get_rotation_mat(data)

Get the rotation matrix of the site in the world frame.

Attributes:

dof_vel_indices

Global DoF velocity indices that affect this site.

index

The index of the site in the site list.

local_pos

The local position of the site in the parent frame in (x, y, z).

local_quat

The local orientation of the site as a quaternion (i, j, k, w).

model

The model that this site belongs to.

name

The name of the site, or None if not set.

parent_link

The parent link of the site, or None if the site is attached to the world frame.

get_jacobian(data)#

Get the compact Jacobian matrix of the site.

The Jacobian maps DoF velocities to the site's spatial velocity in world frame. Only columns corresponding to dof_vel_indices are included.

参数:

data (SceneData) -- The scene data containing the current state.

返回:

Shape (*data.shape, 6, k) where k equals

len(self.dof_vel_indices). The first 3 rows are angular velocity, the last 3 rows are linear velocity.

返回类型:

NDArray[float]

get_pose(data)#

Get the pose of the site in the world frame.

参数:

data (SceneData) -- The scene data to query.

返回:

The pose of the site in the world frame. Shape: (*data.shape,7). The last axis is 7-element array with [x, y, z, i, j, k, w].

返回类型:

NDArray[float]

get_position(data)#

Get the position of the site in the world frame.

参数:

data (SceneData) -- The scene data to query.

返回:

The position of the site in the world frame. Shape: (*data.shape,3).

返回类型:

NDArray[float]

get_rotation_mat(data)#

Get the rotation matrix of the site in the world frame.

参数:

data (SceneData) -- The scene data to query.

返回:

The rotation matrix of the site in the world frame. shape =

(*data.shape,3,3).

返回类型:

NDArray[float]

dof_vel_indices#

Global DoF velocity indices that affect this site.

返回:

Shape (k,) where k is the number of DoFs on the kinematic path

from root to this site's parent link.

返回类型:

NDArray[int]

备注

This is a model property determined by the kinematic tree topology. It does not depend on simulation state and can be cached by the user.

index#

The index of the site in the site list.

Type:

int

local_pos#

The local position of the site in the parent frame in (x, y, z).

Type:

NDArray[float]

local_quat#

The local orientation of the site as a quaternion (i, j, k, w).

Type:

NDArray[float]

model#

The model that this site belongs to.

name#

The name of the site, or None if not set.

Type:

Optional[str]

The parent link of the site, or None if the site is attached to the world frame.

Type:

Link

class motrixsim.TerrainScanner(terrain, frame, offsets, alignment='yaw', output='height')#

基类:object

A scanner object for batched frame-relative terrain height sampling.

TerrainScanner caches all static parameters (terrain geom, reference frame, scan offsets, alignment mode, output mode) at construction time so that the hot-path scan() call only reads batched poses and writes results — no parameter parsing, no temporary array allocation.

Typical usage for RL locomotion height-scan:

scanner = motrixsim.TerrainScanner(
    terrain=hfield_geom,
    frame=base_link,
    offsets=scan_offsets,       # shape (N, 2)
    alignment="yaw",
    output="height",
)

# in step loop (hot path)
heights = scanner.scan(data, out=buffer)
参数:
  • terrain (GeomHField) -- The height-field geom to sample.

  • frame (Link) -- The reference frame whose pose drives the scan.

  • offsets (NDArray[float]) -- Frame-local XY scan points, shape (N, 2).

  • alignment (str) -- How the frame orientation is projected. "yaw" — only the heading (rotation about world Z) is used; roll and pitch are ignored.

  • output (str) -- What quantity to return. "height" — terrain surface world-Z coordinate. "clearance"frame_z - terrain_height, i.e. vertical distance from the frame origin to the terrain surface below each scan point.

Methods:

scan(data[, out])

Perform a batched terrain height scan.

scan(data, out=None)#

Perform a batched terrain height scan.

For each batch instance the method reads the frame link pose, extracts the yaw heading, rotates each local offset into world XY, samples the terrain height via bilinear interpolation, and writes the result.

参数:
  • data (SceneData) -- The scene data (batched or single).

  • out (Optional[NDArray[float]]) -- Pre-allocated output buffer of shape (*data.shape, N) where N is the number of scan points. When provided, the result is written in-place and returned directly, avoiding an internal allocation.

返回:

Shape (*data.shape, N).

When output="height", each element is the terrain surface world-Z at the corresponding scan point. When output="clearance", each element is frame_z - terrain_height.

返回类型:

NDArray[float]

class motrixsim.VelocityActuator#

基类:Actuator

Velocity actuator (MJCF <velocity>).

MJCF parameter mapping:

  • kv -> kv (writes both gain and damping internally)

Methods:

get_kv_override(data)

Get the kv override value from the scene data.

set_kv_override(data, kv)

Override the kv value for a velocity actuator.

get_kv_override(data)#

Get the kv override value from the scene data.

参数:

data (SceneData) -- The scene data to query.

返回:

The kv value. Shape: (*data.shape,)

返回类型:

NDArray[float]

set_kv_override(data, kv)#

Override the kv value for a velocity actuator. Writes both gain and damping.

参数:
  • data (SceneData) -- The scene data to modify.

  • kv (NDArray[float]) -- The new kv value. - Shape (): Single value applied to all batches - Shape: (*data.shape,): Per-batch values

备注

Raises ValueError if the value is negative, NaN, infinite, or the actuator is not a velocity actuator.

motrixsim.forward_kinematic(model, data)#

Run forward kinematic only.

参数:
motrixsim.load_mjcf_str(mjcf)#

Load a model from a string containing MJCF data.

参数:

mjcf (str) -- The MJCF data as a string.

返回:

The loaded scene model.

返回类型:

SceneModel

motrixsim.load_model(path)#

Load a model from the given file path.

参数:
  • path (str) -- The path to the model file.

  • supported. (currently mjcf and urdf are)

返回:

The loaded scene model.

返回类型:

SceneModel

motrixsim.step(model, data)#

Advance the simulation by one step.

参数: