pcg_gazebo.simulation
pcg_gazebo.simulation¶
Simulation interface module, with abstraction classes for all relevant entities that form a simulation in Gazebo.
create_object¶
create_object(tag, **kwargs)
Link
subclasses.
Input arguments
tag
(type:str
): Name identifier of the object classkwargs
(type:dict
): Input arguments for the object class
Returns
Link
: Subclass instance.
get_gazebo_model_folders¶
get_gazebo_model_folders(dir_path)
dir_path
.
Input arguments
dir_path
(type:str
): Path to the search directory.
Returns
dict
: Gazebo model paths ordered according to the
Gazebo model names.
load_gazebo_models¶
load_gazebo_models()
.gazebo/models
folder
and in the ROS paths.
Returns
dict
: Information of all Gazebo models found
get_gazebo_models¶
get_gazebo_models()
.gazebo/models
folder and in the catkin workspace as
a dictionary.
get_gazebo_model_names¶
get_gazebo_model_names()
.gazebo/models
folders and catkin workspace.
get_gazebo_model_ros_pkg¶
get_gazebo_model_ros_pkg(name)
is_gazebo_model¶
is_gazebo_model(name)
name
is a Gazebo
model that is found in the resources path.
Input arguments
name
(type:str
): Name identifier of the model
Returns
True
if name
refers to a Gazebo model.
get_gazebo_model_path¶
get_gazebo_model_path(model_name)
Input arguments
model_name
(type:str
): Name of the Gazebo model
Returns
str
: Path of the Gazebo model folder
get_gazebo_model_sdf¶
get_gazebo_model_sdf(model_name, sdf_file='model.sdf')
pcg_gazebo
SDF instance.
Input arguments
model_name
(type:str
): Name of the Gazebo model.sdf_file
(type:str
, default:model.sdf
): Name of the SDF file to be parsed.
Returns
pcg_gazebo.parsers.types.XMLBase
instance as an SDF element.
Box¶
Box()
pcg_gazebo.simulation.Link
to
describe a box-shaped link or single-link model.
Input arguments
name
(type:str
, default:box
): Name of the objectsize
(type:list
, default:[1, 1, 1]
): Vector with width, length and height of the box,
collision¶
pcg_gazebo.simulation.properties.Collision
:
Return single box-shaped collision model.
size¶
List of float
: Size of the box as [width, length, height]
visual¶
pcg_gazebo.simulation.properties.Visual
:
Return single box-shaped visual model.
to_sdf¶
Box.to_sdf(type='model', name='box', sdf_version='1.6')
type
input
box
: SDF box elementgeometry
: SDF geometry element with nested elementcollision
: SDF collision elementvisual
: SDF visual elementlink
: SDF link element with collision and visual propertiesmodel
: single-link SDF model elementsdf
: SDF file format with a nested model element.
Input arguments
type
(type:str
): Type of output SDF element, options arecollision
,visual
,link
,model
,sdf
.name
(type:str
, default:model
): Name of the output objectsdf_version
(type:str
, default:1.6
): Version of the output SDF element
Returns
pcg_gazebo.parsers.types.XMLBase
: SDF element instance.
add_inertial¶
Box.add_inertial(mass)
Input arguments
mass
(type:float
): Mass in kilograms
update_inertial¶
Box.update_inertial(mass=None)
Input arguments
mass
(type:float
): Mass in kilograms
update_collision¶
Box.update_collision()
size
.
update_visual¶
Box.update_visual()
size
.
Cylinder¶
Cylinder()
pcg_gazebo.simulation.Link
to
describe a cylinder-shaped link or single-link model.
Input arguments
name
(type:str
, default:cylinder
): Name of the object.length
(type:float
, default:1
): Length of the cylinder in meters.radius
(type:float
, default:1
): Radius of the cylinder in meters.
collision¶
pcg_gazebo.simulation.properties.Collision
:
Return single cylinder-shaped collision model.
length¶
float
: Length of the cylinder in meters
radius¶
float
: Radius of the cylinder in meters
visual¶
pcg_gazebo.simulation.properties.Visual
:
Return single cylinder-shaped visual model.
to_sdf¶
Cylinder.to_sdf(type='model', name='cylinder', sdf_version='1.6')
type
input
cylinder
: SDF cylinder elementgeometry
: SDF geometry element with nested elementcollision
: SDF collision elementvisual
: SDF visual elementlink
: SDF link element with collision and visual propertiesmodel
: single-link SDF model elementsdf
: SDF file format with a nested model element.
Input arguments
type
(type:str
): Type of output SDF element, options arecollision
,visual
,link
,model
,sdf
.name
(type:str
, default:model
): Name of the output objectsdf_version
(type:str
, default:1.6
): Version of the output SDF element
Returns
pcg_gazebo.parsers.types.XMLBase
: SDF element instance.
update_inertial¶
Cylinder.update_inertial(mass=None)
Input arguments
mass
(type:float
): Mass in kilograms
update_collision¶
Cylinder.update_collision()
length
and radius
.
update_visual¶
Cylinder.update_visual()
length
and radius
.
Joint¶
Joint()
Light¶
Light()
SimulationModel¶
SimulationModel()
Link¶
Link()
link
or a single-link model
.
Input arguments
name
(type:str
, value:object
): Name of the object.creation_time
(type:float
, default:None
): Timestamp of the creation of the object in Gazebo.life_timeout
(type:float
, default:None
): Timeout in which to remove the object from the simulation (not implemented).
collisions¶
List of pcg_gazebo.simulation.properties.Collision
:
List of collision models
creation_time¶
float
: Time of creation of this object, if
it represents a single-link model.
inertial¶
pcg_gazebo.simulation.properties.Inertial
:
Description of the object's moments of inertia.
kinematic¶
bool
: Flag to indicate if the model is purely kinematic
life_timeout¶
float
: Life timeout timestamp for this object,
if it represents a single-link model
name¶
str
: Object name
pose¶
pcg_gazebo.simulation.properties.Pose
: Pose of the object
self_collide¶
bool
: Self-collision flag
static¶
bool
: Flag to indicate if object is static
visuals¶
List of pcg_gazebo.simulation.properties.Visual
:
List of visual models
create_link_from_mesh¶
Factory method to build a link or single-link model from a mesh. This method allows not only assigning a mesh as a visual and collision geometry, but also using geometrical approximations of the input mesh to create, for example, a collision mesh, or computing the moments of inertia.
Input arguments
name
(type:str
, default:link
): Name of the link.visual_mesh_filename
(type:str
, default:None
): Filename to the visual mesh file.collision_mesh_filename
(type:str
, default:None
): Filename to the collision mesh file. If the input isNone
anduse_approximated_collision
isFalse
, the visual mesh will be also set as collision mesh.use_approximated_collision
(type:bool
, default:False
): IfTrue
, the collision geometry will be approximated from the visual mesh geometry into a model given by theapproximated_collision_model
input.approximated_collision_model
(type:str
, default:box
): Name of the geometry to which the visual geometry will be approximated to generated the collision mesh, options arebox
,cylinder
orsphere
.visual_mesh_scale
(type:list
, default:[1, 1, 1]
): Scaling factors for the visual mesh in X, Y and Z directions.collision_mesh_scale
(type:list
, default:[1, 1, 1]
): Scaling factors for the collision mesh in X, Y and Z directions.pose
(type:list
, default:[0, 0, 0, 0, 0, 0]
): Link's pose with respect to the model frame.color
(type:list
orstr
, default:None
): Color set to the visual mesh. IfNone
is provided, no color is set and the mesh will inherit the material of the mesh file. If the input israndom
, a random RGB color is generated. This input can also be set asxkcd
for a randomxkcd
color name, or a string with the name of a specificxkcd
color (e.g.,teal
). Otherwise, the input can be an RGB vector as alist
.mass
(type:float
, default:0
): Mass of the link in kilograms. If the mass is not greater than zero, the link will be set as static.inertia
(type:dict
, default:None
): Moments of inertia of the link. This input can be either a dictionary defined asdict(ixx=0, iyy=0, izz=0, ixy=0, ixz=0, iyz=0)
orNone
. IfNone
is provided,use_approximated_inertia
isTrue
andmass
is greater than zero, the moments of inertia will be computed from an approximated visual mesh geometry given by the inputapproximated_inertia_model
.use_approximated_inertia
(type:bool
, default:True
): IfTrue
andmass
is greater tha zero, the moments of inertia of the link will be computed from a approximated visual mesh model described byapproximated_inertia_model
.approximated_inertia_model
(type:str
, default:box
): Type of geometry approximation to be applied to the visual geometry. The dimensions of the geometry will then be used to compute the moments of inertia. Options arebox
,cylinder
orsphere
.
Returns
pcg_gazebo.simulation.Link
instance.
enable_collision¶
Link.enable_collision()
disable_collision¶
Link.disable_collision()
enable_visual¶
Link.enable_visual()
disable_visual¶
Link.disable_visual()
get_collision_by_name¶
Link.get_collision_by_name(name)
Input arguments
name
(type:str
): Name of the collision model.
Returns
pcg_gazebo.simulation.properties.Collision
, or None
if not collision with the given name is found.
has_collision¶
Link.has_collision(name)
Input arguments
name
(type:str
): Name of the collision model
Returns
bool
: True
, if a collision model exists, `False, otherwise.
get_visual_by_name¶
Link.get_visual_by_name(name)
Input arguments
name
(type:str
): Name of the visual model.
Returns
pcg_gazebo.simulation.properties.Visual
, or None
if not visual with the given name is found.
has_visual¶
Link.has_visual(name)
Input arguments
name
(type:str
): Name of the visual model
Returns
bool
: True
, if a visual model exists, `False, otherwise.
add_empty_visual¶
Link.add_empty_visual(name='visual')
Input arguments
name
(type:str
, default:visual
): Name of the visual model.
Returns
bool
: True
if visual model could be created and added to the object.
False
if another visual with the same name already exists.
add_visual¶
Link.add_visual(visual)
_i
, i
being an integer.
Input arguments
visual
(type:pcg_gazebo.simulation.properties.Visual
): Visual element
Returns
bool
: True
, if visual element could be added to object.
add_empty_collision¶
Link.add_empty_collision(name='collision')
Input arguments
name
(type:str
, default:collision
): Name of the collision model.
Returns
bool
: True
if collision model could be created and added to the object.
False
if another collision with the same name already exists.
add_collision¶
Link.add_collision(collision)
_i
, i
being an integer.
Input arguments
collision
(type:pcg_gazebo.simulation.properties.Collision
): Collision element
Returns
bool
: True
, if collision element could be added to object.
to_sdf¶
Link.to_sdf(type='link', name='model', sdf_version='1.6')
type
input
collision
: SDF collision elementvisual
: SDF visual elementlink
: SDF link element with collision and visual propertiesmodel
: single-link SDF model elementsdf
: SDF file format with a nested model element.
Input arguments
type
(type:str
): Type of output SDF element, options arecollision
,visual
,link
,model
,sdf
.name
(type:str
, default:model
): Name of the output objectsdf_version
(type:str
, default:1.6
): Version of the output SDF element
Returns
pcg_gazebo.parsers.types.XMLBase
: SDF element instance.
from_sdf¶
Factory method to generate a pcg_gazebo.simulation.Link
instance
from an SDF instance. Only links can be parsed.
Input arguments
sdf
(type:pcg_gazebo.parsers.sdf.Link
): SDF object
Returns
pcg_gazebo.simulation.Link
: Simulation object instance
export_to_gazebo_model¶
Link.export_to_gazebo_model(output_dir, name='model', sdf_version='1.6', version='0.1.0', author_names=None, author_emails=None, description='', generate_sdf_with_version=False)
model_dir/ model.sdf model.config
Input arguments
output_dir
(type:str
): Name of the directory where the model directory will be stored.name
(type:str
, default:model
): Name of the modelsdf_version
(type:str
, default:1.6
): Version of the SDF formatversion
(type:str
, default:0.1.0
): Gazebo model versionauthor_names
(type:list
, default:None
): List of authorsauthor_emails
(type:list
, default:None
): List of e-mailsdescription
(type:str
): Model descriptiongenerate_sdf_with_version
(type:bool
, default:False
): Parameter description
Returns
bool
: True
, if Gazebo model files were exported successfully.
add_inertial¶
Link.add_inertial(mass)
update_inertial¶
Link.update_inertial()
update_collision¶
Link.update_collision()
update_visual¶
Link.update_visual()
add_sensor¶
Link.add_sensor(name, sensor)
Input arguments
name
(type:str
): Name of the sensorsensor
(type:pcg_gazebo.simulation.sensors.Sensor
): Sensor description
Returns
bool
: True
, if sensor could be added to link.
to_markers¶
Link.to_markers()
visualization_msgs/Marker
instances from the visual and/or
collision entities.
Returns
visualization_msgs/MarkerArray
get_footprint¶
Link.get_footprint(mesh_type='collision', pose_offset=None, use_bounding_box=False, z_limits=None)
shapely._GEOMETRIES.Polygon
or shapely._GEOMETRIES.MultiPolygon
that represent the projection of the visual or collision meshes on the XY
plane.
Input arguments
mesh_type
(type:str
, default:collision
): Origin of the meshes, options arevisual
orcollision
.pose_offset
(type:data_type
, default:None
): Pose offset to be applied to all meshes before the footprint is computeduse_bounding_box
(type:bool
, default:False
): Use the mesh's bounding box for the footprint calculationz_limits
(type:list
, default:None
): Minimum and maximum limits in the Z direction were the meshes will be sectioned.
Returns
shapely._GEOMETRIES.Polygon
or shapely._GEOMETRIES.MultiPolygon
get_meshes¶
Link.get_meshes(mesh_type='collision', pose_offset=None)
Input arguments
mesh_type
(type:str
, default:collision
): Type of mesh to be returned, options arevisual
orcollision
.pose_offset
(type:list
, default:None
): Pose offset to be applied to all meshes.
Returns
List of trimesh
meshes.
get_bounds¶
Link.get_bounds(mesh_type='collision')
Input arguments
mesh_type
(type:str
, default:collision
): Type of mesh, options arevisual
orcollision
.
Returns
dict
: Meshes' bounds
Plane¶
Plane()
Polyline¶
Polyline()
Sphere¶
Sphere()
pcg_gazebo.simulation.Link
to
describe a sphere-shaped link or single-link model.
Input arguments
name
(type:str
, default:sphere
): Name of the objectradius
(type:float
, default:1
): Radius of the sphere in meters
collision¶
pcg_gazebo.simulation.properties.Collision
:
Return single sphere-shaped collision model.
radius¶
float
: Radius of the sphere in meters
visual¶
pcg_gazebo.simulation.properties.Visual
:
Return single sphere-shaped visual model.
to_sdf¶
Sphere.to_sdf(type='model', name='sphere', sdf_version='1.6')
type
input
sphere
: SDF sphere elementgeometry
: SDF geometry element with nested elementcollision
: SDF collision elementvisual
: SDF visual elementlink
: SDF link element with collision and visual propertiesmodel
: single-link SDF model elementsdf
: SDF file format with a nested model element.
Input arguments
type
(type:str
): Type of output SDF element, options arecollision
,visual
,link
,model
,sdf
.name
(type:str
, default:model
): Name of the output objectsdf_version
(type:str
, default:1.6
): Version of the output SDF element
Returns
pcg_gazebo.parsers.types.XMLBase
: SDF element instance.
add_inertial¶
Sphere.add_inertial(mass, hollow=False)
Input arguments
mass
(type:float
): Mass in kilogramshollow
(type:bool
, default:False
): Compute moments of inertia for a hollow sphere, instead of a solid one
update_inertial¶
Sphere.update_inertial(mass=None)
Input arguments
mass
(type:float
): Mass in kilograms
update_collision¶
Sphere.update_collision()
radius
.
update_visual¶
Sphere.update_visual()
radius
.
World¶
World()
- physics engine
- models
- lights
- plugins
- gravity
and can be later exported into a .world
file that Gazebo
can parse and execute.
Input arguments
name
(type:str
, value:default
): Name of the world.gravity
(type:list
, default:[0, 0, -9.8]
): Acceleration of gravity vector.engine
(type:str
, default:ode
): Name of the default physics engine, options areode
,bullet
orsimbody
.
engine¶
str
: Name identififier of the physics engine
gravity¶
list
: Acceleration of gravity vector
lights¶
dict
: Lights
model_groups¶
dict
: Model groups
models¶
dict
: Models
name¶
str
: Name of the world
physics¶
pcg_gazebo.simulation.physics.Physics
: Physics engine instance
reset_physics¶
World.reset_physics(engine='ode', *args, **kwargs)
Input arguments
engine
(type:str
, default:ode
): Name identifier of the physics engine, options areode
,bullet
orsimbody
.
reset_models¶
World.reset_models()
add_include¶
World.add_include(include, group='default')
Input arguments
include
(type:pcg_gazebo.parsers.sdf.Include
): SDF<include>
element
Returns
bool
: True
, if model directed by the include
element
could be parsed and added to the world.
add_model¶
World.add_model(tag, model, group='default')
Input arguments
tag
(type:str
): Model's local name in the world. If a model with the same name already exists, the model will be created with a counter suffix in the format_i
,i
being an integer.model
(type:pcg_gazebo.simulation.SimulationModel
): Model object
Returns
bool
: True
, if model could be added to the world.
rm_model¶
World.rm_model(tag, group='default')
Input arguments
tag
(type:str
): Local name identifier of the model to be removed.
Returns
bool
: True
, if model could be removed, False
if
no model with name tag
could be found in the world.
model_exists¶
World.model_exists(tag, group=None)
tag
exists in the world description.
Input arguments
tag
(type:str
): Local name identifier of the model.
Returns
bool
: True
, if model exists, False
, otherwise.
add_plugin¶
World.add_plugin(tag, plugin)
Input arguments
tag
(type:str
): Name identifier for the plugin. If a model with the same name already exists, the model will be created with a counter suffix in the format_i
,i
being an integer.plugin
(type:pcg_gazebo.parsers.sdf.Plugin
orpcg_gazebo.simulation.properties.Plugin
): Plugin description.
rm_plugin¶
World.rm_plugin(tag)
Input arguments
tag
(type:str
): Local name identifier of the plugin to be removed.
Returns
bool
: True
, if plugin could be removed, False
if
no plugin with name tag
could be found in the world.
plugin_exists¶
World.plugin_exists(tag)
tag
exists in the world description.
Input arguments
tag
(type:str
): Local name identifier of the plugin.
Returns
bool
: True
, if plugin exists, False
, otherwise.
add_light¶
World.add_light(tag, light, group='default')
Input arguments
tag
(type:str
): Name identifier for the plugin. If a model with the same name already exists, the model will be created with a counter suffix in the format_i
,i
being an integer.light
(type:pcg_gazebo.parsers.sdf.Light
orpcg_gazebo.simulation.properties.Light
): Light description
rm_light¶
World.rm_light(tag, group='default')
Input arguments
tag
(type:str
): Local name identifier of the light to be removed.
Returns
bool
: True
, if light could be removed, False
if
no light with name tag
could be found in the world.
light_exists¶
World.light_exists(tag, group='default')
tag
exists in the world description.
Input arguments
tag
(type:str
): Local name identifier of the light.
Returns
bool
: True
, if light exists, False
, otherwise.
to_sdf¶
World.to_sdf(type='world', with_default_ground_plane=True, with_default_sun=True)
pcg_gazebo
SDF
element.
Input arguments
type
(type:str
, default:world
): Type of output SDF element to be generated, options areworld
orsdf
. It is important to note that to export the world description into a file, it is necessary to have thesdf
format.with_default_ground_plane
(type:bool
, default:True
): Add Gazebo's default ground plane model to the world.with_default_sun
(type:bool
, default:True
): Add Gazebo's default sun model to the world.
Returns
pcg_gazebo.parsers.sdf.SDF
with a world element in it or
pcg_gazebo.parsers.sdf.World
.
from_sdf¶
Parse an pcg_gazebo.parsers.sdf.World
into a
World
class.
Input arguments
sdf
(type:pcg_gazebo.parsers.sdf.World
): SDF world element
Returns
pcg_gazebo.parsers.sdf.World
instance.
create_scene¶
World.create_scene(mesh_type='collision', add_pseudo_color=True)
trimesh.Scene
with all the world's models.
Input arguments
mesh_type
(type:str
, default:collision
): Type of mesh to be included in the scene, options arecollision
orvisual
.add_pseudo_color
(type:bool
, default:True
): IfTrue
, set each mesh with a pseudo-color.
plot_footprints¶
World.plot_footprints(fig=None, ax=None, fig_width=20, fig_height=20, mesh_type='collision', z_limits=None, colormap='magma', grid=True, ignore_ground_plane=True, line_width=1, line_style='solid', alpha=0.5, engine='matplotlib', dpi=200)
Input arguments
fig
(type:matplotlib.pyplot.Figure
orbokeh.plotting.Figure
, default:None
): Figure object. IfNone
is provided, the figure will be created.ax
(type:matplotlib.pyplot.Axes
, default:None
): Axes object to add the plot. IfNone
is provided, the axes object will be created.fig_width
(type:float
orint
, default:20
): Width of the figure in inches, ifengine
ismatplotlib
, or pixels, ifengine
isbokeh
.fig_height
(type:float
orint
, default:20
): Height of the figure in inches, ifengine
ismatplotlib
, or pixels, ifengine
isbokeh
.mesh_type
(type:str
, default:collision
): Type of mesh to consider for the footprint computation, options arecollision
andvisual
.z_limits
(type:list
, default:None
): List of minimum and maximum Z-levels to consider when sectioning the meshes.colormap
(type:str
, default:magma
): Name of the colormap to be used. Check this link formatplotlib
colormaps and this link forbokeh
colormaps.grid
(type:bool
, default:True
): IfTrue
, add grid to the plot.ignore_ground_plane
(type:bool
, default:True
): Ignore the models flagged as ground plane from the plot.line_width
(type:float
, default:1
): Width of the line of each footprint polygon patch.line_style
(type:str
, default:solid
): Style of the line of each footprint polygon patch. Check this link to see all the line style options.alpha
(type:float
, default:0.5
): Alpha channel value for the footprint objects.engine
(type:str
, default:matplotlib
): Engine to use for the generation of the figure, options arebokeh
andmatplotlib
.dpi
(type:int
, default:200
): Image's DPI
Returns
matplotlib.pyplot.Figure
or bokeh.plotting.Figure
.