rosros

Simple unified interface to ROS1 / ROS2 Python API

Index
Installation
Example usage
ROS core functionality
ROS API helpers
Converting an existing package

API documentation
View the Project on GitHub suurjaak/rosros

ROS API helpers

Functionality for working with message types and data and metainfo. Can be used as stand-alone library functions without initializing rosros core.

Name Description Arguments
Message types and instances
rosros.api.get_message_class returns ROS message / service class object, like std_msgs.msg.Bool for "std_msgs/Bool" msg_or_type
rosros.api.get_message_definition returns ROS message or service request/response type definition text, msg_or_type, full=True
by default including message subtype definitions
rosros.api.get_message_fields returns {field name: field type name} if ROS message or service request/response, else {} val
rosros.api.get_message_header returns message Header-attribute if any, else None val
rosros.api.get_message_type returns ROS message / service canonical type name, like "std_msgs/Header" msg_or_cls
or "*" for AnyMsg
rosros.api.get_message_type_hash returns ROS message / service type MD5 hash msg_or_type
rosros.api.get_message_value returns message attribute value, with numeric arrays converted to lists msg, name, default=...
rosros.api.is_ros_message returns whether value is a ROS message or service request/response class or instance val
Message conversion
rosros.api.deserialize_message returns ROS message or service request/response instantiated from serialized binary raw, cls_or_typename
rosros.api.dict_to_message returns ROS message populated from Python dictionary dct, msg_or_type
rosros.api.message_to_dict returns ROS message as nested Python dictionary; msg, replace=None
with optional replacements for certain values like {math.nan: None}
rosros.api.message_to_str returns ROS message as an evaluatable string, e.g. "std_msgs.msg.UInt8(data=0)" msg, indent=None
rosros.api.serialize_message returns ROS message or service request/response as a serialized binary of bytes() msg
Service classes and definitions
rosros.api.get_service_definition returns ROS service type definition text srv_or_type
rosros.api.get_service_request_class returns ROS service request class object srv_or_type
rosros.api.get_service_response_classreturns ROS service response class object srv_or_type
rosros.api.is_ros_service returns whether value is a ROS service class object val
Time and duration
rosros.api.is_ros_time returns whether value is a ROS time/duration val
rosros.api.make_duration returns a ROS duration secs=0, nsecs=0
rosros.api.make_time returns a ROS time secs=0, nsecs=0
rosros.api.time_category returns "time" or "duration" for time/duration type, else value msg_or_type
rosros.api.time_message returns ROS2 time/duration from rclpy as builtin_interfaces or vice versa, val, to_message=True, clock_type=None
or value if not convertible
rosros.api.to_datetime returns value as datetime.datetime if value is ROS time/duration, else value val
rosros.api.to_decimal returns value as decimal.Decimal if value is ROS time/duration, else value val
rosros.api.to_duration returns value as ROS duration if convertible (int/float/time/datetime/decimal), else value val
rosros.api.to_nsec returns value in nanoseconds if value is ROS time/duration, else value val
rosros.api.to_sec returns value in seconds if value is ROS time/duration, else value val
rosros.api.to_sec_nsec returns value in (seconds, nanoseconds) if value is ROS time/duration, else value val
rosros.api.to_time returns value as ROS time if convertible (int/float/duration/datetime/decimal), else value val
Class and type names
rosros.api.canonical returns "pkg/Type" for "pkg/subdir/Type" typename
rosros.api.get_alias_type returns ROS built-in type for alias like "char", if any; reverse of get_type_alias(). typename
In ROS1, byte and char are aliases for int8 and uint8; in ROS2 the reverse.
rosros.api.get_type_alias returns alias like "char" for ROS built-in type, if any; reverse of get_alias_type(). typename
In ROS1, byte and char are aliases for int8 and uint8; in ROS2 the reverse.
rosros.api.make_full_typename returns "pkg/msg/Type" or "pkg/srv/Type" for "pkg/Type" typename, category="msg"
rosros.api.scalar returns scalar type from ROS message data type, like "uint8" from uint8-array; typename
in ROS2, returns unbounded type, e.g. "string" from "string<=10[<=5]".
Miscellaneous
rosros.api.format_param_name returns parameter name with correct separator for ROS version, and leading sigils stripped name
rosros.api.PARAM_SEPARATOR separator char between ROS parameter namespace parts
rosros.api.ROS_BUILTIN_TYPES list of ROS built-in numeric and string type names, like ["string", "uint8", ..]
rosros.api.ROS_NUMERIC_TYPES list of ROS built-in numeric type names, like ["bool", "int8", ..]
rosros.api.ROS_STRING_TYPES list of ROS built-in string type names
rosros.api.ROS_TIME_CLASSES ROS time/duration types mapped to type names
rosros.api.ROS_TIME_TYPES list of ROS built-in time/duration type names