platforms_pymujoco_sim

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_sim.platform_pymujoco(platform_name: str, scene: mujoco_scene | None = None, tsamp: float = 0.0, **kwargs: Any)[source]

Bases: platform

Synchronous PyMuJoCo-backed mobile platform interface.

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.

  • tsamp (float, optional) – Requested control sampling period in seconds.

  • **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, tsamp: float = 0.0, **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.

  • tsamp (float, optional) – Requested control sampling period in seconds.

  • **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() None[source]

Initialize MuJoCo handles and cached sensor indices.

Return type:

None

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

GetState() None[source]

Update platform state from MuJoCo data buffers.

Return type:

None

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:

True if 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.

Stop() None[source]

Stop platform motion and clear velocity commands.

Return type:

None

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) – Duration for which the command is held. If omitted, self.tsamp is 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), or None if 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 None if 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 None when 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 x has an unsupported shape.

SetEquality(ide: str | int, val: int | bool) None[source]

Set an equality constraint activation flag.

Parameters:
  • ide (ObjectIdType) – Equality constraint name or id.

  • val (Union[int, bool]) – Activation flag.

Return type:

None

class robotblockset.mujoco.platforms_pymujoco_sim.tiagobase(platform_name: str = 'tiagobase', scene: mujoco_scene | None = None, **kwargs: Any)[source]

Bases: platform_pymujoco, tiagobase_spec

Synchronous PyMuJoCo platform wrapper for the PAL Robotics Tiago Base.

Create a TiagoBase platform backed by the synchronous PyMuJoCo simulator.

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 the synchronous PyMuJoCo simulator.

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_sim.mir100_pymujoco(platform_name: str = 'mir', scene: mujoco_scene | None = None, **kwargs: Any)[source]

Bases: platform_pymujoco, mir100_spec

Synchronous PyMuJoCo platform wrapper for the MiR100 mobile base.

Create a MiR100 platform backed by the synchronous PyMuJoCo simulator.

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 the synchronous PyMuJoCo simulator.

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

mir100_pymujoco([platform_name, scene])

Synchronous PyMuJoCo platform wrapper for the MiR100 mobile base.

platform_pymujoco(platform_name[, scene, tsamp])

Synchronous PyMuJoCo-backed mobile platform interface.

tiagobase([platform_name, scene])

Synchronous PyMuJoCo platform wrapper for the PAL Robotics Tiago Base.