pyrcf.components.robot_interfaces.simulation
Provides simulation interfaces for robot extending and respecting the RobotInterface class. These can be used in the control loop without needing a real robot.
Submodules
Classes
A RobotInterface implementation for a generic robot in pybullet. |
Package Contents
- class pyrcf.components.robot_interfaces.simulation.PybulletRobot(urdf_path: str, ee_names: List[str] = None, place_on_ground: bool = True, default_base_position: numpy.ndarray = np.zeros(3), default_base_orientation: numpy.ndarray = np.array([0, 0, 0, 1]), default_joint_positions: numpy.ndarray = None, create_pinocchio_interface: bool = True, floating_base: bool = True, verbose: bool = True, **sim_interface_kwargs)
Bases:
pyrcf.components.robot_interfaces.simulation.sim_robot_base.SimulatedRobotInterfaceA RobotInterface implementation for a generic robot in pybullet.
All subclasses of this method will use synchronous sim time stepping, i.e. the simulated world will step only when the read() method of this class is called. This is to keep the clock synchronous and for providing full repeatable performance to the control loop by minimising parallelisation.
- DEFAULT_URDF_PATH: str = None
Default urdf path to be used for particular instances of PybulletRobot. This variable should be overridden in the implemented child classes.
- class BulletWorldClock(dt: float)
Bases:
pyrcf.utils.time_utils.ClockBaseOnly valid if sim stepping is done synchronously and managed by the PybulletRobot class.
- _current_t = 0.0
- _dt
- step_time()
To be called each time simulation steps forward.
- get_time() float
Get the latest time from this clock.
- Raises:
NotImplementedError – Raised if this method is not implemented by the child class.
- Returns:
the current time in seconds.
- Return type:
float
- _sim_robot
- _clock
- read() pyrcf.core.types.RobotState
Get the latest state from the robot.
- Raises:
NotImplementedError – Raised if this method is not implemented by the child class.
- Returns:
the latest state of the robot.
- Return type:
- write(cmd: pyrcf.core.types.RobotCmd) bool
Send the specified commands to the robot.
- Parameters:
cmd (RobotCmd) – the command object as computed by the controller in the loop.
- Raises:
NotImplementedError – Raised if this method is not implemented by the child class.
- Returns:
True if sending command was succesful.
- Return type:
bool
- set_base_pose(position: numpy.ndarray, orientation: pyrcf.core.types.QuatType)
Set the pose of the base of the simulated robot in the world frame.
- Parameters:
position (np.ndarray) – Desired position for the base frame in the world.
orientation (QuatType) – Desired orientation quaternion [x,y,z,w] for base frame in the world.
- Raises:
NotImplementedError – Raised if this method is not implemented by the child class.
- get_sim_clock() pyrcf.utils.time_utils.ClockBase
Get the Clock object that gives the time in this simulated world.
- Raises:
NotImplementedError – Raised if this method is not implemented by the child class.
- Returns:
- The Clock object that can be used to get the current time using its
get_time() method.
- Return type:
- shutdown()
Cleanly shutdown the PyRCF component. Override in child class if required. The base class implements an empty function.
- classmethod withJointsLocked(joints_to_lock: Mapping[str, float] = None, temp_urdf: bool = True, **kwargs)
Classmethod for RobotInterface implementation for PybulletRobot robot in pybullet, that locks the specified joints of the robot. All specified joints are converted to “fixed” joint type and cannot be reverted dynamically!
NOTE: Use this method with caution. All keyword arguments are directly passed to the default constructor!
- Parameters:
joints_to_lock (Mapping[str, float]) – Dictionary containing name of joints that should be locked as keys, and the joint values to lock them at as values. By default, uses upper body joints (from upper torso upwards) set to zeros.
temp_urdf (bool, optional) – If set to True, will create a temporary urdf that will be deleted after loading in pybullet, otherwise create a file in /tmp/ directory. Defaults to True.
**kwargs – additional keyword arguments to pass to PybulletRobot or subclass.
By default, the urdf created via this constructor is only valid during construction. The path to the urdf (accessed through self._sim_robot.urdf_path, for instance) will not be a valid path once the init is completed. This is because this method temporarily creates a urdf after modifying the specified joints to “fixed” joint type, and destroys the temporary file soon after all objects using it (pybullet, pinocchio, etc.) are created in the construction.
To disable this behaviour, set temp_urdf=False during construction. This will create a permenant urdf file in the /tmp/ directory. ——————————————————————————————-
- classmethod fromAwesomeRobotDescriptions(robot_description_name: str, ee_names: List[str] = None, place_on_ground: bool = True, default_base_position: numpy.ndarray = np.zeros(3), default_base_orientation: numpy.ndarray = np.array([0, 0, 0, 1]), default_joint_positions: numpy.ndarray = None, create_pinocchio_interface: bool = True, floating_base: bool = True, verbose: bool = True, **sim_interface_kwargs) PybulletRobot
Create a PybulletRobot instance using robots available in the open source Awesome Robot Descriptions list (https://github.com/robot-descriptions/robot_descriptions.py/tree/main?tab=readme-ov-file#descriptions).
The list of available robot descriptions can also be viewed in the variable AWESOME_ROBOTS imported from pybullet_robot.utils.urdf_utils.
Downloads description package for the specified robot and caches it locally (only needs downloading once), and loads this robot as a PybulletRobot instance. NOTE: ee_names should be provided if proper end-effector kinematics is required. Also starting pose and joint configurations are always at zero. So to set to some specific configuration provide appropriate arguments.
- Parameters:
robot_description_name (str) – The name of the robot description package name. Should be a value available in the awesome robots list (also defined in variable AVAILABLE_ROBOTS in utils.urdf_utils).
ee_names (List[str], optional) – List of end-effectors for the robot. Defaults to None.
place_on_ground (bool) – If true, the base position height will automatically be adjusted such that the robot is on the ground with the given joint positions. Defaults to True.
default_base_position (np.ndarray, optional) – Default position of the base of the robot in the world frame during start-up. Note that the height value (z) is only used if ‘place_on_ground’ is set to False. Defaults to np.zeros(3).
default_base_orientation (np.ndarray, optional) – Default orientation quaternion in the world frame for the base of the robot during start-up. Defaults to np.array([0, 0, 0, 1]).
default_joint_positions (List[float], optional) – Optional starting values for joints. Defaults to None. NOTE: These values should be in the order of joints in pybullet.
create_pinocchio_interface (bool, optional) – If true, creates a PinocchioInterface object for this robot. The object is automatically updated with latest state when read() is called. Defaults to True.
floating_base (bool, optional) – Specifying whether this robot has a floating or fixed base (setting to True creates a floating base instance with pinocchio, and makes the simulated robot free floating (not fixed base)). Defaults to True.
verbose (bool, optional) – Verbosity flag for debugging robot info during construction. Defaults to True.
- Returns:
- A PybulletRobot instance created using the URDF generated using the awesome
robot descriptions package.
- Return type: