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

ROS2 interface. More...

Classes

class  ROS2Bag
 ROS2 bag reader and writer (SQLite format), providing most of rosbag.Bag interface. More...
 

Functions

 canonical (typename, unbounded=False)
 Returns "pkg/Type" for "pkg/msg/Type", standardizes various ROS2 formats.
 
 create_publisher (topic, cls_or_typename, queue_size)
 Returns an rclpy.Publisher instance, with .get_num_connections() and .unregister().
 
 create_subscriber (topic, cls_or_typename, handler, queue_size)
 Returns an rclpy.Subscription.
 
 deserialize_message (raw, cls_or_typename)
 Returns ROS2 message or service request/response instantiated from serialized binary.
 
 format_message_value (msg, name, value)
 Returns a message attribute value as string.
 
 get_message_class (typename)
 Returns ROS2 message class, or None if unknown type.
 
 get_message_definition (msg_or_type)
 Returns ROS2 message type definition full text, including subtype definitions.
 
 get_message_definition_idl (typename)
 Returns ROS2 message type definition parsed from IDL file.
 
 get_message_fields (val)
 Returns OrderedDict({field name: field type name}) if ROS2 message, else {}.
 
 get_message_type (msg_or_cls)
 Returns ROS2 message type name, like "std_msgs/Header".
 
 get_message_type_hash (msg_or_type)
 Returns ROS2 message type MD5 hash, or "" if unknown type.
 
 get_message_value (msg, name, typename=None, default=Ellipsis)
 Returns object attribute value, with numeric arrays converted to lists.
 
 get_rostime (fallback=False)
 Returns current ROS2 time, as rclpy.time.Time.
 
 get_topic_types ()
 Returns currently available ROS2 topics, as [(topicname, typename)].
 
 init_node (name)
 Initializes a ROS2 node if not already initialized.
 
 is_ros_message (val, ignore_time=False)
 Returns whether value is a ROS2 message or special like ROS2 time/duration class or instance.
 
 is_ros_time (val)
 Returns whether value is a ROS2 time/duration class or instance.
 
 make_duration (secs=0, nsecs=0)
 Returns an rclpy.duration.Duration.
 
 make_full_typename (typename)
 Returns "pkg/msg/Type" for "pkg/Type".
 
 make_subscriber_qos (topic, typename, queue_size=10)
 Returns rclpy.qos.QoSProfile that matches the most permissive publisher.
 
 make_time (secs=0, nsecs=0)
 Returns a ROS2 time, as rclpy.time.Time.
 
 qos_to_dict (qos)
 Returns rclpy.qos.QoSProfile as dictionary.
 
 scalar (typename)
 Returns unbounded scalar type from ROS2 message data type.
 
 serialize_message (msg)
 Returns ROS2 message as a serialized binary.
 
 set_message_value (obj, name, value)
 Sets message or object attribute value.
 
 shutdown_node ()
 Shuts down live ROS2 node.
 
 time_message (val, to_message=True, clock_type=None)
 Converts ROS2 time/duration between rclpy and builtin_interfaces objects.
 
 to_duration (val)
 Returns value as ROS2 duration if convertible (int/float/time/datetime/decimal), else value.
 
 to_nsec (val)
 Returns value in nanoseconds if value is ROS2 time/duration, else value.
 
 to_sec (val)
 Returns value in seconds if value is ROS2 time/duration, else value.
 
 to_sec_nsec (val)
 Returns value as (seconds, nanoseconds) if value is ROS2 time/duration, else value.
 
 to_time (val)
 Returns value as ROS2 time if convertible, else value.
 
 validate (live=False)
 Returns whether ROS2 environment is set, prints error if not.
 

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.

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]".

Parameters
unboundeddrop constraints like array and string bounds, e.g. returning "uint8[]" for "uint8[10]" and "string" for "string<=8"

Definition at line 620 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 653 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 670 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 994 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 699 of file ros2.py.

◆ get_message_class()

get_message_class (   typename)

Returns ROS2 message class, or None if unknown type.

Definition at line 710 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 721 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 770 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 854 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 861 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 726 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.

Parameters
namemessage attribute name
typenamevalue ROS type name, for identifying byte arrays
defaultvalue to return if attribute does not exist; raises exception otherwise

Definition at line 874 of file ros2.py.

◆ get_rostime()

get_rostime (   fallback = False)

Returns current ROS2 time, as rclpy.time.Time.

Parameters
fallbackuse wall time if node not initialized

Definition at line 893 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 905 of file ros2.py.

◆ init_node()

init_node (   name)

Initializes a ROS2 node if not already initialized.

Definition at line 563 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.

Parameters
ignore_timewhether to ignore ROS2 time/duration types

Definition at line 925 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 931 of file ros2.py.

◆ make_duration()

make_duration (   secs = 0,
  nsecs = 0 
)

Returns an rclpy.duration.Duration.

Definition at line 937 of file ros2.py.

◆ make_full_typename()

make_full_typename (   typename)

Returns "pkg/msg/Type" for "pkg/Type".

Definition at line 947 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.

Parameters
queue_sizeQoSProfile.depth

Definition at line 959 of file ros2.py.

◆ make_time()

make_time (   secs = 0,
  nsecs = 0 
)

Returns a ROS2 time, as rclpy.time.Time.

Definition at line 942 of file ros2.py.

◆ qos_to_dict()

qos_to_dict (   qos)

Returns rclpy.qos.QoSProfile as dictionary.

Definition at line 970 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 1008 of file ros2.py.

◆ serialize_message()

serialize_message (   msg)

Returns ROS2 message as a serialized binary.

Definition at line 987 of file ros2.py.

◆ set_message_value()

set_message_value (   obj,
  name,
  value 
)

Sets message or object attribute value.

Definition at line 1014 of file ros2.py.

◆ shutdown_node()

shutdown_node ( )

Shuts down live ROS2 node.

Definition at line 586 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.

Parameters
valROS2 time/duration object from rclpy or builtin_interfaces
to_messagewhether to convert from rclpy to builtin_interfaces or vice versa
clock_typeClockType for converting to rclpy.Time, defaults to ROS_TIME
Returns
value converted to appropriate type, or original value if not convertible

Definition at line 1031 of file ros2.py.

◆ to_duration()

to_duration (   val)

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

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

Definition at line 1047 of file ros2.py.

◆ to_nsec()

to_nsec (   val)

Returns value in nanoseconds if value is ROS2 time/duration, else value.

Definition at line 1062 of file ros2.py.

◆ to_sec()

to_sec (   val)

Returns value in seconds if value is ROS2 time/duration, else value.

Definition at line 1071 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 1081 of file ros2.py.

◆ to_time()

to_time (   val)

Returns value as ROS2 time if convertible, else value.

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

Definition at line 1097 of file ros2.py.

◆ validate()

validate (   live = False)

Returns whether ROS2 environment is set, prints error if not.

Parameters
livewhether environment must support launching a ROS node

Definition at line 601 of file ros2.py.

Variable Documentation

◆ Bag

Bag = ROS2Bag

Definition at line 559 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.