hbp_nrp_cle.robotsim.GazeboHelper module

Helper class for gazebo loading operations

class GazeboHelper[source]

Bases: object

This class provides some useful Gazebo macros by wrapping ROS services.

empty_gazebo_world()[source]

Clean up the ROS connected running instance. Remove all models and all lights.

load_gazebo_model_file(model_name, model_file, initial_pose=None, retina_config_path=None)[source]

Load a sdf model file into the ROS connected running gazebo instance.

Parameters
  • model_name – Name of the model (can be anything)

  • model_file – The absolute path of the model sdf file inside the NRP_MODELS_PATH folders. :param initial_pose: Initial pose of the model. Uses the Gazebo “Pose” type.

  • retina_config_path – Configuration script for the Retina Camera Plugin

load_gazebo_world(models_sdf_dict, lights_sdf_dict)[source]

Load a SDF world into the ROS connected gazebo running instance. The world is described by the models_sdf_dict and lights_sdf_dict dictionaries.

Parameters
  • models_sdf_dict – A dictionary containing pairs (model_name: {‘model_sdf’: sdf, ‘model_state_sdf’: sdf})

  • lights_sdf_dict – A dictionary containing pairs (light_name: light_sdf)

load_gazebo_world_file(world_file)[source]

Load an SDF world file into the ROS connected gazebo running instance.

Parameters

world_file – The absolute path of the SDF world file.

Return A pair of dictionaries

1st containing pairs (model_name: {‘model_sdf’: sdf, ‘model_state_sdf’: sdf}), 2nd second pairs (light_name: light_sdf)

load_sdf_entity(model_name, model_sdf, initial_pose=None)[source]

Load a gazebo model (sdf) into the ROS connected running gazebo instance.

Parameters
  • model_name – Name of the model (can be anything).

  • model_sdf – The SDF xml code describing the model.

  • initial_pose – Initial pose of the model. Uses the Gazebo “Pose” type.

load_textures(textures)[source]

Loads the user textures in the simulation

Parameters

textures – A list of dict describing textures

static make_model_state_msg(model_name=None, pose=None, scale=None, twist=None, reference_frame=None)[source]

ModelState messages factory

static parse_gazebo_world_file(world_file)[source]

Parse an SDF world file.

Parameters

world_file – The absolute path of the SDF world file.

Return A pair of dictionaries

1st containing pairs (model_name: {‘model_sdf’: sdf, ‘model_state_sdf’: sdf}), 2nd second pairs (light_name: light_sdf)

static parse_model_state_sdf(model_state_sdf)[source]

Create a ModelState message using a model state sdf element

Parameters

model_state_sdf – A string serialization of a model state sdf element

Returns

A ModelState message

static parse_world_string(world_string)[source]

Parse an SDF world string producing a pair of dictionaries:

  • (model_name: (model_sdf, model_state_sdf))

  • (light_name: light_sdf)

Parameters

world_string – A string containing the SDF world.

Returns

A pair of dictionaries:

  1. pairs (model_name: {‘model_sdf’: sdf, ‘model_staet_sdf’: sdf},

  2. pairs (light_name: light_sdf)

set_model_pose(model_name, pose)[source]

Sets the pose of a given model to a given pose.

Parameters
  • model_name – The model to reposition.

  • pose – The new pose of the model, if None, it will be set to origin w/o rotation.

set_model_state(model_state_sdf)[source]

Set a model state described by the model state sdf element string

Parameters

model_state_sdf – A string serialization of the model state sdf element describing the model state to be set

static try_remove_pose(model)[source]

Remove pose from the model object if it exists

Param

A model object

wait_for_backend_rendering()[source]

Wait for the backend rendering environment to be ready. Blocks until all world models and lights are loaded in the rendering scene (only if needed, if there are no sensors or cameras then a scene will not exist and this will not block).

This is necessary for sensors (e.g. cameras) that depend on the rendering environment to be immediately usable. The simulation will otherwise run, but the cameras and sensors will not publish data until they are fully loaded.