airobot.arm.single_arm_pybullet

class airobot.arm.single_arm_pybullet.SingleArmPybullet(cfgs, pb_client, seed=None, self_collision=False, eetool_cfg=None)[source]

Bases: airobot.arm.arm.ARM

Base class for a single arm simulated in pybullet.

Parameters:
  • cfgs (YACS CfgNode) – configurations for the arm.
  • pb_client (BulletClient) – pybullet client.
  • seed (int) – random seed.
  • self_collision (bool) – enable self_collision or not whiling loading URDF.
  • eetool_cfg (dict) – arguments to pass in the constructor of the end effector tool class.
Variables:
  • cfgs (YACS CfgNode) – configurations for the arm.
  • robot_id (int) – pybullet body unique id of the robot.
  • arm_jnt_names (list) – names of the arm joints.
  • arm_dof (int) – degrees of freedom of the arm.
  • arm_jnt_ids (list) – pybullet joint ids of the arm joints.
  • arm_jnt_ik_ids (list) – joint indices of the non-fixed arm joints.
  • ee_link_jnt (str) – joint name of the end-effector link.
  • ee_link_id (int) – joint id of the end-effector link.
  • jnt_to_id (dict) – dictionary with [joint name : pybullet joint] id [key : value] pairs.
  • non_fixed_jnt_names (list) – names of non-fixed joints in the arms, used for returning the correct inverse kinematics solution.
compute_ik(pos, ori=None, ns=False, *args, **kwargs)[source]

Compute the inverse kinematics solution given the position and orientation of the end effector.

Parameters:
  • pos (list or np.ndarray) – position (shape: \([3,]\)).
  • ori (list or np.ndarray) – orientation. It can be euler angles ([roll, pitch, yaw], shape: \([3,]\)), or quaternion ([qx, qy, qz, qw], shape: \([4,]\)), or rotation matrix (shape: \([3, 3]\)).
  • ns (bool) – whether to use the nullspace options in pybullet, True if nullspace should be used. Defaults to False.
Returns:

list – solution to inverse kinematics, joint angles which achieve the specified EE pose (shape: \([DOF]\)).

disable_torque_control(joint_name=None)[source]

Disable the torque control mode in Pybullet.

Parameters:joint_name (str) – If it’s none, then all the six joints on the UR robot are disabled with torque control. Otherwise, only the specified joint is disabled with torque control. The joint(s) will enter velocity control mode.
enable_torque_control(joint_name=None)[source]

Enable the torque control mode in Pybullet.

Parameters:joint_name (str) – If it’s none, then all the six joints on the UR robot are enabled in torque control mode. Otherwise, only the specified joint is enabled in torque control mode.
get_ee_pose()[source]

Return the end effector pose.

Returns:4-element tuple containing
  • np.ndarray: x, y, z position of the EE (shape: \([3,]\)).
  • np.ndarray: quaternion representation of the EE orientation (shape: \([4,]\)).
  • np.ndarray: rotation matrix representation of the EE orientation (shape: \([3, 3]\)).
  • np.ndarray: euler angle representation of the EE orientation (roll, pitch, yaw with static reference frame) (shape: \([3,]\)).
get_ee_vel()[source]

Return the end effector’s velocity.

Returns:2-element tuple containing
  • np.ndarray: translational velocity (shape: \([3,]\)).
  • np.ndarray: rotational velocity (shape: \([3,]\)).
get_jpos(joint_name=None)[source]

Return the joint position(s) of the arm.

Parameters:joint_name (str, optional) – If it’s None, it will return joint positions of all the actuated joints. Otherwise, it will return the joint position of the specified joint.
Returns:One of the following
  • float: joint position given joint_name.
  • list: joint positions if joint_name is None (shape: \([DOF]\)).
get_jtorq(joint_name=None)[source]

If the robot is operated in VELOCITY_CONTROL or POSITION_CONTROL mode, return the joint torque(s) applied during the last simulation step. In TORQUE_CONTROL, the applied joint motor torque is exactly what you provide, so there is no need to report it separately. So don’t use this method to get the joint torque values when the robot is in TORQUE_CONTROL mode.

Parameters:joint_name (str, optional) – If it’s None, it will return joint torques of all the actuated joints. Otherwise, it will return the joint torque of the specified joint.
Returns:One of the following
  • float: joint torque given joint_name
  • list: joint torques if joint_name is None (shape: \([DOF]\)).
get_jvel(joint_name=None)[source]

Return the joint velocity(ies) of the arm.

Parameters:joint_name (str, optional) – If it’s None, it will return joint velocities of all the actuated joints. Otherwise, it will return the joint velocity of the specified joint.
Returns:One of the following
  • float: joint velocity given joint_name.
  • list: joint velocities if joint_name is None (shape: \([DOF]\)).
go_home(ignore_physics=False)[source]

Move the robot to a pre-defined home pose

move_ee_xyz(delta_xyz, eef_step=0.005, *args, **kwargs)[source]

Move the end-effector in a straight line without changing the orientation.

Parameters:
  • delta_xyz (list or np.ndarray) – movement in x, y, z directions (shape: \([3,]\)).
  • eef_step (float) – interpolation interval along delta_xyz. Interpolate a point every eef_step distance between the two end points.
Returns:

bool – A boolean variable representing if the action is successful at the moment when the function exits.

reset()[source]

Reset the simulation environment.

reset_joint_state(jnt_name, jpos, jvel=0)[source]

Reset the state of the joint. It’s best only to do this at the start, while not running the simulation. It will overrides all physics simulation.

Parameters:
  • jnt_name (str) – joint name.
  • jpos (float) – target joint position.
  • jvel (float) – optional, target joint velocity.
rot_ee_xyz(angle, axis='x', N=50, *args, **kwargs)[source]

Rotate the end-effector about one of the end-effector axes, without changing the position

Parameters:
  • angle (float) – Angle by which to rotate in radians.
  • axis (str) – Which end-effector frame axis to rotate about. Must be in [‘x’, ‘y’, ‘z’].
  • N (int) – Number of waypoints along the rotation trajectory (larger N means motion will be more smooth but potentially slower).
Returns:

bool – A boolean variable representing if the action is successful at the moment when the function exits.

set_ee_pose(pos=None, ori=None, wait=True, ignore_physics=False, *args, **kwargs)[source]

Move the end effector to the specifed pose.

Parameters:
  • pos (list or np.ndarray) – Desired x, y, z positions in the robot’s base frame to move to (shape: \([3,]\)).
  • ori (list or np.ndarray, optional) – It can be euler angles ([roll, pitch, yaw], shape: \([4,]\)), or quaternion ([qx, qy, qz, qw], shape: \([4,]\)), or rotation matrix (shape: \([3, 3]\)). If it’s None, the solver will use the current end effector orientation as the target orientation.
  • wait (bool) – whether to block the code and wait for the action to complete.
  • ignore_physics (bool) – hard reset the joints to the target joint positions. It’s best only to do this at the start, while not running the simulation. It will overrides all physics simulation.
Returns:

bool – A boolean variable representing if the action is successful at the moment when the function exits.

set_jpos(position, joint_name=None, wait=True, ignore_physics=False, *args, **kwargs)[source]

Move the arm to the specified joint position(s).

Parameters:
  • position (float or list) – desired joint position(s).
  • joint_name (str) – If not provided, position should be a list and all the actuated joints will be moved to the specified positions. If provided, only the specified joint will be moved to the desired joint position.
  • wait (bool) – whether to block the code and wait for the action to complete.
  • ignore_physics (bool) – hard reset the joints to the target joint positions. It’s best only to do this at the start, while not running the simulation. It will overrides all physics simulation.
Returns:

bool – A boolean variable representing if the action is successful at the moment when the function exits.

set_jtorq(torque, joint_name=None, wait=False, *args, **kwargs)[source]

Apply torque(s) to the joint(s), call enable_torque_control() or enable_torque_control(joint_name) before doing torque control.

Note

call to this function is only effective in this simulation step. you need to supply torque value for each simulation step to do the torque control. It’s easier to use torque control in step_simulation mode instead of realtime_simulation mode. If you are using realtime_simulation mode, the time interval between two set_jtorq() calls must be small enough (like 0.0002s)

Parameters:
  • torque (float or list) – torque value(s) for the joint(s).
  • joint_name (str) – specify the joint on which the torque is applied. If it’s not provided(None), it will apply the torques on the six joints on the arm. Otherwise, only the specified joint will be applied with the given torque.
  • wait (bool) – Not used in this method, just to keep the method signature consistent.
Returns:

bool – Always return True as the torque will be applied as specified in Pybullet.

set_jvel(velocity, joint_name=None, wait=False, *args, **kwargs)[source]

Move the arm with the specified joint velocity(ies).

Parameters:
  • velocity (float or list) – desired joint velocity(ies).
  • joint_name (str) – If not provided, velocity should be a list and all the actuated joints will be moved in the specified velocities. If provided, only the specified joint will be moved in the desired joint velocity.
  • wait (bool) – whether to block the code and wait for the action to complete.
Returns:

bool – A boolean variable representing if the action is successful at the moment when the function exits.