ros_gazebo_gym.core.gazebo_connection

Contains a small python utility class that makes it easier to interact with the Gazebo simulator.

Module Contents

Classes

GazeboConnection

Class that contains several methods that can be used to interact with the Gazebo

Attributes

GAZEBO_PAUSE_PHYSICS_TOPIC

GAZEBO_UNPAUSE_PHYSICS_TOPIC

GAZEBO_RESET_SIM_TOPIC

GAZEBO_RESET_WORLD_TOPIC

GAZEBO_CLOCK_TOPIC

GAZEBO_SPAWN_SDF_MODEL_TOPIC

GAZEBO_SPAWN_URDF_MODEL_TOPIC

GAZEBO_LINK_STATES_TOPIC

GAZEBO_MODEL_STATES_TOPIC

GAZEBO_GET_MODEL_STATE_TOPIC

GAZEBO_SET_MODEL_STATE_TOPIC

GAZEBO_GET_LINK_STATE_TOPIC

GAZEBO_SET_MODEL_CONFIGURATION_TOPIC

GAZEBO_GET_PHYSICS_PROPERTIES_TOPIC

GAZEBO_SET_PHYSICS_PROPERTIES_TOPIC

PHYSICS_UPDATE_RATE

SERVICES_CONNECTION_TIMEOUTS

ros_gazebo_gym.core.gazebo_connection.GAZEBO_PAUSE_PHYSICS_TOPIC = '/gazebo/pause_physics'[source]
ros_gazebo_gym.core.gazebo_connection.GAZEBO_UNPAUSE_PHYSICS_TOPIC = '/gazebo/unpause_physics'[source]
ros_gazebo_gym.core.gazebo_connection.GAZEBO_RESET_SIM_TOPIC = '/gazebo/reset_simulation'[source]
ros_gazebo_gym.core.gazebo_connection.GAZEBO_RESET_WORLD_TOPIC = '/gazebo/reset_world'[source]
ros_gazebo_gym.core.gazebo_connection.GAZEBO_CLOCK_TOPIC = '/clock'[source]
ros_gazebo_gym.core.gazebo_connection.GAZEBO_SPAWN_SDF_MODEL_TOPIC = '/gazebo/spawn_sdf_model'[source]
ros_gazebo_gym.core.gazebo_connection.GAZEBO_SPAWN_URDF_MODEL_TOPIC = '/gazebo/spawn_urdf_model'[source]
ros_gazebo_gym.core.gazebo_connection.GAZEBO_MODEL_STATES_TOPIC = '/gazebo/model_states'[source]
ros_gazebo_gym.core.gazebo_connection.GAZEBO_GET_MODEL_STATE_TOPIC = '/gazebo/get_model_state'[source]
ros_gazebo_gym.core.gazebo_connection.GAZEBO_SET_MODEL_STATE_TOPIC = '/gazebo/set_model_state'[source]
ros_gazebo_gym.core.gazebo_connection.GAZEBO_SET_MODEL_CONFIGURATION_TOPIC = '/gazebo/set_model_configuration'[source]
ros_gazebo_gym.core.gazebo_connection.GAZEBO_GET_PHYSICS_PROPERTIES_TOPIC = '/gazebo/get_physics_properties'[source]
ros_gazebo_gym.core.gazebo_connection.GAZEBO_SET_PHYSICS_PROPERTIES_TOPIC = '/gazebo/set_physics_properties'[source]
ros_gazebo_gym.core.gazebo_connection.PHYSICS_UPDATE_RATE = 1000[source]
ros_gazebo_gym.core.gazebo_connection.SERVICES_CONNECTION_TIMEOUTS = 5[source]
class ros_gazebo_gym.core.gazebo_connection.GazeboConnection(reset_world_or_sim='WORLD', max_retry=20, retry_rate=5, log_reset=True)[source]

Class that contains several methods that can be used to interact with the Gazebo simulation.

pause_proxy

ROS service that pauses the gazebo simulator.

Type:

rospy.impl.tcpros_service.ServiceProxy

unpause_proxy

ROS service that un-pauses the gazebo simulator.

Type:

rospy.impl.tcpros_service.ServiceProxy

reset_simulation_proxy

ROS service that resets the gazebo simulator.

Type:

rospy.impl.tcpros_service.ServiceProxy

reset_world_proxy

ROS service that resets the gazebo world.

Type:

rospy.impl.tcpros_service.ServiceProxy

spawn_sdf_proxy

ROS service that spawns a sdf model.

Type:

rospy.impl.tcpros_service.ServiceProxy

spawn_urdf_proxy

ROS service that spawns a urdf model.

Type:

rospy.impl.tcpros_service.ServiceProxy

get_model_state_proxy

ROS service used to set get model states.

Type:

rospy.impl.tcpros_service.ServiceProxy

set_model_state_proxy

ROS service used to set the model state of a object.

Type:

rospy.impl.tcpros_service.ServiceProxy

ROS service used to set the link states.

Type:

rospy.impl.tcpros_service.ServiceProxy

ROS service used to get the link states.

Type:

rospy.impl.tcpros_service.ServiceProxy

set_model_configuration_proxy

ROS service that sets the configuration of a model.

Type:

rospy.impl.tcpros_service.ServiceProxy

get_physics_proxy

ROS service used to retrieve the physics properties.

Type:

rospy.impl.tcpros_service.ServiceProxy

set_physics_proxy

ROS service used to set the physics properties.

Type:

rospy.impl.tcpros_service.ServiceProxy

Initiate the GazeboConnection instance.

Parameters:
  • reset_world_or_sim (str, optional) – Whether you want to reset the whole simulation “SIMULATION” at startup or only the world “WORLD” (object positions). Defaults to “WORLD”.

  • max_retry (int, optional) – How many times a command to the simulator is retried before giving up. Defaults to 30.

  • retry_rate (int, optional) – The rate at which the retry is done. Defaults to 2 (i.e. 0.5 seconds).

  • log_reset (bool, optional) – Whether we want to print a log statement when the world/simulation is reset. Defaults to True.

property physics_properties[source]

Retrieves the physics properties from gazebo.

property time[source]

Retrieves the Gazebo time.

pause_sim()[source]

Pause the simulation.

unpause_sim()[source]

Unpauses the simulation.

reset_sim()[source]

Reset the simulation or the world.

Note

Implemented like this since in some simulations, when reset the simulation the systems that work with TF break. In this case we ONLY resets the object position, not the entire simulation.

get_model_state(model_name)[source]

Retrieve the current state of a model.

Parameters:

model_name (str) – The name of the model for which you want to retrieve the state.

Returns:

The pose of the model.

Return type:

numpy.ndarray

Raises:

ros_gazebo_gym.exceptions.GetModelStateError – Thrown when the model state retrieval failed.

set_model_state(model_state)[source]

Sets the state of a model.

Parameters:

model_state (gazebo_msgs.msg.SetModelState) – The model_state object.

Returns:

Boolean specifying whether the model state was set successfully.

Return type:

bool

Raises:

ros_gazebo_gym.exceptions.SetModelStateError – Thrown when the model state could not be set.

Retrieve the current state of a model.

Parameters:

link_name (str) – The name of the robot link.

Returns:

The pose of the robot link.

Return type:

numpy.ndarray

Raises:

GetLinkStateError – Thrown when the link state retrieval failed.

set_model_configuration(model_name, joint_names, joint_positions, pause=True)[source]

Sets the configuration of a model.

Parameters:
  • model_name (string) – Model to set the configuration for.

  • joint_names (list) – The joint names for which you want to set the configuration.

  • joint_positions (list) – The joint positions you want to set.

  • pause (bool, optional) – Pause the simulation while setting the model pose. Defaults to True.

Returns:

Boolean specifying whether the model configuration was set

successfully.

Return type:

bool

Raises:

ros_gazebo_gym.exceptions.SetModelConfigurationError – Thrown when the model configuration could not be set.

get_physics_properties()[source]

Retrieve physics properties from gazebo.

Returns:

Physics properties

message.

Return type:

gazebo_msgs.srv.GetPhysicsPropertiesResponse

Raises:

ros_gazebo_gym.errors.GetPhysicsPropertiesError – Thrown when something goes wrong while trying to retrieve the physics properties.

set_physics_properties(**kwargs)[source]

Change physics properties of the gazebo physics engine. These properties have to be supplied as a keyword argument.

Tip

You can use the GazeboConnection.set_physics_proxy If you want to send a gazebo_msgs.srv.SetPhysicsProperties message directly.

Parameters:

**kwargs – Keyword arguments specifying the physics properties you want to set.

Raises:

SetPhysicsPropertiesError – Thrown when something goes wrong while setting the physics properties.

change_gravity(x, y, z)[source]

Changes the gravity vector

Parameters:
  • x (float) – Gravity vector x coordinate.

  • y (float) – Gravity vector y coordinate.

  • z (float) – Gravity vector z coordinate.

spawn_object(object_name, model_name, models_folder_path, pose=None)[source]

Spawns a object from the model directory into gazebo.

Parameters:
  • object_name (str) – The name you want the model to have.

  • model_name (str) – The model type (The name of the xml file you want to use).

  • models_folder_path (str) – The folder in which you want to search for the models.

  • pose (geometry_msgs.msg.Pose, optional) – The pose of the model, by default geometry_msgs.msg.Pose.

Returns:

A boolean specifying whether the model was successfully spawned.

Return type:

bool

Raises:

ros_gazebo_gym.exceptions.SpawnModelError – When model was not spawned successfully.