platforms_pymujoco
PyMuJoCo Platforms Module.
This module provides platform implementations for the Python MuJoCo simulator, mirroring the platform interface in robotblockset.platforms.
- class robotblockset.mujoco.platforms_pymujoco.platform_pymujoco(platform_name: str, scene: mujoco_scene | None = None, **kwargs: Any)[source]
Bases:
platformPyMuJoCo-backed mobile platform interface operating on a
mujoco_scene.Initialize a PyMuJoCo platform interface.
- Parameters:
platform_name (str) – Base name of the platform model in MuJoCo.
scene (
mujoco_scene, optional) – MuJoCo scene instance to control. Must be provided.**kwargs (Any) – Additional keyword arguments.
Notes
When constructing objects of this class, the following keyword arguments can explicitly configure model element names. If omitted, names are derived from the platform name:
- JointNameslist[str], optional
Explicit list of platform joint names.
- ActuatorNameslist[str], optional
Explicit list of actuator names used for velocity commands.
- RobotBaseNamestr, optional
Name of the robot base body used as the platform reference frame.
- SensorJointPosNameslist[str], optional
Sensor names used to read joint positions.
- SensorJointVelNameslist[str], optional
Sensor names used to read joint velocities.
- SensorPosNamestr, optional
Sensor name used to read the platform position.
- SensorOriNamestr, optional
Sensor name used to read the platform orientation.
- SensorLinVelNamestr, optional
Sensor name used to read the platform linear velocity.
- SensorRotVelNamestr, optional
Sensor name used to read the platform angular velocity.
- SensorForceNamestr, optional
Sensor name used to read force measurements.
- SensorTorqueNamestr, optional
Sensor name used to read torque measurements.
- Raises:
Exception – If joint or actuator names do not resolve uniquely in the MJCF model.
- __init__(platform_name: str, scene: mujoco_scene | None = None, **kwargs: Any) None[source]
Initialize a PyMuJoCo platform interface.
- Parameters:
platform_name (str) – Base name of the platform model in MuJoCo.
scene (
mujoco_scene, optional) – MuJoCo scene instance to control. Must be provided.**kwargs (Any) – Additional keyword arguments.
Notes
When constructing objects of this class, the following keyword arguments can explicitly configure model element names. If omitted, names are derived from the platform name:
- JointNameslist[str], optional
Explicit list of platform joint names.
- ActuatorNameslist[str], optional
Explicit list of actuator names used for velocity commands.
- RobotBaseNamestr, optional
Name of the robot base body used as the platform reference frame.
- SensorJointPosNameslist[str], optional
Sensor names used to read joint positions.
- SensorJointVelNameslist[str], optional
Sensor names used to read joint velocities.
- SensorPosNamestr, optional
Sensor name used to read the platform position.
- SensorOriNamestr, optional
Sensor name used to read the platform orientation.
- SensorLinVelNamestr, optional
Sensor name used to read the platform linear velocity.
- SensorRotVelNamestr, optional
Sensor name used to read the platform angular velocity.
- SensorForceNamestr, optional
Sensor name used to read force measurements.
- SensorTorqueNamestr, optional
Sensor name used to read torque measurements.
- Raises:
Exception – If joint or actuator names do not resolve uniquely in the MJCF model.
- simtime() float[source]
Return the current simulation time from the MuJoCo simulator.
- Returns:
The current simulation time in seconds since an arbitrary point (see ResetTime).
- Return type:
float
- isReady() bool[source]
Check if the platform is connected.
- Returns:
True if the simulator connection is active.
- Return type:
bool
- isActive() bool[source]
Check whether the simulator is running.
- Returns:
Trueif the scene is not paused.- Return type:
bool
- Restart(qpos: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...] | None = None, u: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...] | None = None, reset: bool = True, keyframe: int | None = None, mocap_list: Sequence[str | int] | None = None) None[source]
Restart the simulation.
- Parameters:
qpos (ArrayLike, optional) – Full generalized-position vector to apply after reset.
u (ArrayLike, optional) – Joint command vector to apply after reset.
reset (bool, optional) – If
True, reset the simulator before applying state updates.keyframe (int, optional) – Keyframe index used for simulator reset.
mocap_list (sequence of str or int, optional) – Names or body IDs of mocap bodies whose poses should be preserved during reset.
- Raises:
TypeError – If a mocap_list entry is not a body name or integer body ID.
ValueError – If a requested body does not exist or is not a mocap body.
- Set_vel(v: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], wait: float | None = None) int[source]
Update platform velocities (forward, turn) and wait.
- Parameters:
v (ArrayLike) – Desired planar velocity
[vx, wz].wait (float, optional) – Time to wait (in seconds) to synchronize the command to move. If omitted,
self.tsampis used.
- Returns:
Status of the move (0 for success, non-zero for error).
- Return type:
int
- SendRobot_u(u: ndarray) None[source]
Send joint commands to platform actuators.
- Parameters:
u (JointVelocityType) – Actuator command vector.
- SendCtrl(u: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...]) None[source]
Send a full control vector to the MuJoCo platform.
- Parameters:
u (ArrayLike) – Full actuator control vector for the MuJoCo scene.
- SendAuxCtrl(idx: Sequence[int], val: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...]) None[source]
Update selected actuator controls by index.
- Parameters:
idx (Sequence[int]) – Actuator indices to update.
val (ArrayLike) – Control values written to the selected actuators.
- Return type:
None
- Raises:
TypeError – If an actuator index is not an integer.
ValueError – If an actuator index is out of range or the number of values does not match the number of indices.
- GetAuxJointPos(ide: Sequence[int]) ndarray[source]
Return joint positions for auxiliary joints by index.
- Parameters:
ide (Sequence[int]) – Joint indices in
self.scene.data.qpos.- Returns:
Joint positions for the requested indices.
- Return type:
JointConfigurationType
- GetSensor(ide: str | int | None = None) ndarray[source]
Read sensor data by name/id or return the full sensor array.
- Parameters:
ide (str or int, optional) – Sensor identifier. If omitted, all sensor samples are returned.
- Returns:
Selected sensor data, or all sensor data if no identifier is provided.
- Return type:
np.ndarray
- GetContacts(ide: str | int | None = None) ndarray | None[source]
Return contact forces for a geom or for all contacts.
- Parameters:
ide (str or int, optional) – Optional geom identifier. If None, all contacts are reported.
- Returns:
Contact-force array of shape
(N, 3), orNoneif there are no contacts.- Return type:
np.ndarray or None
- SetMocapPose(ide: str | int, x: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...]) None[source]
Set the pose of a mocap body.
- Parameters:
ide (ObjectIdType) – Mocap body name or ID.
x (PoseInputType) – Mocap pose.
- Raises:
ValueError – If the mocap body cannot be resolved or if the pose shape is unsupported.
Note
When mocap body names are used, mocap bodies have to be first bodies in the model!
- GetMocapPose(ide: str | int, out: str = 'x') ndarray | None[source]
Return mocap body pose in the requested output format.
- Parameters:
ide (str | int) – Mocap body name or id.
out (str, optional) – Output pose format.
- Returns:
Mocap body pose in the requested format, or
Noneif the mocap body could not be resolved.- Return type:
Pose3DType | HomogeneousMatrixType | Vector3DType | RotationMatrixType | None
- GetObjectData(ide: str | int) Any[source]
Return raw MuJoCo body data for a body name or ID.
- Parameters:
ide (ObjectIdType) – Body name or id.
- Returns:
Raw MuJoCo body data object.
- Return type:
Any
- GetObjectPose(typ: str, ide: str | int, out: str = 'x') ndarray | None[source]
Return the pose of a body, site, or geom in the requested format.
- Parameters:
typ (str) – Object type (“body”, “site”, or “geom”).
ide (ObjectIdType) – Object name or id.
out (str, optional) – Output pose format understood by
robotblockset.transformations.map_pose().
- Returns:
Pose of the requested object, or
Nonewhen the object type is unsupported.- Return type:
PoseOutputType or None
- SetObjectPose(ide: str | int, x: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...]) None[source]
Set a body pose from a spatial representation.
- Parameters:
ide (ObjectIdType) – Body name or id.
x (PoseInputType) – Pose represented as position, quaternion, pose vector, rotation matrix, or homogeneous transform.
- Return type:
None
- Raises:
ValueError – If
xhas an unsupported shape.
- class robotblockset.mujoco.platforms_pymujoco.tiagobase(platform_name: str = 'tiagobase', scene: mujoco_scene | None = None, **kwargs: Any)[source]
Bases:
platform_pymujoco,tiagobase_specPyMuJoCo platform wrapper for the PAL Robotics Tiago Base.
Create a TiagoBase platform backed by PyMuJoCo.
- Parameters:
platform_name (str, optional) – Base name of the platform in the MuJoCo model.
scene (
mujoco_scene, optional) – Scene instance that owns the MuJoCo model and data.**kwargs (Any) – Additional keyword arguments passed to
platform_pymujoco, including optional joint, actuator, base-body, and sensor names.
- __init__(platform_name: str = 'tiagobase', scene: mujoco_scene | None = None, **kwargs: Any) None[source]
Create a TiagoBase platform backed by PyMuJoCo.
- Parameters:
platform_name (str, optional) – Base name of the platform in the MuJoCo model.
scene (
mujoco_scene, optional) – Scene instance that owns the MuJoCo model and data.**kwargs (Any) – Additional keyword arguments passed to
platform_pymujoco, including optional joint, actuator, base-body, and sensor names.
- class robotblockset.mujoco.platforms_pymujoco.mir100_pymujoco(platform_name: str = 'mir', scene: mujoco_scene | None = None, **kwargs: Any)[source]
Bases:
platform_pymujoco,mir100_specPyMuJoCo platform wrapper for the MiR100 mobile base.
Create a MiR100 platform backed by PyMuJoCo.
- Parameters:
platform_name (str, optional) – Base name of the platform in the MuJoCo model.
scene (
mujoco_scene, optional) – Scene instance that owns the MuJoCo model and data.**kwargs (Any) – Additional keyword arguments passed to
platform_pymujoco, including optional joint, actuator, base-body, and sensor names.
- __init__(platform_name: str = 'mir', scene: mujoco_scene | None = None, **kwargs: Any) None[source]
Create a MiR100 platform backed by PyMuJoCo.
- Parameters:
platform_name (str, optional) – Base name of the platform in the MuJoCo model.
scene (
mujoco_scene, optional) – Scene instance that owns the MuJoCo model and data.**kwargs (Any) – Additional keyword arguments passed to
platform_pymujoco, including optional joint, actuator, base-body, and sensor names.
Classes
|
PyMuJoCo platform wrapper for the MiR100 mobile base. |
|
PyMuJoCo-backed mobile platform interface operating on a |
|
PyMuJoCo platform wrapper for the PAL Robotics Tiago Base. |