grepros 1.3.0
grep for ROS bag files and live topics
Loading...
Searching...
No Matches
grepros.ros2 Namespace Reference

Classes

class  ROS2Bag
 

Functions

 canonical (typename, unbounded=False)
 
 create_publisher (topic, cls_or_typename, queue_size)
 
 create_subscriber (topic, cls_or_typename, handler, queue_size)
 
 deserialize_message (raw, cls_or_typename)
 
 format_message_value (msg, name, value)
 
 get_message_class (typename)
 
 get_message_definition (msg_or_type)
 
 get_message_definition_idl (typename)
 
 get_message_fields (val)
 
 get_message_type (msg_or_cls)
 
 get_message_type_hash (msg_or_type)
 
 get_message_value (msg, name, typename=None, default=Ellipsis)
 
 get_rostime (fallback=False)
 
 get_topic_types ()
 
 init_node (name)
 
 is_ros_message (val, ignore_time=False)
 
 is_ros_time (val)
 
 make_duration (secs=0, nsecs=0)
 
 make_full_typename (typename)
 
 make_subscriber_qos (topic, typename, queue_size=10)
 
 make_time (secs=0, nsecs=0)
 
 qos_to_dict (qos)
 
 scalar (typename)
 
 serialize_message (msg)
 
 set_message_value (obj, name, value)
 
 shutdown_node ()
 
 time_message (val, to_message=True, clock_type=None)
 
 to_duration (val)
 
 to_nsec (val)
 
 to_sec (val)
 
 to_sec_nsec (val)
 
 to_time (val)
 
 validate (live=False)
 

Variables

 Bag = ROS2Bag
 
tuple BAG_EXTENSIONS = (".db3", )
 Bagfile extensions to seek.
 
 context = None
 rclpy.context.Context instance
 
dict DDS_TYPES
 Data Distribution Service types to ROS builtins.
 
 executor = None
 rclpy.executors.Executor instance
 
 node = None
 rclpy.node.Node instance
 
dict ROS_ALIAS_TYPES = {"byte": "uint8", "char": "int8"}
 Mapping between type aliases and real types, like {"byte": "uint8"}.
 
dict ROS_TIME_CLASSES
 ROS2 time/duration types and message types mapped to type names.
 
dict ROS_TIME_MESSAGES
 ROS2 time/duration types mapped to message types.
 
list ROS_TIME_TYPES = ["builtin_interfaces/Time", "builtin_interfaces/Duration"]
 ROS2 time/duration message types.
 
tuple SKIP_EXTENSIONS = ()
 Bagfile extensions to skip.
 

Detailed Description

ROS2 interface.

------------------------------------------------------------------------------
This file is part of grepros - grep for ROS bag files and live topics.
Released under the BSD License.

@author      Erki Suurjaak
@created     02.11.2021
@modified    20.11.2024
------------------------------------------------------------------------------

Function Documentation

◆ canonical()

canonical (   typename,
  unbounded = False 
)
Returns "pkg/Type" for "pkg/msg/Type", standardizes various ROS2 formats.

Converts DDS types like "octet" to "byte", and "sequence<uint8, 100>" to "uint8[100]".

@param  unbounded  drop constraints like array and string bounds,
                   e.g. returning "uint8[]" for "uint8[10]" and "string" for "string<=8"

Definition at line 588 of file ros2.py.

◆ create_publisher()

create_publisher (   topic,
  cls_or_typename,
  queue_size 
)
Returns an rclpy.Publisher instance, with .get_num_connections() and .unregister().

Definition at line 629 of file ros2.py.

◆ create_subscriber()

create_subscriber (   topic,
  cls_or_typename,
  handler,
  queue_size 
)
Returns an rclpy.Subscription.

Supplemented with .get_message_class(), .get_message_definition(),
.get_message_type_hash(), .get_qoses(), and.unregister().

Definition at line 640 of file ros2.py.

◆ deserialize_message()

deserialize_message (   raw,
  cls_or_typename 
)
Returns ROS2 message or service request/response instantiated from serialized binary.

Definition at line 967 of file ros2.py.

◆ format_message_value()

format_message_value (   msg,
  name,
  value 
)
Returns a message attribute value as string.

Result is at least 10 chars wide if message is a ROS2 time/duration
(aligning seconds and nanoseconds).

Definition at line 669 of file ros2.py.

◆ get_message_class()

get_message_class (   typename)
Returns ROS2 message class, or None if unknown type.

Definition at line 686 of file ros2.py.

◆ get_message_definition()

get_message_definition (   msg_or_type)
Returns ROS2 message type definition full text, including subtype definitions.

Returns None if unknown type.

Definition at line 692 of file ros2.py.

◆ get_message_definition_idl()

get_message_definition_idl (   typename)
Returns ROS2 message type definition parsed from IDL file.

@since   version 0.4.2

Definition at line 740 of file ros2.py.

◆ get_message_fields()

get_message_fields (   val)
Returns OrderedDict({field name: field type name}) if ROS2 message, else {}.

Definition at line 827 of file ros2.py.

◆ get_message_type()

get_message_type (   msg_or_cls)
Returns ROS2 message type name, like "std_msgs/Header".

Definition at line 834 of file ros2.py.

◆ get_message_type_hash()

get_message_type_hash (   msg_or_type)
Returns ROS2 message type MD5 hash, or "" if unknown type.

Definition at line 702 of file ros2.py.

◆ get_message_value()

get_message_value (   msg,
  name,
  typename = None,
  default = Ellipsis 
)
Returns object attribute value, with numeric arrays converted to lists.

@param   name      message attribute name
@param   typename  value ROS type name, for identifying byte arrays
@param   default   value to return if attribute does not exist; raises exception otherwise

Definition at line 840 of file ros2.py.

◆ get_rostime()

get_rostime (   fallback = False)
Returns current ROS2 time, as rclpy.time.Time.

@param   fallback  use wall time if node not initialized

Definition at line 861 of file ros2.py.

◆ get_topic_types()

get_topic_types ( )
Returns currently available ROS2 topics, as [(topicname, typename)].

Omits topics that the current ROS2 node itself has published.

Definition at line 873 of file ros2.py.

◆ init_node()

init_node (   name)
Initializes a ROS2 node if not already initialized.

Definition at line 538 of file ros2.py.

◆ is_ros_message()

is_ros_message (   val,
  ignore_time = False 
)
Returns whether value is a ROS2 message or special like ROS2 time/duration class or instance.

@param  ignore_time  whether to ignore ROS2 time/duration types

Definition at line 893 of file ros2.py.

◆ is_ros_time()

is_ros_time (   val)
Returns whether value is a ROS2 time/duration class or instance.

Definition at line 904 of file ros2.py.

◆ make_duration()

make_duration (   secs = 0,
  nsecs = 0 
)
Returns an rclpy.duration.Duration.

Definition at line 910 of file ros2.py.

◆ make_full_typename()

make_full_typename (   typename)
Returns "pkg/msg/Type" for "pkg/Type".

Definition at line 920 of file ros2.py.

◆ make_subscriber_qos()

make_subscriber_qos (   topic,
  typename,
  queue_size = 10 
)
Returns rclpy.qos.QoSProfile that matches the most permissive publisher.

@param   queue_size  QoSProfile.depth

Definition at line 927 of file ros2.py.

◆ make_time()

make_time (   secs = 0,
  nsecs = 0 
)
Returns a ROS2 time, as rclpy.time.Time.

Definition at line 915 of file ros2.py.

◆ qos_to_dict()

qos_to_dict (   qos)
Returns rclpy.qos.QoSProfile as dictionary.

Definition at line 943 of file ros2.py.

◆ scalar()

scalar (   typename)
Returns unbounded scalar type from ROS2 message data type

Like "uint8" from "uint8[]", or "string" from "string<=10[<=5]".
Returns type unchanged if not a collection or bounded type.

Definition at line 975 of file ros2.py.

◆ serialize_message()

serialize_message (   msg)
Returns ROS2 message as a serialized binary.

Definition at line 960 of file ros2.py.

◆ set_message_value()

set_message_value (   obj,
  name,
  value 
)
Sets message or object attribute value.

Definition at line 987 of file ros2.py.

◆ shutdown_node()

shutdown_node ( )
Shuts down live ROS2 node.

Definition at line 561 of file ros2.py.

◆ time_message()

time_message (   val,
  to_message = True,
  clock_type = None 
)
Converts ROS2 time/duration between `rclpy` and `builtin_interfaces` objects.

@param   val         ROS2 time/duration object from `rclpy` or `builtin_interfaces`
@param   to_message  whether to convert from `rclpy` to `builtin_interfaces` or vice versa
@param   clock_type  ClockType for converting to `rclpy.Time`, defaults to `ROS_TIME`
@return              value converted to appropriate type, or original value if not convertible

Definition at line 997 of file ros2.py.

◆ to_duration()

to_duration (   val)
Returns value as ROS2 duration if convertible (int/float/time/datetime/decimal), else value.

Convertible types: int/float/time/datetime/decimal/builtin_interfaces.Time.

Definition at line 1016 of file ros2.py.

◆ to_nsec()

to_nsec (   val)
Returns value in nanoseconds if value is ROS2 time/duration, else value.

Definition at line 1036 of file ros2.py.

◆ to_sec()

to_sec (   val)
Returns value in seconds if value is ROS2 time/duration, else value.

Definition at line 1045 of file ros2.py.

◆ to_sec_nsec()

to_sec_nsec (   val)
Returns value as (seconds, nanoseconds) if value is ROS2 time/duration, else value.

Definition at line 1055 of file ros2.py.

◆ to_time()

to_time (   val)
Returns value as ROS2 time if convertible, else value.

Convertible types: int/float/duration/datetime/decimal/builtin_interfaces.Time.

Definition at line 1066 of file ros2.py.

◆ validate()

validate (   live = False)
Returns whether ROS2 environment is set, prints error if not.

@param   live  whether environment must support launching a ROS node

Definition at line 571 of file ros2.py.

Variable Documentation

◆ Bag

Definition at line 534 of file ros2.py.

◆ BAG_EXTENSIONS

tuple BAG_EXTENSIONS = (".db3", )

Bagfile extensions to seek.

Definition at line 47 of file ros2.py.

◆ context

context = None

rclpy.context.Context instance

Definition at line 84 of file ros2.py.

◆ DDS_TYPES

dict DDS_TYPES
Initial value:
1= {"boolean": "bool",
2 "float": "float32",
3 "double": "float64",
4 "octet": "byte",
5 "short": "int16",
6 "unsigned short": "uint16",
7 "long": "int32",
8 "unsigned long": "uint32",
9 "long long": "int64",
10 "unsigned long long": "uint64", }

Data Distribution Service types to ROS builtins.

Definition at line 69 of file ros2.py.

◆ executor

executor = None

rclpy.executors.Executor instance

Definition at line 87 of file ros2.py.

◆ node

node = None

rclpy.node.Node instance

Definition at line 81 of file ros2.py.

◆ ROS_ALIAS_TYPES

dict ROS_ALIAS_TYPES = {"byte": "uint8", "char": "int8"}

Mapping between type aliases and real types, like {"byte": "uint8"}.

Definition at line 66 of file ros2.py.

◆ ROS_TIME_CLASSES

dict ROS_TIME_CLASSES
Initial value:
1= {rclpy.time.Time: "builtin_interfaces/Time",
2 builtin_interfaces.msg.Time: "builtin_interfaces/Time",
3 rclpy.duration.Duration: "builtin_interfaces/Duration",
4 builtin_interfaces.msg.Duration: "builtin_interfaces/Duration"}

ROS2 time/duration types and message types mapped to type names.

Definition at line 56 of file ros2.py.

◆ ROS_TIME_MESSAGES

dict ROS_TIME_MESSAGES
Initial value:
1= {rclpy.time.Time: builtin_interfaces.msg.Time,
2 rclpy.duration.Duration: builtin_interfaces.msg.Duration}

ROS2 time/duration types mapped to message types.

Definition at line 62 of file ros2.py.

◆ ROS_TIME_TYPES

list ROS_TIME_TYPES = ["builtin_interfaces/Time", "builtin_interfaces/Duration"]

ROS2 time/duration message types.

Definition at line 53 of file ros2.py.

◆ SKIP_EXTENSIONS

tuple SKIP_EXTENSIONS = ()

Bagfile extensions to skip.

Definition at line 50 of file ros2.py.