pyCub

The main class and utils for pyCub simulator

Author:

Lukas Rustler

class icub_pybullet.pycub.EndEffector(name: str, client: int)[source]

Bases: object

Help function for end-effector encapsulaation

Parameters:
  • name (str) – name of the end-effector

  • client (pointer to pyCub instance) – parent client

get_position() Pose[source]

Function to get current position of the end-effector

class icub_pybullet.pycub.Joint(name: str, robot_joint_id: int, joints_id: int, lower_limit: float, upper_limit: float, max_force: float, max_velocity: float)[source]

Bases: object

Help class to encapsulate joint information

Parameters:
  • name (str) – name of the joint

  • robot_joint_id (int) – id of the joint in pybullet

  • joints_id (int) – id of the joint in pycub.joints

  • lower_limit (float) – lower limit of the joint

  • upper_limit (float) – upper limit of the joint

  • max_force (float) – max force of the joint

  • max_velocity (float) – max velocity of the joint

Bases: object

Help function to encapsulate link information

Parameters:
  • name (str) – name of the link

  • robot_link_id (int) – id of the link in pybullet

  • urdf_link (int) – id of the link in pycub.urdfs[“robot”].links

class icub_pybullet.pycub.pyCub(config: str | None = 'default.yaml')[source]

Bases: BulletClient

Client class which inherits from BulletClient and contains the whole simulation functionality

Parameters:

config (str, optional, default="default.yaml") – path to the config file

static bbox_overlap(b1_min: list, b1_max: list, b2_min: list, b2_max: list) bool[source]

Function to check whether two bounding boxes overlap

Parameters:
  • b1_min (list) – min bbox 1

  • b1_max (list) – max bbox 1

  • b2_min (list) – min bbox 2

  • b2_max (list) – max bbox 2

Returns:

whether the boxes overlap

Return type:

bool

compute_jacobian(chain: Literal['left_arm', 'right_arm', 'left_leg', 'right_leg', 'torso', 'head'], start: str | None = None, end: str | None = None) Tuple[array, array][source]

Help function to compute a Jacobian using RTB of a given chain with optional start and end

Parameters:
  • chain (str) – name of the chain

  • start (str) – name of the start link

  • end (str) – name of the end link

Returns:

Jacobian and list of joints used

Return type:

np.array, np.array

compute_skin() None[source]

Function to emulate skin activations using ray casting.

contactPoints = {'DISTANCE': 8, 'FLAG': 0, 'FORCE': 9, 'FRICTION1': 10, 'FRICTION2': 12, 'FRICTIONDIR1': 11, 'FRICTIONDIR2': 13, 'IDA': 1, 'IDB': 2, 'INDEXA': 3, 'INDEXB': 4, 'NORMAL': 7, 'POSITIONA': 5, 'POSITIONB': 6}
create_urdf(object_path: str, fixed: bool, color: List[float], suffix: str | None = '')[source]

Creates a URDF for the given .obj file

Parameters:
  • object_path (str) – path to the .obj

  • fixed (bool) – whether the object is fixed in space

  • color (list of 3 floats) – color of the object

  • suffix (str, optional, default="") – suffix to add to the object name

dynamicsInfo = {'BODYTYPE': 10, 'DAMPING': 8, 'FRICTION': 1, 'INERTIAOR': 4, 'INERTIAPOS': 3, 'INTERTIADIAGONAL': 2, 'MARGIN': 11, 'MASS': 0, 'RESTITUTION': 5, 'ROLLINGFRICTION': 6, 'SPINNINGFRICTION': 7, 'STIFFNESS': 9}
find_joint_id(joint_name: JOINTS | JOINTS_IDS) Tuple[int, int][source]

Help function to get indexes from joint name of joint index in self.joints list

Parameters:

joint_name (str or int) – name or index of the link

Returns:

joint id in pybullet and pycub space

Return type:

int, int

Help function to find link id from mesh name

Parameters:
  • mesh_name (str) – name of the mesh (only basename with extension)

  • robot (int, optional, default=None) – robot pybullet id

  • urdf_name (str, optional, default="robot") – name of the object in pycub.urdfs

Returns:

id of the link in pybullet space

Return type:

int

find_processes_by_name() List[int][source]

Help function to find PIDs of processes with the parent name

Returns:

list of matching PIDs

Return type:

list of ints

get_camera_depthimages(eyes: str | List[str] | None = None) dict[source]

Gets the images from enabled eye cameras

Parameters:

eyes (str or list of str, optional) – name of eye/eyes to get images for

Returns:

dictionary with eye as keys and np.array of images as values

Return type:

dict

get_cameraimages(eyes: str | List[str] | None = None) dict[source]

Gets the images from enabled eye cameras

Parameters:

eyes (str or list of str, optional) – name of eye/eyes to get images for

Returns:

dictionary with eye as keys and np.array of images as values

Return type:

dict

static get_chains() Tuple[dict, dict][source]

Function to get chains (and corresponding chains of joints) of the robot

Returns:

chains of links and chains of joints

Return type:

dict, dict

get_joint_state(joints: JOINTS | List[JOINTS] | JOINTS_IDS | List[JOINTS_IDS] | None = None, allow_error: bool | None = False) List[list][source]

Get the state of the specified joints

Parameters:
  • joints (int or list, optional, default=None) – joint or list of joints to get the state of

  • allow_error (bool, optional, default=False) – whether to allow errors (non-existing joints); useful for Jacobian computation

Returns:

list of states of the joints

Return type:

list

init_robot() Tuple[int, List[Joint], List[Link]][source]

Load the robot URDF and get its joints’ information

Returns:

robot, its joints and links

Return type:

int, list of Joint, list of Link

init_urdfs() None[source]

Function to load URDFs of other objects

Returns:

Return type:

is_alive() bool[source]

Checks whether the engine is still running

Returns:

True when running

Return type:

bool

jointInfo = {'AXIS': 13, 'DAMPING': 6, 'FLAGS': 5, 'FRICTION': 7, 'INDEX': 0, 'LINKNAME': 12, 'LOWERLIMIT': 8, 'MAXFORCE': 10, 'MAXVELOCITY': 11, 'NAME': 1, 'PARENTINDEX': 16, 'PARENTORN': 15, 'PARENTPOS': 14, 'QINDEX': 3, 'TYPE': 2, 'UINDEX': 4, 'UPPERLIMIT': 9}
jointStates = {'FORCES': 2, 'POSITION': 0, 'TORQUE': 3, 'VELOCITY': 1}
kill_open3d() None[source]

A bit of a workaround to kill open3d, that seems to hang for some reason.

Returns:

Return type:

linkInfo = {'ANGVEL': 7, 'INERTIAORI': 3, 'INERTIAPOS': 2, 'LINVEL': 6, 'URDFORI': 5, 'URDFPOS': 4, 'WORLDORI': 1, 'WORLDPOS': 0}
motion_done(joints: JOINTS | List[JOINTS] | JOINTS_IDS | List[JOINTS_IDS] | None = None, check_collision=True) bool[source]

Checks whether the motion is done.

Parameters:
  • joints (int or list, optional, default=None) – joint or list of joints to get the state of

  • check_collision (bool, optional, default=True) – whether to check for collision during motion

Returns:

True when motion is done, false otherwise

Return type:

bool

move_cartesian(pose: Pose, wait: bool | None = True, velocity: float | None = 1, check_collision: bool | None = True, timeout: float | None = None) None[source]

Move the robot in cartesian space by computing inverse kinematics and running position control

Parameters:
  • pose (utils.Pose) – desired pose of the end effector

  • wait (bool, optional, default=True) – whether to wait for movement completion

  • velocity (float, optional, default=1) – joint velocity to move with

  • check_collision (bool, optional, default=True) – whether to check for collisions during motion

  • timeout (float, optional, default=10) – timeout for the motion

move_position(joints: JOINTS | List[JOINTS] | JOINTS_IDS | List[JOINTS_IDS], positions: float | List[float], wait: bool | None = True, velocity: float | None = 1, set_col_state: bool | None = True, check_collision: bool | None = True, timeout: float | None = None) None[source]

Move the specified joints to the given positions

Parameters:
  • joints (int, str, list of int, list of str) – joint or list of joints to move

  • positions (float or list; same length as joints) – position or list of positions to move the joints to

  • wait (bool, optional, default=True) – whether to wait until the motion is done

  • velocity (float, optional, default=1) – velocity to move the joints with

  • set_col_state (bool, optional, default=True) – whether to reset collision state

  • check_collision (bool, optional, default=True) – whether to check for collision during motion

  • timeout (float, optional, default=10) – timeout for the motion

move_velocity(joints: JOINTS | List[JOINTS] | JOINTS_IDS | List[JOINTS_IDS], velocities: float | List[float]) None[source]

Move the specified joints with the specified velocity

Parameters:
  • joints (int or list) – joint or list of joints to move

  • velocities (float or list; same length as joints) – velocity or list of velocities to move the joints to

prepare_log() str[source]

Prepares the log string

Returns:

log string

Return type:

str

print_collision_info(c: list | None = None)[source]

Help function to print collision info

Parameters:

c (list, optional, default=None) – one collision; if None print all collisions

run_vhacd(robot: bool | None = True) None[source]

Function to run VHACD on all objects in loaded URDFs, and to create new URDFs with changed collision meshes

Parameters:

robot (bool, optional, default=True) – whether to run VHACD on the robot

static scale_bbox(bbox: list, scale: float) Tuple[array, array][source]

Function to scale the bounding box

Parameters:
  • bbox (list) – list of min and max bbox

  • scale (float) – scale factor

Returns:

new min and max bbox

Return type:

list, list

stop_robot(joints: JOINTS | List[JOINTS] | JOINTS_IDS | List[JOINTS_IDS] | None = None) None[source]

Stops the robot

toggle_gravity() None[source]

Toggles the gravity

update_simulation(sleep_duration: float | None | None = -1) None[source]

Updates the simulation

Parameters:

sleep_duration (float or None, optional, default=-1) – duration to sleep before the next simulation step

visualShapeData = {'COLOR': 7, 'DIMS': 3, 'FILE': 4, 'GEOMTYPE': 2, 'ID': 0, 'LINK': 1, 'ORI': 6, 'POS': 5, 'TEXTURE': 8}
wait_motion_done(sleep_duration: float | None = 0.01, check_collision: bool | None = True) None[source]

Help function to wait for motion to be done. Can sleep for a specific duration

Parameters:
  • sleep_duration (float, optional, default=0.01) – how long to sleep before running simulation step

  • check_collision (bool, optional, default=True) – whether to check for collisions during motion