World¶
A world encompasses the reality the robot experiment takes place, this includes simulations like PyBullet, as well as The Simulation We Inhabit known as reality. Worlds contain RobotInterfaces, ObjectInterfaces, Arenas and SensorInterfaces. They do not include experimental concepts such as tasks and reward functions.
World¶
-
class
perls2.worlds.world.
World
(cfg_path)¶ Abstract base class for Worlds.
A World encompasses all necessary components for managing an experiment in simulation or reality. Worlds generate the appropriate robot, sensor and object interfaces based on the configuration file.
-
config
¶ Config files contain parameters to create an arena, robot interface, sensor interface and object interface. They also contain specs for learning, simulation and experiment setup.
- Type
dict
-
arena
¶ Manages the sim by loading models for real and sim and for simulations, randomizing objects and sensors parameters
- Type
Arena
-
robot_interface
¶ Communicates with robots and executes robot commands.
- Type
-
sensor_interface
¶ Retrieves sensor info and executes changes to params
- Type
SensorInterface
-
is_sim
¶ Flag that is true if world is simulation.
- Type
bool
-
abstract
reset
()¶ Reset the world to initial state.
- Returns
The observation.
-
abstract
step
(start=None)¶ Step simulation forward.
-
BulletWorld¶
-
class
perls2.worlds.bullet_world.
BulletWorld
(config, use_visualizer=False, name=None)¶ Class for PyBullet worlds.
A BulletWorld will automatically create instances of BulletRobot, BulletCamera and BulletObjectInterfaces based on the config file.
-
arena
¶ Manages the sim by loading models, and for simulations, randomizing objects and sensors params.
- Type
BulletArena
-
robot_interface
¶ Communicates with robots and executes robot commands.
- Type
-
camera_interface
¶ Retrieves camera images and executes changes to params (e.g. intrinsics/extrinsics)
- Type
BulletCameraInterface
-
object_interfaces
¶ A dictionary of perls2.BulletObjectInterfaces currently in the simulation. Keys are string unique identifying names for the object.
- Type
dict
-
physics_id
¶ Unique id identifying physics client for Pybullet. Used to connect other interfaces when working with multiple simulations.
- Type
int
-
time_step
¶ float Float defining timestep to increment Pybullet simulation during pybullet.stepSimulation() calls. Set in config file
-
MAX_STEPS
¶ int Constant for maximum number of steps before terminating epsiode. Set in config file
-
name
¶ str A name to describe the world (e.g. training or testing)
-
add_object
(path, name, pose, scale=1.0, is_static=False)¶ Add object to world explicitly.
- Parameters
path (str) – filepath name to object urdf
name (str) – name of object used for dictionary key
pose (list) – ((3,),(4,)) pose of the object as [[x, y, z], [qx, qy, qz, w]] orientation as quaternion.
scale (double) – scale of object.
is_static (bool) – whether object should remain fixed or not.
- Returns
object interface added to world.
- Return type
object_interface (ObjectInterface)
Examples
objI = self.add_object(‘objects/ycb/013_apple/google_16k/textured.urdf’, ‘013_apple’, [0, 0, 0, 0, 0, 0, 1], 1.0,)
-
reboot
()¶ Reboot pybullet simulation by clearing all objects, urdfs and resetting sim state.
Warning: this is a slow process and should only be used for restoring state and deterministic applications.
-
reconnect
()¶ Disconnects and reconnects to new physics engine
-
remove_object
(name)¶ Remove object from world. :param name: name of the object as stored in objects dictionary. :type name: str
Notes: Removes object from arena as well as objects dictionary.
-
reset
()¶ Reset the world.
- Returns
None
TODO: Should this return something? an error? This needs to be defined by derived class. But all derived reset functions share these steps.
-
set_pb_physics
()¶ Set physics parameters for pybullet simulation.
-
set_state
(filepath)¶ Set simulation to .bullet path found in filepath
- Parameters
filepath (str) – filepath of .bullet file for saved state.
- Returns
None
Examples
env.world.set_state(‘/path/to/state.bullet’)
Notes
To use this function correctly, the same objects / robots must be loaded in the same order. Therefore it is only recommended to use with the same world / config, rather than trying to load an empty world.
-
step
(start=None)¶ Step the world(simulation) forward.
- Parameters
start (float) – timestamp for when env.step was called by policy. Ignored for this class.
- Returns
None
Step simulation forward a number of times per action to ensure smoothness when for collisions
-
visualize
(observation, action)¶ Visualize the action.
Add visual markers to the world (in case of sim) or execute some movements (in case of real) to indicate the action about to be performed.
- Parameters
observation – The observation of the current step.
action – The selected action.
-
visualize_safenet_boundaries
()¶ Add visualization to pb sim for safenet boundary.
-
wait_until_stable
(linear_velocity_threshold=0.005, angular_velocity_threshold=0.005, check_after_steps=100, min_stable_steps=100, max_steps=30000)¶ Wait until the objects are stable.
Blocking code that checks if object linear and angular velocity are within respectives thresholds of 0.
- Parameters
linear_velocity_threshold (float) –
angular_velocity_threshold (float) –
check_after_steps (int) – min number of steps to wait before checking object state
min_stable_step (int) – min number of steps for object to be stable before exiting
max_steps (int) – max number of steps to wait for stable object
- Returns
None
- TODO
add check for angular velocity threshold
-
RealWorld¶
-
class
perls2.worlds.real_world.
RealWorld
(config=None, use_visualizer=False, name='DefaultEnv')¶ Typically, an env will have one robot with one camera as well as logic to have the robot execute a particular task.
-
reset
()¶ Reset the environment.
- Returns
The observation.
-
step
(start=None)¶ Take a step.
- Parameters
start (float) – time.time() timestamp taken from before policy computes action. This is to enforce policy frequency.
Returns: None
Takes a step forward, since this happens naturally in reality, we don’t do anything.
-