robits.sim package

Submodules

robits.sim.blueprints module

Class that contains blueprints for the scene such as robots and objects

class robits.sim.blueprints.Attachment(gripper_path: str, wrist_name: str | None = None, attachment_offset: Pose | None = None, attachment_site: str = 'attachment_site')

Bases: object

the path of the robot blueprint that we want to attach to

attachment_offset: Pose | None = None
attachment_site: str = 'attachment_site'
gripper_path: str
wrist_name: str | None = None
class robits.sim.blueprints.Blueprint(path: str)

Bases: ABC

Simple data class to model elements in the environment

property basename: str
property parent_path: str
path: str
to_dict() Dict

Serialize this blueprint (and nested dataclasses) to a plain dict.

class robits.sim.blueprints.BlueprintGroup(path: str, pose: robits.sim.blueprints.Pose | None = None)

Bases: Blueprint

pose: Pose | None = None
class robits.sim.blueprints.CameraBlueprint(path: str, width: int, height: int, intrinsics: numpy.ndarray, pose: robits.sim.blueprints.Pose | None = None)

Bases: Blueprint

property extrinsics

world to camera coordinates

height: int
intrinsics: ndarray
pose: Pose | None = None
width: int
class robits.sim.blueprints.GeomBlueprint(path: str, geom_type: str = 'box', pose: robits.sim.blueprints.Pose | None = None, size: Sequence[float] = <factory>, rgba: Sequence[float] | None = None, is_static: bool = False, mass: float = 0.2)

Bases: Blueprint

geom_type: str = 'box'
is_static: bool = False
mass: float = 0.2
pose: Pose | None = None
rgba: Sequence[float] | None = None
size: Sequence[float]
class robits.sim.blueprints.GripperBlueprint(path: str, model: robits.sim.blueprints.RobotDescriptionModel, default_joint_positions: Sequence[float] | None = None)

Bases: Blueprint

default_joint_positions: Sequence[float] | None = None
model: RobotDescriptionModel
class robits.sim.blueprints.MeshBlueprint(path: str, mesh_path: str, pose: robits.sim.blueprints.Pose | None = None, is_static: bool = False, scale: float = 1.0)

Bases: Blueprint

is_static: bool = False
mesh_path: str
pose: Pose | None = None
scale: float = 1.0
class robits.sim.blueprints.ObjectBlueprint(path: str, model_path: str, pose: robits.sim.blueprints.Pose | None = None, is_static: bool = True, model_prefix_name: str | None = None)

Bases: Blueprint

is_static: bool = True
model_path: str
model_prefix_name: str | None = None
pose: Pose | None = None
class robits.sim.blueprints.Pose(matrix: numpy.ndarray = <factory>)

Bases: object

property euler: ndarray
matrix: ndarray
property position: ndarray
property quaternion: ndarray
property quaternion_wxyz: ndarray
to_dict() List[float]
with_euler(new_euler: Sequence[float], degrees=False)
with_position(new_position: Sequence[float])
with_quat(new_quat: Sequence[float] | ndarray)
with_quat_wxyz(new_quat: Sequence[float])
class robits.sim.blueprints.RobotBlueprint(path: str, model: robits.sim.blueprints.RobotDescriptionModel, pose: robits.sim.blueprints.Pose | None = None, attachment: robits.sim.blueprints.Attachment | None = None, default_joint_positions: Sequence[float] | None = None)

Bases: Blueprint

attachment: Attachment | None = None
default_joint_positions: Sequence[float] | None = None
model: RobotDescriptionModel
pose: Pose | None = None
class robits.sim.blueprints.RobotDescriptionModel(description_name: str, variant_name: str | None = None, model_prefix_name: str | None = None)

Bases: object

description_name: str
model_prefix_name: str | None = None
variant_name: str | None = None
robits.sim.blueprints.blueprints_from_json(json_string: str) List[Blueprint]
robits.sim.blueprints.convert_json_to_bp(data: Any) Blueprint

See also

Blueprint.to_json

robits.sim.camera module

class robits.sim.camera.MujocoCamera(camera_name, width=640, height=480, **kwargs)

Bases: CameraBase, MujocoEnvClient

Implements a camera in Mujoco

property camera_name: str

Name of the camera

Returns:

The camera name

property extrinsics

Extrinsics parameters

Returns:

the extrinsic parameters of the camera as 4x4 matrix

get_camera_data() Tuple[CameraData, Dict[str, Any]]

Gets the camera images

Returns:

the camera images and metadata

property intrinsics

Intrinsic parameters

Returns:

the intrinsic parameters of the camera as 3x3 matrix

intrinsics_from_model()

robits.sim.control module

class robits.sim.control.MujocoCartesianControl(joint_names: List[str], actuator_names: List[str], site, transform_robot_to_world: ndarray)

Bases: ControllerBase, MujocoJointControlClient

Cartesian control for Mujoco

start_controller() None

Start the controller.

stop_controller() None

Stop the controller.

update(pose: Tuple[ndarray, ndarray], relative: bool = False)

Abstract method to update the controller’s command target. Concrete subclasses must implement this.

class robits.sim.control.MujocoControlManager(joint_names, actuator_names, site, default_joint_positions, transform_robot_to_world)

Bases: ControlManager

move_home() None

Convenience function to move the robot to default joint position

stop() None

Stop the active controller.

class robits.sim.control.MujocoPositionControl(joint_names: List[str], actuator_names: List[str])

Bases: ControllerBase, MujocoJointControlClient

Position control for Mujoco

start_controller() None

Start the controller.

stop_controller() None

Stop the controller.

update(joint_positions: ndarray, relative: bool = False) None

Abstract method to update the controller’s command target. Concrete subclasses must implement this.

robits.sim.env module

class robits.sim.env.MujocoEnv

Bases: object

Mujoco environment

classmethod get() MujocoEnv

Singleton instance

get_collisions() List[Set[str]]

Object names that are in collision. Result of this function is cached, but the cache is resetted after each simulation step.

Returns:

The object that are in collisions

get_joint_to_actuator_mapping(model: MjModel) Dict[int, int]

Generates a mapping from joint id to actuator id

Parameters:

model – the mujoco model to build the mapping from

get_scene_info() Dict[str, Dict[str, Any]]

Gets the current information about objects in the scene. An object is defined as geom element, whose parent bodies have a free joint. The result of this function is cached but resetted after each simulation step

Returns:

information, such as pose, about objects in the scene

property num_free_joints: int

Returns the number of free joint in the model

render_cameras(renderer) None

Renders the camera images

Parameters:

renderer – the renderer to use

sim_control_loop() None

The actual control loop over the simulation

robits.sim.env_client module

class robits.sim.env_client.MujocoEnvClient

Bases: object

Convenience class to access data models

Also allows the lazy initialize the mujoco environment.

property data: MjData

Convenience property to access the MuJoCo simulation data.

property env: MujocoEnv

Access the current environment, which triggers a build of the environment

property model: MjModel

Convenience property to access the MuJoCo model.

property viewer

Convenience property to access the current MuJoCo viewer.

class robits.sim.env_client.MujocoJointControlClient(joint_names: List[str], actuator_names: List[str] | None = None)

Bases: MujocoEnvClient

property actuator_ids: ndarray
Returns:

the actuator ids

property ctrl_max: ndarray

Maximum control range for the actuators

property ctrl_min: ndarray

Minimum control range for the actuators

get_current_joint_positions() ndarray

Removes the free joints from the model.

Returns:

A numpy array of the current joint positions

property joint_ids: ndarray
Returns:

the joint ids

property qpos_indices: ndarray
Returns:

the qpos indicies for each actuated joints

property qvel_indices: ndarray

qvel, qacc indices for each actuated joint, using jnt_dofadr.

see https://github.com/google-deepmind/mujoco/issues/1564

robits.sim.env_design module

class robits.sim.env_design.EnvDesigner

Bases: object

Collects all the necessary requirments to build the environemnt. Kind of like an architect.

add(blueprint: Blueprint) EnvDesigner
add_blocks()

Convenience function to add three different colored blocks

add_floor()
finalize() Dict[str, Blueprint]

Finalizes the layout of the environment

Returns:

all blueprints

from_json(json_string: str)
classmethod get() EnvDesigner

Singleton instance

get_camera_names() List[str]

Returns the name of all cameras

remove(name: str) EnvDesigner

Deletes a blueprint. Does not work in the environemnt is already build

Parameters:

name – name of the blueprint to remove

to_json() str
update(blueprint: Blueprint, **changes)

robits.sim.gripper module

class robits.sim.gripper.MujocoGripper(gripper_name: str, joint_names: List[str], actuator_names: List[str] | None = None, invert: bool = False, description_name: str = '', variant_name: str | None = None, **kwargs)

Bases: MujocoJointControlClient, GripperBase

Implements a gripper in Mujoco

close()

Closes the gripper / hand

get_info()

Returns general information about the gripper.

Returns:

Dictionary containing gripper information

get_obs() Dict[str, Any]

Gets the normalized position of the gripper / finger joints

Returns:

A dictionary with joint positions and other observations

property gripper_name

Returns the name of the gripper.

Returns:

The gripper name

is_open() bool

Returns whether the hand / gripper is open

Returns:

True if the gripper is open

open()

Opens the gripper / hand

set_pos(pos)

Set the open amount the gripper / hand

Parameters:

pos – the normalized position

robits.sim.model_factory module

class robits.sim.model_factory.SceneBuilder(add_floor: bool = True)

Bases: object

add(blueprint)
add(blueprint: MeshBlueprint)
add(blueprint: ObjectBlueprint)
add(blueprint: CameraBlueprint)
add(blueprint: BlueprintGroup)
add(blueprint: GeomBlueprint)
add(blueprint: GripperBlueprint)
add_camera(blueprint: CameraBlueprint)
add_default_assets()
add_geom(blueprint: GeomBlueprint)
add_gripper(blueprint: GripperBlueprint)
add_group(blueprint: BlueprintGroup)
add_mesh(blueprint: MeshBlueprint)
add_mocap()
add_object(blueprint: ObjectBlueprint)
add_robot(blueprint: RobotBlueprint, gripper_blueprint: GripperBlueprint | None = None)
attach_gripper(arm_model: Element, attachment_blueprint: Attachment, gripper_blueprint: GripperBlueprint) MjModel
build_from_blueprints(blueprints: Sequence[Blueprint]) MjModel

Creates a mujoco model from blueprints

export_with_assets(out_path: Path) None
get_parent(blueprint: Blueprint) Element
get_top_level_parent(blueprint: Blueprint) Element

Returns the top parent element below the worldbod

merge_all_keyframes_into_home()

robits.sim.robot module

class robits.sim.robot.BimanualMujocoRobot(robot_name: str, right_robot, left_robot, **kwargs)

Bases: BimanualRobot, MujocoEnvClient

property control
class robits.sim.robot.MujocoRobot(robot_name: str, joint_names: List[str], default_joint_positions: List[float], transform_robot_to_world: Sequence[Sequence[float]], gripper: MujocoGripper | None, actuator_names: List[str] | None = None, cameras: List[CameraBase] | None = None, description_name: str = '', variant_name: str | None = None, side_name: str | None = None, **kwargs)

Bases: MujocoJointControlClient, UnimanualRobot

property control
property eef_matrix

The 4x4 matrix of the current end-effector pose

Returns:

The pose of the robot as matrix

eef_matrix_by_site(site)

..todo:: rename Convenience function

property eef_pose

The pose of the end-effector as (position, quaternion). Quaternion format is xyzw

Returns:

The pose of the robot as tuple

eef_pose_by_site(site)

Convenience function

get_info()
get_proprioception_data(include_eef: bool = True, include_gripper_obs: bool = True) Dict[str, Any]

Gets the proprioception data from a robot. This includes

  • joint position

  • joint velocities

  • gripper joint position (optional)

  • gripper pose (optional)

Parameters:
  • include_eef – include pose of the end-effector

  • include_gripper_obs – include joint positions and other proprioception of the gripper

Returns:

The proprioception data

property robot_name

Returns the name of the robot.

Returns:

The robot name

property site

Heuristic to search for a site

robits.sim.utils module