pcg_gazebo.generators

pcg_gazebo.generators

The tools in this modules allow the generation of models and worlds using policy rules for object placement and constraints.

AssetsManager

AssetsManager(self)
Assets manager containing all valid Gazebo models and model group generators. This collection should be initialized as a singleton object in order to have a single source of model to all instances of engines, model and world generators. The asset types allowed to be added are:

  • pcg_gazebo.simulation.SimulationModel: Description for a model
  • pcg_gazebo.simulation.Light: Description for light sources
  • pcg_gazebo.simulation.ModelGroup: Group of models and light sources
  • pcg_gazebo.generators.ModelGroupGenerator: Dynamic model group generator
  • dict: Input configuration of the creators factory methods for box, sphere, cylinder and mesh models, for an instance of pcg_gazebo.simulation.Light, or an instance of pcg_gazebo.generators.ModelGroupGenerator
  • str: Name of an existing Gazebo model that can be found in the Gazebo resources path
ground_planes

list: List of strings with tags of ground plane models

tags

list: List of strings with all asset tags

get_instance

AssetsManager.get_instance()
Return singleton instance of the AssetsMananger

is_model

AssetsManager.is_model(tag)
Return if asset identified by tag is an instance of pcg_gazebo.simulation.SimulationModel.

Input arguments

  • tag (type: str): Tag of the asset.
is_light

AssetsManager.is_light(tag)
Return if asset identified by tag is an instance of pcg_gazebo.simulation.Light.

Input arguments

  • tag (type: str): Tag of the asset.
is_model_group

AssetsManager.is_model_group(tag)
Return if asset identified by tag is an instance of pcg_gazebo.simulation.ModelGroup.

Input arguments

  • tag (type: str): Tag of the asset.
is_gazebo_model

AssetsManager.is_gazebo_model(tag)
Return if asset identified by tag is a Gazebo model found in Gazebo's resources path.

Input arguments

  • tag (type: str): Tag of the asset.
is_model_group_generator

AssetsManager.is_model_group_generator(tag)
Return if asset identified by tag is an instance of pcg_gazebo.generators.ModelGroupGenerator.

Input arguments

  • tag (type: str): Tag of the asset.
is_ground_plane

AssetsManager.is_ground_plane(tag)
Return if asset identified by tag is flagged as a ground plane model.

Input arguments

  • tag (type: str): Tag of the asset.
is_factory_input

AssetsManager.is_factory_input(tag)
Return if asset identified by tag is a dict containing the inputs for a pcg_gazebo.generators.creators factory method to create a box, sphere, cylinder or mesh model.

Input arguments

  • tag (type: str): Tag of the asset.
add

AssetsManager.add(description,
                  tag=None,
                  type=None,
                  parameters=None,
                  include_dir=None,
                  overwrite=True)
Add new asset to the collection.

Input arguments

  • description (type: str, dict, pcg_gazebo.simulation.SimulationModel, pcg_gazebo.simulation.Light, pcg_gazebo.simulation.ModelGroup or pcg_gazebo.generators.ModelGroupGenerator): Model description.
  • tag (type: str, default: None): Asset's tag. If None is provided, the input description must have an attribute name which will be used as a tag, otherwise the function returns False.
  • type (type: str, default: None): When the provided description is dict, the type of asset that must be generated with the dict input must be then provided as either factory, model_generator or light.

Returns

True, if asset could be added to the collection.

get

AssetsManager.get(tag, *args, **kwargs)
Return an asset reference by tag.

Input arguments

  • tag (type: str): Tag of the asset. In case tag is referencing a pcg_gazebo.generators.ModelGroupGenerator, additional inputs to run the engines can be provided using *args and **kwargs.

Returns

pcg_gazebo.simulation.SimulationModel or pcg_gazebo.simulation.ModelGroup. None, if tag is invalid.

set_asset_as_ground_plane

AssetsManager.set_asset_as_ground_plane(tag)
Flag a model asset as part of the ground plane. This procedure will affect the collision checks during the automatic placement of models in the world using the placement engines.

Input arguments

  • tag (type: str): Name of the model asset
from_dict

AssetsManager.from_dict(config)
Read assets from an input dict. The dictionary should have a list of asset descriptions under the tag assets and, if necessary, a list of strings referring to models that must be flagged as ground plane under the tag ground_plane.

Input arguments

  • config (type: data_type, default: data): Parameter description

Returns

Description of return values

from_yaml

AssetsManager.from_yaml(filename)
Load the assets from a YAML file.

Input arguments

  • filename (type: str): YAML filename.
has_element

AssetsManager.has_element(tag)
Return True if an element for tag exists.

Input arguments

  • tag (type: str): Tag of the element.

CollisionChecker

CollisionChecker(self, ignore_ground_plane=True)
Mesh-based collision checker manager. The meshes can be added to the collision check scene and used to check any other object for collisions.

Input arguments

  • ignore_ground_plane (type: bool, value: True): Ignores the meshes flagged as ground plane when performing collision checks.
scene

trimesh.scene.Scene: Collision check scenario

reset_scenario

CollisionChecker.reset_scenario()
Remove all meshes from collision check scene.

reset_to_fixed_model_scenario

CollisionChecker.reset_to_fixed_model_scenario()
Remove all meshes that were not generated by a fixed-pose engine.

add_fixed_model

CollisionChecker.add_fixed_model(model)
Add a model as a fixed-pose model to the scene.

Input arguments

  • model (type: pcg_gazebo.simulation.SimulationModel): Simulation model structure
add_model

CollisionChecker.add_model(model)
Add model to collision checking scene.

Input arguments

  • model (type: pcg_gazebo.simulation.SimulationModel): Simulation model structure
show

CollisionChecker.show()
Display the current collision check scenario using pyglet.

check_collision_with_current_scene

CollisionChecker.check_collision_with_current_scene(
    model, min_distance=0.0)
Check if there are any collisions between model and the meshes in the scene.

Input arguments

  • model (type: pcg_gazebo.simulation.SimulationModel): Simulation model structure

Returns

True, if any collision is detected. False, otherwise.

check_for_collisions

CollisionChecker.check_for_collisions()
Check if there are any collisions amongst the meshes in the scene.

Returns

True, if any collision is detected. False, otherwise.

ConstraintsManager

ConstraintsManager(self)
add

ConstraintsManager.add(name, type=None, constraint_obj=None, **kwargs)
Add a new positioning constraint class to the internal constraints list.

Input arguments

  • name (type: str): ID name for the constraint class instance
  • type (type: str): Name of the constraints class to be created
  • kwargs (type: dict): Input arguments for the constraint class to be created

EngineManager

EngineManager(self)
add

EngineManager.add(tag,
                  engine_name=None,
                  models=None,
                  engine_obj=None,
                  **kwargs)
Add a new model creator engine to the internal engines list.

Input arguments

  • engine_name (type: str): Name of the engine class to be created
  • models (type: list of str): Name of the models that will be assets to the created engine
  • kwargs (type: dict): Input arguments to the created engine.
from_yaml

EngineManager.from_yaml(filename)
Load the engines from a YAML file.

Input arguments

  • filename (type: str): YAML filename.

ModelGroupGenerator

ModelGroupGenerator(self, name='generator', **kwargs)

SingletonCollisionChecker

SingletonCollisionChecker(self, ignore_ground_plane=True)
Singleton collision checker that can be have one instance accessed by multiple clients. It facilitates sharing the collision managar amongst many engines, for example.

Attributes

  • INSTANCE (type: SingletonCollisionChecker, value: None): Instance of the singleton collision checker that is initialized by the first call of get_instance().

Input arguments

  • ignore_ground_plane (type: bool, value: True): Ignores the meshes flagged as ground plane when performing collision checks.
get_instance

SingletonCollisionChecker.get_instance(**kwargs)
Return a singleton instance of the collision checker.

Input arguments

  • kwargs (type: dict): Input arguments for the SingletonCollisionChecker instance.

Returns

A SingletonCollisionChecker instance

WorldGenerator

WorldGenerator(self,
               name='default',
               gazebo_proxy=None,
               output_world_dir=None,
               output_model_dir='/tmp/gazebo_models',
               **kwargs)
Generation of full Gazebo worlds, including physics engine configuration, modes and lights.

Input arguments

  • gazebo_proxy (type: pcg_gazebo.task_manager.GazeboProxy, default: None): A GazeboProxy object to enable spawning of models and configuration of the simulation in runtime.
gazebo_proxy

pcg_gazebo.task_manager.GazeboProxy: Internal instance of the GazeboProxy

world

pcg_gazebo.simulation.World: World abstraction instance

init_gazebo_proxy

WorldGenerator.init_gazebo_proxy(ros_host='localhost',
                                 ros_port=11311,
                                 gazebo_host='localhost',
                                 gazebo_port=11345,
                                 timeout=30,
                                 ignore_services=None)
Initialize a GazeboProxy instance to interface with a running instance of Gazebo. If a GazeboProxy already exists, it will be deleted before a new one is created.

Input arguments

  • ros_host (type: str, default: localhost): Address of the ROS host machine running roscore.
  • ros_port (type: int, default: 11311): Port number for roscore
  • gazebo_host (type: str, default: localhost): Address of the Gazebo server
  • gazebo_port (type: int, default: 11345): Port number of the Gazebo server
delete_model

WorldGenerator.delete_model(model_name)
Delete a model from the currently running Gazebo instance

Input arguments

  • model_name (type: str): Name of the model

Returns

True if the model could be deleted from the simulation.

from_dict

WorldGenerator.from_dict(config)
Parse a configuration settings dict with all information on the list of model assets, engines, constraints and lights and instantiate the necessary objects.

An example of a YAML file that can hold this kind of information can be seen below:

name: world_name
assets:
- model_1       # This list holds only Gazebo models
- model_2
- model_3
ground_plane:   # Optional input
- model_1       # If model_1 is part of the ground_plane,
                # it should be flagged for collision checking
constraints:
- name: kitchen                     # Name identifier
    type: workspace                 # Name of the constraint class
    frame: world
    geometry:
    type: area
    description:
        points:
        - [-6.54833, -4.17127, 0]
        - [-3.24447, -4.17127, 0]
        - [-3.24447, 0.12423, 0]
        - [-6.54833, 0.12423, 0]
- name: tangent_to_ground_plane     # Name identifier
    type: tangent                   # Name of the constraint class
    frame: world
    reference:
    type: plane
    args:
        origin: [0, 0, 0]
        normal: [0, 0, 1]
engines:
- engine_name: fixed_pose
  models:
  - sll_room_empty
  poses:
  - [0, 0, 0, 0, 0, 0]
- engine_name: random_pose
  models:
  - sll_table_group_futura_seat
  - sll_table_group_futura
  model_picker: size
  max_area: 0.9
  no_collision: false
  max_num:
    sll_table_group_futura_seat: 6
    sll_table_group_futura: 1
  policies:
    - models:
        - sll_table_group_futura_seat
        - sll_table_group_futura
        config:
        - dofs:
        - x
        - y
        policy:
            name: workspace
            args: dining_room
        - dofs:
        - z
        - roll
        - pitch
        policy:
            name: value
            args: 0
        - dofs:
        - yaw
        policy:
            name: uniform
            args:
            mean: 0
            min: -3.141592653589793
            max: 3.141592653589793
  constraints:
    - model: sll_table_group_futura
        constraint: tangent_to_ground_plane
    - model: sll_table_group_futura_seat
        constraint: tangent_to_ground_plane
lights:
- name: sun     # Name of the Gazebo model with the light data

Input arguments

  • config (type: dict): Configuration settings for the world generator

Returns

Description of return values

spawn_model

WorldGenerator.spawn_model(model,
                           robot_namespace,
                           pos=[0, 0, 0],
                           rot=[0, 0, 0],
                           reference_frame='world',
                           timeout=30,
                           replace=False)
Spawn a pcg_gazebo.simulation.SimulationModel in a running instance of Gazebo. A GazeboProxy is required for this method to finish successfully.

Input arguments

  • model (type: pcg_gazebo.simulation.SimulationModel): Simulation model to be spawned
  • robot_namespace (type: str): Name under which the robot should be spawned in Gazebo
  • pos (type: list, default: [0, 0, 0]): Spawning position wrt reference frame
  • rot (type: list, default: [0, 0, 0]): Roll-Pitch-Yaw angles in radians or a (w, i, j, k) quaternion vector.
  • reference_frame (type: str, default: world): Reference frame for the spawning pose
  • timeout (type: float): Timeout in seconds to wait for Gazebo to start
  • replace (type: bool, default: False): Replace the model in the simulation in case a model with the same name already exists.

Returns

True if the model could be spawned.

get_physics_engine

WorldGenerator.get_physics_engine(engine='ode')
Return an instance of a physics engine as pcg_gazebo.simulation.physics.Physics object.

Input arguments

  • engine (type: str): ID name of the physics engine, options are ode, bullet and simbody.

Returns

An pcg_gazebo.simulation.physics.Physics object.

reset_world

WorldGenerator.reset_world(name, engine='ode', gravity=[0, 0, -9.8])
Reset the generated world instance to its default state and without any models.

Input arguments

  • name (type: str): Name of the world
  • engine (type: str, default: ode): Name of the physics engine to be used. Options are ode, bullet or simbody.
  • gravity (type: list, default: [0, 0, -9.8]): Gravitational acceleration vector
export_world

WorldGenerator.export_world(output_dir=None,
                            filename=None,
                            with_default_ground_plane=True,
                            with_default_sun=True,
                            models_output_dir=None,
                            overwrite=True,
                            sdf_version='1.6')
Export world to an SDF file that can be used by Gazebo.

Input arguments

  • output_dir (type: str, default: None): Path to output directory to store the world file.
  • filename (type: str, default: None): Name of the SDF world file
  • with_default_ground_plane (type: bool, default: True): Add the default ground plane model to the world before exporting it
  • with_default_sun (type: bool, default: True): Add the default sun model to the world before exporting it

Returns

Full name of the exported SDF world file as a str

plot_results

WorldGenerator.plot_results(fig=None,
                            fig_width=1000,
                            fig_height=800,
                            footprint_geometry='collision',
                            engine='bokeh')
Plot the footprints of models included in the current world instance.

Input arguments

  • fig (type: a bokeh or a matplotlib figure, default: None): A figure object. If fig is None, a new figure will be created
  • fig_width (type: int, default: 1000): Width of the figure
  • param (type: data_type, default: data): Parameter description

Returns

Description of return values