robots_mujoco

Robot interfaces for the socket-based MuJoCo backend.

This module provides RobotBlockSet robot backends that communicate with an external MuJoCo simulator through mjInterface, together with concrete robot wrappers for supported manipulators and mobile platforms.

class robotblockset.mujoco.robots_mujoco.robot_mujoco(robot_name: str, scene: mjInterface | None = None, host: str = 'localhost', port: int = 50000, **kwargs: Any)[source]

Bases: robot

MuJoCo-backed robot interface using the socket-based server API.

Attributes:
  • scene (mjInterface) – Socket-based MuJoCo interface used to exchange state and commands.

  • BaseName (str) – Base model name used to derive joint, actuator, and sensor names.

  • JointNames (list[str]) – Ordered list of robot joint names.

  • ActuatorNames (list[str]) – Ordered list of actuator names used for joint commands.

  • MocapNames (list[str]) – Names of MuJoCo mocap bodies associated with the scene.

Create a MuJoCo-backed robot interface.

Parameters:
  • robot_name (str) – Base name of the robot model in MuJoCo.

  • scene (mjInterface, optional) – Existing MuJoCo interface instance. If None, a new connection is created.

  • host (str, optional) – Hostname of the MuJoCo simulator.

  • port (int, optional) – Port of the MuJoCo simulator.

  • **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 robot name:

JointNameslist[str] or str, optional

Explicit joint names, or "gen" to generate names from robot_name.

ActuatorNameslist[str], optional

Explicit actuator names.

FlangeNamestr, optional

Name of the flange or end-effector body.

TCPNamestr, optional

Name of the tool center point body or site.

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 Cartesian position.

SensorOriNamestr, optional

Sensor name used to read Cartesian orientation.

SensorLinVelNamestr, optional

Sensor name used to read Cartesian linear velocity.

SensorRotVelNamestr, optional

Sensor name used to read Cartesian 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__(robot_name: str, scene: mjInterface | None = None, host: str = 'localhost', port: int = 50000, **kwargs: Any) None[source]

Create a MuJoCo-backed robot interface.

Parameters:
  • robot_name (str) – Base name of the robot model in MuJoCo.

  • scene (mjInterface, optional) – Existing MuJoCo interface instance. If None, a new connection is created.

  • host (str, optional) – Hostname of the MuJoCo simulator.

  • port (int, optional) – Port of the MuJoCo simulator.

  • **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 robot name:

JointNameslist[str] or str, optional

Explicit joint names, or "gen" to generate names from robot_name.

ActuatorNameslist[str], optional

Explicit actuator names.

FlangeNamestr, optional

Name of the flange or end-effector body.

TCPNamestr, optional

Name of the tool center point body or site.

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 Cartesian position.

SensorOriNamestr, optional

Sensor name used to read Cartesian orientation.

SensorLinVelNamestr, optional

Sensor name used to read Cartesian linear velocity.

SensorRotVelNamestr, optional

Sensor name used to read Cartesian 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.

Notes

The method resolves joint, actuator, site, sensor, and mocap handles and then initializes the RobotBlockSet state.

GetState() None[source]

Update robot state from MuJoCo data buffers.

Notes

Joint, Cartesian, force-torque, and object-following state are updated from the current simulator buffers.

isReady() bool[source]

Return whether the simulator connection is active.

Returns:

True if the MuJoCo connection is active.

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) 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.

Notes

The method optionally resets the simulator, applies state and control vectors, clears joint velocities, and resets RobotBlockSet timing and targets.

GoTo_q(q: ndarray, qdot: ndarray | None = None, trq: ndarray | None = None, wait: float | None = None, **kwargs: Any) int[source]

Update joint positions and wait.

This method sets the commanded joint positions (q), velocities (qdot), and torques (trq), then sends them to the robot and waits for the specified time (wait).

Parameters:
  • q (JointConfigurationType) – Desired joint positions (nj,).

  • qdot (JointVelocityType, optional) – Desired joint velocities (nj,).

  • trq (JointTorqueType, optional) – Desired joint torques (nj,).

  • wait (float, optional) – Time to wait (in seconds) to synchronize the command to move. If omitted, self.tsamp is used.

Returns:

Status of the move (0 for success, non-zero for error).

Return type:

int

Notes

The method sends the joint command to MuJoCo, updates the RobotBlockSet command state, and synchronizes with the requested wait time.

SetStrategy(strategy: str) None[source]

Set the control strategy.

Parameters:

strategy (str) – Requested control strategy.

Notes

The socket-based MuJoCo wrapper currently keeps a single joint-position strategy and accepts this method for compatibility.

SendRobot_u(u: ndarray) None[source]

Send joint commands to MuJoCo actuators.

Parameters:

u (JointConfigurationType) – Joint command vector.

Raises:

ValueError – If u does not contain exactly self.nj commands.

SendCtrl(u: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...]) None[source]

Send a full control vector to the MuJoCo actuators.

Parameters:

u (ArrayLike) – Full actuator control vector.

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 to assign.

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(idx: Sequence[int]) ndarray | None[source]

Return joint positions for auxiliary joints by index.

Parameters:

idx (Sequence[int]) – Joint-position indices to read.

Returns:

Joint positions for the selected indices, if available.

Return type:

np.ndarray | None

GetSensor(ide: str | int | Sequence[int] | None = None) ndarray | None[source]

Read sensor data by name or ID, or return the full sensor array.

Parameters:

ide (str, int, or sequence of int, optional) – Sensor name, scalar sensor ID, or sequence of sensor IDs. Data for multiple IDs is concatenated in the requested order. If None, all sensor samples are returned.

Returns:

Selected sensor data, the full sensor array, or None if a sensor cannot be resolved.

Return type:

np.ndarray | None

Raises:

TypeError – If ide is not a sensor name, integer ID, sequence of integer IDs, or None.

GetContacts(ide: str | int | Sequence[int] | None = None) ndarray | None[source]

Return contact forces for a geom or for all contacts.

Parameters:

ide (str, int, or sequence of int, optional) – Geom name, scalar geom ID, or sequence of geom IDs. If None, all contacts are reported.

Returns:

Contact forces in world coordinates, or None if there are no contacts or a geom cannot be resolved.

Return type:

np.ndarray | None

Raises:

TypeError – If ide is not a geom name, integer ID, sequence of integer IDs, or None.

SetRobotPose(x: ndarray) None[source]

Set the robot base pose.

Parameters:

x (Union[Pose3DType, HomogeneousMatrixType]) – The pose of the base (7,) or (4, 4).

Return type:

None

Raises:

ValueError – If the base pose shape is not recognized.

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 pose shape is unsupported.

GetMocapPose(ide: str | int, out: str = 'x') ndarray | None[source]

Return a mocap-body pose in the requested output format.

Parameters:
Returns:

Mocap-body pose, or None if it cannot be resolved.

Return type:

Pose3DType or HomogeneousMatrixType or Vector3DType or RotationMatrixType or None

GetObjectData(ide: str | int) Any | None[source]

Return raw MuJoCo body data for a body name or ID.

Parameters:

ide (str or int) – Body name or ID.

Returns:

Body data, or None if the body cannot be resolved.

Return type:

Any or None

GetObjectPose(typ: str, ide: str | int, out: str = 'x') ndarray | None[source]

Return the pose of a body, site, or geom.

Parameters:
Returns:

Object pose, or None if the object cannot be resolved.

Return type:

Pose3DType or HomogeneousMatrixType or Vector3DType or RotationMatrixType or None

SetObjectPose(ide: str | int, x: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...]) None[source]

Set a MuJoCo body pose from a spatial representation.

Parameters:
  • ide (str or int) – Body name or ID.

  • x (Pose3DType or HomogeneousMatrixType or RotationMatrixType or Vector3DType or QuaternionType or ArrayLike) – Body pose, position, or orientation.

Raises:

ValueError – If the pose shape is unsupported.

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

Set an equality-constraint activation flag.

Parameters:
  • ide (str or int) – Equality-constraint name or ID.

  • val (int or bool) – Activation flag.

SetBasePlatform(platform: Any, x: ndarray | None = None) None[source]

Attach or detach a base platform.

Parameters:
  • platform (Any) – Platform to attach, or None to detach the current platform.

  • x (Pose3DType or HomogeneousMatrixType or RotationMatrixType or Vector3DType, optional) – Platform pose. If omitted, the robot base is read from the model.

UpdateRobotBaseFromModel() ndarray[source]

Update the cached robot base pose from the MuJoCo model.

SimulatorMessage(msg: str) None[source]

Send a message to the simulator UI.

Parameters:

msg (str) – Message to display.

sim(dt: float) None[source]

Advance the simulator for a fixed duration.

Parameters:

dt (float) – Nonnegative simulation duration in seconds.

Raises:
  • ValueError – If dt is not a finite, nonnegative real scalar.

  • RuntimeError – If MuJoCo returns invalid simulation time or simulation time does not advance for one second.

class robotblockset.mujoco.robots_mujoco.panda(robot_name: str = 'panda', **kwargs: Any)[source]

Bases: robot_mujoco, panda_spec

MuJoCo robot wrapper for the Franka Panda manipulator.

Create a Panda robot in MuJoCo.

Parameters:
  • robot_name (str, optional) – Base name of the robot model in MuJoCo.

  • **kwargs (Any) – Additional keyword arguments passed to robot_mujoco, including optional joint, actuator, flange, TCP, and sensor names.

__init__(robot_name: str = 'panda', **kwargs: Any) None[source]

Create a Panda robot in MuJoCo.

Parameters:
  • robot_name (str, optional) – Base name of the robot model in MuJoCo.

  • **kwargs (Any) – Additional keyword arguments passed to robot_mujoco, including optional joint, actuator, flange, TCP, and sensor names.

class robotblockset.mujoco.robots_mujoco.fr3(robot_name: str = 'fr3', **kwargs: Any)[source]

Bases: robot_mujoco, fr3_spec

MuJoCo robot wrapper for the Franka Research 3 manipulator.

Create an FR3 robot in MuJoCo.

Parameters:
  • robot_name (str, optional) – Base name of the robot model in MuJoCo.

  • **kwargs (Any) – Additional keyword arguments passed to robot_mujoco, including optional joint, actuator, flange, TCP, and sensor names.

__init__(robot_name: str = 'fr3', **kwargs: Any) None[source]

Create an FR3 robot in MuJoCo.

Parameters:
  • robot_name (str, optional) – Base name of the robot model in MuJoCo.

  • **kwargs (Any) – Additional keyword arguments passed to robot_mujoco, including optional joint, actuator, flange, TCP, and sensor names.

class robotblockset.mujoco.robots_mujoco.lwr(robot_name: str = 'LWR', **kwargs: Any)[source]

Bases: robot_mujoco, lwr_spec

MuJoCo robot wrapper for the KUKA LWR manipulator.

Create an LWR robot in MuJoCo.

__init__(robot_name: str = 'LWR', **kwargs: Any) None[source]

Create an LWR robot in MuJoCo.

class robotblockset.mujoco.robots_mujoco.iiwa(robot_name: str = 'iiwa14', **kwargs: Any)[source]

Bases: robot_mujoco, iiwa_spec

MuJoCo robot wrapper for the KUKA iiwa manipulator.

Create a KUKA iiwa robot in MuJoCo.

__init__(robot_name: str = 'iiwa14', **kwargs: Any) None[source]

Create a KUKA iiwa robot in MuJoCo.

class robotblockset.mujoco.robots_mujoco.ur10(robot_name: str = 'ur10', **kwargs: Any)[source]

Bases: robot_mujoco, ur10_spec

MuJoCo robot wrapper for the Universal Robots UR10 manipulator.

Create a UR10 robot in MuJoCo.

__init__(robot_name: str = 'ur10', **kwargs: Any) None[source]

Create a UR10 robot in MuJoCo.

class robotblockset.mujoco.robots_mujoco.ur10e(robot_name: str = 'ur10e', **kwargs: Any)[source]

Bases: robot_mujoco, ur10e_spec

MuJoCo robot wrapper for the Universal Robots UR10e manipulator.

Create a UR10e robot in MuJoCo.

__init__(robot_name: str = 'ur10e', **kwargs: Any) None[source]

Create a UR10e robot in MuJoCo.

class robotblockset.mujoco.robots_mujoco.ur5(robot_name: str = 'ur5', **kwargs: Any)[source]

Bases: robot_mujoco, ur5_spec

MuJoCo robot wrapper for the Universal Robots UR5 manipulator.

Create a UR5 robot in MuJoCo.

__init__(robot_name: str = 'ur5', **kwargs: Any) None[source]

Create a UR5 robot in MuJoCo.

class robotblockset.mujoco.robots_mujoco.ur5e(robot_name: str = 'ur5e', **kwargs: Any)[source]

Bases: robot_mujoco, ur5e_spec

MuJoCo robot wrapper for the Universal Robots UR5e manipulator.

Create a UR5e robot in MuJoCo.

__init__(robot_name: str = 'ur5e', **kwargs: Any) None[source]

Create a UR5e robot in MuJoCo.

class robotblockset.mujoco.robots_mujoco.crx20(robot_name: str = 'CRX20', **kwargs: Any)[source]

Bases: robot_mujoco, crx20_spec

MuJoCo robot wrapper for the FANUC CRX-20 collaborative manipulator.

Create a CRX20 robot in MuJoCo.

__init__(robot_name: str = 'CRX20', **kwargs: Any) None[source]

Create a CRX20 robot in MuJoCo.

class robotblockset.mujoco.robots_mujoco.hc20(robot_name: str = 'hc20', **kwargs: Any)[source]

Bases: robot_mujoco, hc20_spec

MuJoCo robot wrapper for the Yaskawa HC20 manipulator.

Create an HC20 robot in MuJoCo.

__init__(robot_name: str = 'hc20', **kwargs: Any) None[source]

Create an HC20 robot in MuJoCo.

class robotblockset.mujoco.robots_mujoco.hc30(robot_name: str = 'hc30', **kwargs: Any)[source]

Bases: robot_mujoco, hc30_spec

MuJoCo robot wrapper for the Yaskawa HC30 manipulator.

Create an HC30 robot in MuJoCo.

__init__(robot_name: str = 'hc30', **kwargs: Any) None[source]

Create an HC30 robot in MuJoCo.

class robotblockset.mujoco.robots_mujoco.z1(robot_name: str = 'z1', **kwargs: Any)[source]

Bases: robot_mujoco, z1_spec

MuJoCo robot wrapper for the Unitree Z1 arm.

Create a Z1 robot in MuJoCo.

__init__(robot_name: str = 'z1', **kwargs: Any) None[source]

Create a Z1 robot in MuJoCo.

class robotblockset.mujoco.robots_mujoco.b2(robot_name: str = 'b2', **kwargs: Any)[source]

Bases: robot_mujoco, b2_spec

MuJoCo robot wrapper for the Unitree B2 platform-arm system.

Create a B2 robot in MuJoCo.

__init__(robot_name: str = 'b2', **kwargs: Any) None[source]

Create a B2 robot in MuJoCo.

Classes

b2([robot_name])

MuJoCo robot wrapper for the Unitree B2 platform-arm system.

crx20([robot_name])

MuJoCo robot wrapper for the FANUC CRX-20 collaborative manipulator.

fr3([robot_name])

MuJoCo robot wrapper for the Franka Research 3 manipulator.

hc20([robot_name])

MuJoCo robot wrapper for the Yaskawa HC20 manipulator.

hc30([robot_name])

MuJoCo robot wrapper for the Yaskawa HC30 manipulator.

iiwa([robot_name])

MuJoCo robot wrapper for the KUKA iiwa manipulator.

lwr([robot_name])

MuJoCo robot wrapper for the KUKA LWR manipulator.

panda([robot_name])

MuJoCo robot wrapper for the Franka Panda manipulator.

robot_mujoco(robot_name[, scene, host, port])

MuJoCo-backed robot interface using the socket-based server API.

ur10([robot_name])

MuJoCo robot wrapper for the Universal Robots UR10 manipulator.

ur10e([robot_name])

MuJoCo robot wrapper for the Universal Robots UR10e manipulator.

ur5([robot_name])

MuJoCo robot wrapper for the Universal Robots UR5 manipulator.

ur5e([robot_name])

MuJoCo robot wrapper for the Universal Robots UR5e manipulator.

z1([robot_name])

MuJoCo robot wrapper for the Unitree Z1 arm.