ros_gazebo_gym.common.helpers
Contains several helper functions that are used in the several environments.
Module Contents
Classes
Dummy file class to redirect stderr to. |
Functions
|
Converts the a gazebo_msgs/ModelState |
|
Create a pose dictionary |
|
De-capitalize the first letter of a string. |
|
Wrap one additional space around text if it is not already present. |
|
Convert a string to pascal case. |
|
Convert a string to snake case. |
|
Function converts a list of values into human readable sentence. |
|
Split a dictionary into smaller dictionaries based on the keys. |
|
Splits the bounding region dictionary into two separate bounding dictionaries, |
|
Replaces a 'gripper_width' key in a dictionary with corresponding finger joint |
|
Splits a pose dictionary into two separate pose dictionaries, one for the |
|
Given several dicts, merge them into a new dict as a shallow copy. |
|
Function used to flatten a list containing sublists. It does this by calling |
|
Updates a dictionary recursively (i.e. deep update). This function takes a update |
|
Checks whether lst1 is a sublist of lst2. |
|
Removes all the None values from a dictionary. |
|
Validates whether a variable or its attributes has an invalid type. |
|
Checks whether a topic contains an action server |
|
Finds the path of the |
|
Converts pose (position, orientation) to euler angles. |
|
Calculates the norm of a quaternion. |
|
Normalizes a given quaternion. |
Suppresses the stderr output of a code block. |
- ros_gazebo_gym.common.helpers.model_state_msg_2_link_state_dict(link_state_msgs)[source]
Converts the a gazebo_msgs/ModelState message into a state dictionary. Contrary to the original ModelState message, in the model state dictionary the poses and twists are grouped per link/model.
- Parameters:
link_state_msgs (
gazebo_msgs.msg.ModelState
) – A ModelState message.- Returns:
A model_state dictionary.
- Return type:
- ros_gazebo_gym.common.helpers.pose_msg_2_pose_dict(pose_msg)[source]
Create a pose dictionary
{x, y, z, rx, ry, rz, rw}
out of a geometry_msgs.msg.Pose message.- Parameters:
pose_msg (
geometry_msgs.msg.Pose
) – A pose message- Returns:
Dictionary that contains the pose.
- Return type:
- ros_gazebo_gym.common.helpers.lower_first_char(string)[source]
De-capitalize the first letter of a string.
Note
This function is not the exact opposite of the capitalize function of the standard library. For example, capitalize(‘abC’) returns Abc rather than AbC.
- ros_gazebo_gym.common.helpers.wrap_space_around(text)[source]
Wrap one additional space around text if it is not already present.
- ros_gazebo_gym.common.helpers.list_2_human_text(input_list, separator=', ', end_separator=' & ')[source]
Function converts a list of values into human readable sentence.
Example
Using this function a list of 4 items
[item1, item2, item3, item4]
becomesitem2, item3 & item4
.
- ros_gazebo_gym.common.helpers.split_dict(input_dict, *args)[source]
Split a dictionary into smaller dictionaries based on the keys.
Example
split_dict_list = split_dict( input_dict, ["first_dict_key1", "first_dict_key2"], ["second_dict_key1", "second_dict_key2"] )
- ros_gazebo_gym.common.helpers.split_bounds_dict(bounds_dict)[source]
Splits the bounding region dictionary into two separate bounding dictionaries, one for the
ee_pose
and one fore thejoint_pose
.
- ros_gazebo_gym.common.helpers.gripper_width_2_finger_joints_positions(input_dict, joints)[source]
Replaces a ‘gripper_width’ key in a dictionary with corresponding finger joint position keys.
- ros_gazebo_gym.common.helpers.split_pose_dict(pose_dict)[source]
Splits a pose dictionary into two separate pose dictionaries, one for the
ee_pose
and one fore thejoint_pose
.
- ros_gazebo_gym.common.helpers.shallow_dict_merge(*args, order=None)[source]
Given several dicts, merge them into a new dict as a shallow copy.
- ros_gazebo_gym.common.helpers.flatten_list(input_list)[source]
Function used to flatten a list containing sublists. It does this by calling itself recursively.
- ros_gazebo_gym.common.helpers.deep_update(d, u=None, fixed=False, **kwargs)[source]
Updates a dictionary recursively (i.e. deep update). This function takes a update dictionary and/or keyword arguments. When a keyword argument is supplied, the key-value pair is changed if it exists somewhere in the dictionary.
- Parameters:
- Returns:
The updated dictionary.
- Return type:
See also
Based on the answer given by @alex-martelli on this stackoverflow question.
- ros_gazebo_gym.common.helpers.is_sublist(lst1, lst2)[source]
Checks whether lst1 is a sublist of lst2.
- ros_gazebo_gym.common.helpers.remove_dict_none_values(input_dict)[source]
Removes all the None values from a dictionary.
- ros_gazebo_gym.common.helpers.has_invalid_type(variable, variable_types, items_types=None, depth=0)[source]
Validates whether a variable or its attributes has an invalid type.
- ros_gazebo_gym.common.helpers.action_server_exists(topic_name)[source]
Checks whether a topic contains an action server is running.
- ros_gazebo_gym.common.helpers.find_gazebo_model_path(model_name, models_directory_path, extension='')[source]
Finds the path of the
sdf
orurdf
file that belongs to a givenmodel_name
. This is done by searching in themodels_directory_path
folder. If no file was found the model file path is returned empty.- Parameters:
model_name (str) – The name of the model for which you want to find the path.
models_directory_path (str) – The path of the folder that contains the gazebo models. extension (str, optional): The model path extension. Defaults to
""
meaning that the function will first look for asdf
file and if that is not found it will look for aurdf
file.
- Returns:
tuple containing:
- Return type:
(tuple)
- ros_gazebo_gym.common.helpers.get_orientation_euler(quaternion)[source]
Converts pose (position, orientation) to euler angles.
- Parameters:
quaternion (
geometry_msgs.Pose
) – Input quaternion.
- Returns=:
EulerAngles
: Object containing theyaw (z), pitch (y) and roll (x) euler angles.
- ros_gazebo_gym.common.helpers.quaternion_norm(quaternion)[source]
Calculates the norm of a quaternion.
- Parameters:
Quaternion (
geometry_msgs.msg.Quaternion
) – A quaternion.- Returns:
The norm of the quaternion.
- Return type:
- ros_gazebo_gym.common.helpers.normalize_quaternion(quaternion)[source]
Normalizes a given quaternion.
- Parameters:
quaternion (
geometry_msgs.msg.Quaternion
) – A quaternion.- Returns:
The normalized quaternion.
- Return type:
geometry_msgs.msg.Quaternion