Package Summary

Tags No category tags.
Version 2.0.10
License BSD
Build type CATKIN
Use RECOMMENDED

Repository Summary

Checkout URI https://github.com/ctu-vras/ros-utils.git
VCS Type git
VCS Version master
Last Updated 2022-11-30
Dev Status DEVELOPED
CI status No Continuous Integration
Released RELEASED
Tags No category tags.
Contributing Help Wanted (0)
Good First Issues (0)
Pull Requests to Review (0)

Package Description

A Czech-army knife for ROS code written in Python.

Additional Links

Maintainers

  • Martin Pecka

Authors

  • Martin Pecka

cras_py_common

A Czech-army knife for ROS code written in Python.

The aim of this package is to provide some missing utility functions to rospy. Using libraries from this package, you should be able to write more efficient, safer and less error-prone code without much boilerplate. As this package is intended to handle a lot of the boring code for you "behind the scenes", ubiquitous effort was put into unit-testing everything, so that you can rely on the provided code without the usual fear whether it works or not.

This readme shortly introduces the provided libraries. Detailed documentation can be found in the comments in code and in the API docs. Examples of usage can be found in the dependent packages from ros-utils, and in the unit tests.

Parts of this package were used by team CTU-CRAS-Norlab in DARPA Subterranean Challenge.

Support and Build Status

This package is supported on Melodic and Noetic until their End of Life (and maybe later). It is occasionally tested with non-default GCC versions like Melodic+GCC8 or Noetic+GCC11.

Development versions: CI Dev melodic Dev noetic ubuntu Dev noetic debian

Release jobs Melodic Melodic version: Bin melodic-amd64 Bin melodic-arm64 Bin melodic-armhf

Release jobs Noetic Noetic version: Bin ubuntu noetic-amd64 Bin ubuntu noetic-arm64 Bin ubuntu noetic-armhf Bin debian noetic-amd64 Bin debian noetic-arm64

List of Provided Modules

The most useful functions and classes from these modules are available directly from the cras package, i.e.

from cras import to_str
# instead of
from cras.string_utils import to_str

  • geometry_utils: Finally THE module providing easy and foolproof conversion between quaternions and roll/pitch/yaw notation.
  • log_utils: Some convenience for rospy logging. This is mostly an internal library, but it can be used elsewhere, too.
  • message_utils: Conversion of std_msgs/String to Python type etc. Generic access to message fields using a string "address".
  • param_utils: Utilities for type-safe, easy, unified and configurable access to ROS parameters. See below for examples and more details.
  • static_transform_broadcaster: An drop-in replacement of tf2_ros.static_transform_broadcaster that can safely publish multiple transforms from a single node (upstreaming to tf2_ros in progress).
  • string_utils: Universal to_str() that converts almost anything to a sensible string.
  • test_utils: Utilities for writing unit tests, e.g. a tool that can "read" what was written by rospy.loginfo().
  • time_utils: Conversions between rospy.Rate and frequency. rospy.Rate equality comparison. Min/max time and duration constants. WallTime, WallRate, SteadyTime, SteadyRate, and a Timer that can use these custom rates.
  • topic_utils: Generic topic subscriber.

param_utils: Parameter Reading Helpers

param_utils provide a type-safe, unified and highly configurable interface for reading ROS parameters. Read a numpy matrix, vector of unsigned ints, rospy.Duration or geometry_msgs.msg.Vector3 directly without the need to write a single line of conversion code or value checking. Type of the value to read is automatically determined either from the provided default value, or from result_type parameter.

Example usage:

from cras import get_param, GetParamException
from geometry_msgs.msg import Vector3

# read array of 3 doubles from parameter server into a geometry_msgs.msg.Vector3, defaulting to the specified vector if not set.
gravity = get_param("gravity", Vector3(0, 0, -9.81), "m.s^-2")

# required parameters are specified by not having a default; if you still want conversion to some type, use result_type
try:
    gravity2 = get_param("gravity", "m.s^-2", result_type=Vector3)
except GetParamException as e:
    # the exception is raised if the required parameter is not set
    # e.info contains details about the unsuccessful lookup
    print(e.info.message)

You can also configure the parameter lookup behavior, e.g. to throw exception if the value cannot be converted to the requested type (normally, the default value is used in such case):

# will throw GetParamException if int_param has a value different from 0 and 1
from cras import get_param
bool_param = get_param("int_param", False, throw_if_convert_fails=True)

Finally, there is also a more verbose version of get_param() that tells more about how the lookup went:

from cras import get_param_verbose
res = get_param_verbose("int", 0)
int_param = res.value
was_default_used = res.info.default_used

CHANGELOG

Changelog for package cras_py_common

2.0.10 (2022-11-24)

  • Fix test bug.
  • Contributors: Martin Pecka

2.0.9 (2022-11-24)

  • Relay attribute access in GenericMessageSubscriber to the raw subscriber (to allow e.g. calling unsubscribe()).
  • Contributors: Martin Pecka

2.0.8 (2022-11-24)

  • Pass connection header to user callback in GenericMessageSubscriber.
  • Contributors: Martin Pecka

2.0.7 (2022-11-24)

  • Moved get_msg_type from type_utils to message_utils and added get_msg_field there.
  • Contributors: Martin Pecka

2.0.6 (2022-11-24)

  • Added topic_utils and type_utils.
  • Contributors: Martin Pecka

2.0.5 (2022-10-23)

  • Added static_transform_broadcaster docs to readme.
  • Contributors: Martin Pecka

2.0.4 (2022-10-14)

  • Fixed StaticTransformBroadcaster on Noetic and added unit test for it.
  • Added missing license notices.
  • Contributors: Martin Pecka

2.0.3 (2022-10-07)

  • Improved time_utils, added node_utils.
  • Added geometry_utils.py.
  • Remove support for long integer type to achieve compatibility with Python 3.
  • Extended functionality to get closer to cras_cpp_common.
  • Improved readmes and added more badges to them.
  • Contributors: Martin Pecka

2.0.2 (2022-08-29)

  • De-flake throttle test and enable catkin_lint when it has chance to run correctly.
  • Added website links.
  • Add linters and licenses.
  • Contributors: Martin Pecka

2.0.1 (2022-08-26)

  • Moved hack_frame_id from cras_py_common to cras_topic_tools.

1.0.0

  • Added improved static_transform_broadcaster for Python.
  • Added hack_frame_id
  • Added cras_py_common
  • Contributors: Martin Pecka

Wiki Tutorials

See ROS Wiki Tutorials for more details.

Source Tutorials

Not currently indexed.

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged cras_py_common at answers.ros.org

Package Summary

Tags No category tags.
Version 2.0.10
License BSD
Build type CATKIN
Use RECOMMENDED

Repository Summary

Checkout URI https://github.com/ctu-vras/ros-utils.git
VCS Type git
VCS Version master
Last Updated 2022-11-30
Dev Status DEVELOPED
CI status No Continuous Integration
Released RELEASED
Tags No category tags.
Contributing Help Wanted (0)
Good First Issues (0)
Pull Requests to Review (0)

Package Description

A Czech-army knife for ROS code written in Python.

Additional Links

Maintainers

  • Martin Pecka

Authors

  • Martin Pecka

cras_py_common

A Czech-army knife for ROS code written in Python.

The aim of this package is to provide some missing utility functions to rospy. Using libraries from this package, you should be able to write more efficient, safer and less error-prone code without much boilerplate. As this package is intended to handle a lot of the boring code for you "behind the scenes", ubiquitous effort was put into unit-testing everything, so that you can rely on the provided code without the usual fear whether it works or not.

This readme shortly introduces the provided libraries. Detailed documentation can be found in the comments in code and in the API docs. Examples of usage can be found in the dependent packages from ros-utils, and in the unit tests.

Parts of this package were used by team CTU-CRAS-Norlab in DARPA Subterranean Challenge.

Support and Build Status

This package is supported on Melodic and Noetic until their End of Life (and maybe later). It is occasionally tested with non-default GCC versions like Melodic+GCC8 or Noetic+GCC11.

Development versions: CI Dev melodic Dev noetic ubuntu Dev noetic debian

Release jobs Melodic Melodic version: Bin melodic-amd64 Bin melodic-arm64 Bin melodic-armhf

Release jobs Noetic Noetic version: Bin ubuntu noetic-amd64 Bin ubuntu noetic-arm64 Bin ubuntu noetic-armhf Bin debian noetic-amd64 Bin debian noetic-arm64

List of Provided Modules

The most useful functions and classes from these modules are available directly from the cras package, i.e.

from cras import to_str
# instead of
from cras.string_utils import to_str

  • geometry_utils: Finally THE module providing easy and foolproof conversion between quaternions and roll/pitch/yaw notation.
  • log_utils: Some convenience for rospy logging. This is mostly an internal library, but it can be used elsewhere, too.
  • message_utils: Conversion of std_msgs/String to Python type etc. Generic access to message fields using a string "address".
  • param_utils: Utilities for type-safe, easy, unified and configurable access to ROS parameters. See below for examples and more details.
  • static_transform_broadcaster: An drop-in replacement of tf2_ros.static_transform_broadcaster that can safely publish multiple transforms from a single node (upstreaming to tf2_ros in progress).
  • string_utils: Universal to_str() that converts almost anything to a sensible string.
  • test_utils: Utilities for writing unit tests, e.g. a tool that can "read" what was written by rospy.loginfo().
  • time_utils: Conversions between rospy.Rate and frequency. rospy.Rate equality comparison. Min/max time and duration constants. WallTime, WallRate, SteadyTime, SteadyRate, and a Timer that can use these custom rates.
  • topic_utils: Generic topic subscriber.

param_utils: Parameter Reading Helpers

param_utils provide a type-safe, unified and highly configurable interface for reading ROS parameters. Read a numpy matrix, vector of unsigned ints, rospy.Duration or geometry_msgs.msg.Vector3 directly without the need to write a single line of conversion code or value checking. Type of the value to read is automatically determined either from the provided default value, or from result_type parameter.

Example usage:

from cras import get_param, GetParamException
from geometry_msgs.msg import Vector3

# read array of 3 doubles from parameter server into a geometry_msgs.msg.Vector3, defaulting to the specified vector if not set.
gravity = get_param("gravity", Vector3(0, 0, -9.81), "m.s^-2")

# required parameters are specified by not having a default; if you still want conversion to some type, use result_type
try:
    gravity2 = get_param("gravity", "m.s^-2", result_type=Vector3)
except GetParamException as e:
    # the exception is raised if the required parameter is not set
    # e.info contains details about the unsuccessful lookup
    print(e.info.message)

You can also configure the parameter lookup behavior, e.g. to throw exception if the value cannot be converted to the requested type (normally, the default value is used in such case):

# will throw GetParamException if int_param has a value different from 0 and 1
from cras import get_param
bool_param = get_param("int_param", False, throw_if_convert_fails=True)

Finally, there is also a more verbose version of get_param() that tells more about how the lookup went:

from cras import get_param_verbose
res = get_param_verbose("int", 0)
int_param = res.value
was_default_used = res.info.default_used

CHANGELOG

Changelog for package cras_py_common

2.0.10 (2022-11-24)

  • Fix test bug.
  • Contributors: Martin Pecka

2.0.9 (2022-11-24)

  • Relay attribute access in GenericMessageSubscriber to the raw subscriber (to allow e.g. calling unsubscribe()).
  • Contributors: Martin Pecka

2.0.8 (2022-11-24)

  • Pass connection header to user callback in GenericMessageSubscriber.
  • Contributors: Martin Pecka

2.0.7 (2022-11-24)

  • Moved get_msg_type from type_utils to message_utils and added get_msg_field there.
  • Contributors: Martin Pecka

2.0.6 (2022-11-24)

  • Added topic_utils and type_utils.
  • Contributors: Martin Pecka

2.0.5 (2022-10-23)

  • Added static_transform_broadcaster docs to readme.
  • Contributors: Martin Pecka

2.0.4 (2022-10-14)

  • Fixed StaticTransformBroadcaster on Noetic and added unit test for it.
  • Added missing license notices.
  • Contributors: Martin Pecka

2.0.3 (2022-10-07)

  • Improved time_utils, added node_utils.
  • Added geometry_utils.py.
  • Remove support for long integer type to achieve compatibility with Python 3.
  • Extended functionality to get closer to cras_cpp_common.
  • Improved readmes and added more badges to them.
  • Contributors: Martin Pecka

2.0.2 (2022-08-29)

  • De-flake throttle test and enable catkin_lint when it has chance to run correctly.
  • Added website links.
  • Add linters and licenses.
  • Contributors: Martin Pecka

2.0.1 (2022-08-26)

  • Moved hack_frame_id from cras_py_common to cras_topic_tools.

1.0.0

  • Added improved static_transform_broadcaster for Python.
  • Added hack_frame_id
  • Added cras_py_common
  • Contributors: Martin Pecka

Wiki Tutorials

See ROS Wiki Tutorials for more details.

Source Tutorials

Not currently indexed.

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged cras_py_common at answers.ros.org