motrixsim#
Classes:
The Actuator object represents a controllable actuator in the simulation. |
|
The Body object represents a rigid body in the scene. |
|
The Camera object in the scene. |
|
|
|
The FloatingBase object represents a floating base in the scene. |
|
The Geom object represents a geometry in the scene. |
|
The HField object represents a height field terrain in the scene. |
|
The Joint object represents a joint in the scene. |
|
The Link object represents a kinematic link in the scene. |
|
The Mocap object represents a motion capture body in the scene. |
|
The Options object represents the simulation options. |
|
|
The SceneData object represents the simulation state. |
The SceneModel object represents the entire simulation world. |
|
The Site object represents a reference point or marker in the scene. |
Functions:
|
Run forward kinematic only. |
|
Load a model from a string containing MJCF data. |
|
Load a model from the given file path. |
|
Advance the simulation by one step. |
- class motrixsim.Actuator#
基类:
objectThe Actuator object represents a controllable actuator in the simulation.
This class provides access to the properties and methods of an actuator, allowing users to query its name, index, control range, and set the control value.
Methods:
get_ctrl(data)Get the control value of the actuator.
set_ctrl(data, ctrl)Set the control value of the actuator.
Attributes:
The control range of the actuator.
The index of the actuator in the simulation world.
The name of the actuator.
The name of the actuator target.
The type of the actuator target.
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. If the data has batch dimension, ctrl must have the same shape as the data.
- ctrl_range#
The control range of the actuator.
Returns None if not set.
- Type:
Optional[Tuple[float, float]]
- 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.Body#
基类:
objectThe 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_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:
The floating base object.
Whether the body is a mocap (kinematic) body.
Convert this body to a mocap object if it is a mocap body.
The name of the body.
The number of DoF positions of all joints on the body.
The number of DoF velocities of all joints on the body.
The number of joints that belong to this body.
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, y, z, i, j, k, w].
- 返回类型:
NDArray[float]
- 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 [i, j, k, w].
- 返回类型:
NDArray[float]
- 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_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.
- floatingbase#
The floating base object.
Return None if not present.
备注
In mjcf, a body is free moving if it has <freejoint>
- Type:
Optional[FloatingBase]
- 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]
- name#
The name of the body.
Return None if not present.
- Type:
Optional[str]
- 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
- num_links#
The number of links that belong to this body.
- Type:
int
- class motrixsim.Camera#
基类:
objectThe 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:
Whether the camera is in depth-only mode.
Get the far plane distance of the camera.
The index of the camera in the
motrixsim.SceneModel.cameras().The scene model that this camera belongs to.
Get the name of the camera.
Get the far plane distance of the camera.
Get the render target of the camera, either "window" or "image".
- 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
- index#
The index of the camera in the
motrixsim.SceneModel.cameras().- Type:
int
- model#
The scene model that this camera belongs to.
- Type:
- name#
Get the name of the camera.
- Type:
Option[str]
- near_plane#
Get the far plane distance of the camera.
- Type:
float
- render_target#
Get the render target of the camera, either "window" or "image".
- Type:
str
- class motrixsim.CameraMgr#
基类:
objectAttributes:
All the cameras defined in the model.
The scene model that this camera manager belongs to.
- model#
The scene model that this camera manager belongs to.
- Type:
- class motrixsim.ContactQuery#
基类:
objectMethods:
is_colliding(geom_pairs)Given a list of geometry pairs, check if they are colliding.
Attributes:
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)#
基类:
objectAttributes:
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#
基类:
objectThe 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.
Extract the world angular velocity of the floating base from the dof velocity array.
Extract the world linear velocity of the floating base from the dof velocity array.
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:
The DoF position indices of the floating base.
The DoF position address of the floating base in the
motrixsim.SceneData.dof_pos().The DoF velocity indices of the floating base.
The DoF velocity address of the floating base in the
motrixsim.SceneData.dof_vel().The index of the floatingbase in the
motrixsim.SceneModel.floating_bases().The scene model this floating base belongs to.
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:
- name#
The name of the floating base.
Return None if not set.
- Type:
Optional[str]
- class motrixsim.Geom#
基类:
objectThe 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.
Methods:
get_angular_velocity(data)Get the world angular velocity of the geom.
get_linear_velocity(data)Get the world linear velocity of the geom.
get_pose(data)Get the world pose of the geom.
Attributes:
The index of the geom in the
motrixsim.SceneModel.geoms().The scene model that this geom belongs to.
The name 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_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]
- index#
The index of the geom in the
motrixsim.SceneModel.geoms().- Type:
int
- model#
The scene model that this geom belongs to.
- Type:
- name#
The name of the geom. Must be unique within the scene.
- 返回:
The name of the geom, or "None" if not set.
- 返回类型:
Optional[str]
- class motrixsim.HField#
基类:
objectThe 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:
Get the bounding box of the height field in local space.
Get the height matrix data as a numpy array.
The index of the hfield in the scene.
The scene model that this hfield belongs to.
The name of the hfield.
The number of columns in the height field grid.
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.
- 返回类型:
NDArray[float]
- index#
The index of the hfield in the scene.
- Type:
int
- model#
The scene model that this hfield belongs to.
- Type:
- 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#
基类:
objectThe 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_dof_pos(data)Get the DoF positions of the joint.
get_dof_vel(data)Get the DoF velocities 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.
Attributes:
The position DoF address of the joint.
The velocity DoF address of the joint.
The index of the joint in the
motrixsim.SceneModel.joints().The link this joint is attached to.
The index of the link this joint is attached to.
The scene model this joint belongs to.
The name of the joint.
The number of position DoFs of the joint.
The number of velocity DoFs of the joint.
- 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]
- 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())
- 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
- index#
The index of the joint in the
motrixsim.SceneModel.joints().- Type:
int
- link_index#
The index of the link this joint is attached to.
- Type:
int
- model#
The scene model this joint belongs to.
- Type:
- 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
- class motrixsim.Link#
基类:
objectThe 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:
get_angular_velocity(data)Get the world angular velocity of the link.
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_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_mass(mass)Set the custom mass for a link.
Attributes:
The index of the link in the
motrixsim.SceneModel.links().The joint indices of this link in the
motrixsim.SceneModel.joints().The scene model that this link belongs to.
The name of the link.
The number of joints associated with this link.
- 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_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_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]
- set_mass(mass)#
Set the custom mass for a link.
- 参数:
mass (Real) -- The new mass.
- 返回:
True if the set operation success. False if fail due to the setting opearation on a Mocap type link or an internal virtual link.
- 返回类型:
bool
备注
This function change the model directly.
- 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]
- model#
The scene model that this link belongs to.
- Type:
- 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.
- 返回:
the number of joints associated with this link.
- 返回类型:
int
- class motrixsim.Mocap#
基类:
objectThe 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:
- 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)
- model#
The scene model this mocap belongs to.
- Type:
- class motrixsim.Options#
基类:
objectThe Options object represents the simulation options.
This class is used to configure the simulation options. You can access it through model.options.
Attributes:
Is all contact constraints disabled in the simulation?
Is the gravity disabled in the simulation?
Is impedance effects disabled in the simulation?
The gravity vector applied to the simulation.
The maximum number of iterations for the solver.
The tolerance for the solver.
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
- disable_impedance#
Is impedance effects 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.SceneData(model, batch=Ellipsis)#
基类:
objectThe 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:
The all the actuator control values.
The dof position array of the world.
The dof velocity array of the world.
The low-level data object for advanced simulation control.
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. shape = (*data.shape, num_dof_pos).
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
- 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#
基类:
objectThe 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 the initial DoF positions for the world.
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_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_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_index(name)Get the link index by its name.
get_link_poses(data)Get the world poses of all links.
get_link_rotation_mats(data)Get all link rotation matrices.
get_sensor_value(id, data)Get the value of a specific sensor by its ID.
get_site(key)Get a site by name or index.
get_site_index(name)Get site index by name.
step(data)Advance the simulation by one step using the current model and data.
Attributes:
The actuator control ranges.
The list of actuator names in the world.
Get all actuators defined in the model.
The list of all bodies in the world.
The list of all body names in the world.
All the cameras in the scene.
The list of all floating bases in the world.
The list of all geoms names in the world.
The list of all geoms in the world.
The start dof index for each joint in the dof positions array.
The number of DoF positions for each joint.
The start dof index for each joint in the dof velocities array.
The size of DoF velocities of each joint.
The joint position limits for each joint.
The list of all joint names in the world.
The list of all joints in the world.
The list of all link names in the world.
The list of all links in the world.
The low-level model for advanced or internal simulation access.
The number of actuators in the world.
The number of bodies in the world.
The number of DoF positions in the world.
The number of DoF velocities in the world.
The number of geoms in the world.
The number of height fields in the world.
The number of joints in the world.
The number of links in the world.
The number of sensors in the world.
The number of sites in the world.
The simulation options of the model.
The list of all site names in the world.
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]
- 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_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.
- 返回类型:
- 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_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_link(arg)#
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_link_index(name)#
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_link_poses(data)#
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_link_rotation_mats(data)#
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_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_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]
- 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
- 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 🤖 刚体(Body) 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#
All the cameras in the scene.
- 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]]
- 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]]
- link_names#
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]]
- 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_links#
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
- site_names#
The list of all site names in the world.
- Type:
List[str]
- class motrixsim.Site#
基类:
objectThe Site object represents a reference point or marker in the scene.
Methods:
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:
The index of the site in the site list.
The local position of the site in the parent frame in (x, y, z).
The local orientation of the site as a quaternion (i, j, k, w).
The model that this site belongs to.
The name of the site, or None if not set.
The parent link of the site, or None if the site is attached to the world frame.
- 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]
- 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]
- motrixsim.forward_kinematic(model, data)#
Run forward kinematic only.
- 参数:
model (SceneModel) -- The scene model.
data (SceneData) -- The scene data.
- 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.
- 返回类型:
- 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.
- 返回类型:
- motrixsim.step(model, data)#
Advance the simulation by one step.
- 参数:
model (SceneModel) -- The scene model.
data (SceneData) -- The scene data.