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

ROS1 interface. More...

Classes

class  ROS1Bag
 ROS1 bag reader and writer. More...
 

Functions

 canonical (typename, unbounded=False)
 Returns "pkg/Type" for "pkg/subdir/Type".
 
 create_publisher (topic, cls_or_typename, queue_size)
 Returns a rospy.Publisher.
 
 create_subscriber (topic, typename, handler, queue_size)
 Returns a rospy.Subscriber.
 
 deserialize_message (raw, cls_or_typename)
 Returns ROS1 message or service request/response instantiated from serialized binary.
 
 format_message_value (msg, name, value)
 Returns a message attribute value as string.
 
 generate_message_classes (typename, typedef)
 Generates ROS message classes dynamically from given name and definition.
 
 get_message_class (typename)
 Returns ROS1 message class.
 
 get_message_definition (msg_or_type)
 Returns ROS1 message type definition full text, including subtype definitions.
 
 get_message_fields (val)
 Returns OrderedDict({field name: field type name}) if ROS1 message, else {}.
 
 get_message_type (msg_or_cls)
 Returns ROS1 message type name, like "std_msgs/Header".
 
 get_message_type_hash (msg_or_type)
 Returns ROS 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 ROS1 time, as rospy.Time.
 
 get_topic_types ()
 Returns currently available ROS1 topics, as [(topicname, typename)].
 
 init_node (name)
 Initializes a ROS1 node if not already initialized.
 
 is_ros_message (val, ignore_time=False)
 Returns whether value is a ROS1 message or special like ROS1 time/duration class or instance.
 
 is_ros_time (val)
 Returns whether value is a ROS1 time/duration class or instance.
 
 make_duration (secs=0, nsecs=0)
 Returns a ROS1 duration, as rospy.Duration.
 
 make_time (secs=0, nsecs=0)
 Returns a ROS1 time, as rospy.Time.
 
 scalar (typename)
 Returns scalar type from ROS message data type, like "uint8" from "uint8[100]".
 
 serialize_message (msg)
 Returns ROS1 message as a serialized binary.
 
 set_message_value (obj, name, value)
 Sets message or object attribute value.
 
 shutdown_node ()
 Shuts down live ROS1 node.
 
 to_duration (val)
 Returns value as ROS1 duration if convertible (int/float/time/datetime/decimal), else value.
 
 to_nsec (val)
 Returns value in nanoseconds if value is ROS time/duration, else value.
 
 to_sec (val)
 Returns value in seconds if value is ROS1 time/duration, else value.
 
 to_sec_nsec (val)
 Returns value as (seconds, nanoseconds) if value is ROS1 time/duration, else value.
 
 to_time (val)
 Returns value as ROS1 time if convertible (int/float/duration/datetime/decimal), else value.
 
 validate (live=False)
 Returns whether ROS1 environment is set, prints error if not.
 

Variables

 Bag = ROS1Bag
 
tuple BAG_EXTENSIONS = (".bag", ".bag.active")
 Bagfile extensions to seek.
 
 genpy_mtx = threading.RLock()
 Mutex for ensuring exclusive access to genpy generator (genpy.dynamic is not thread-safe)
 
 master = None
 rospy.MasterProxy instance
 
dict ROS_ALIAS_TYPES = {"byte": "int8", "char": "uint8"}
 Mapping between type aliases and real types, like {"byte": "int8"}.
 
dict ROS_TIME_CLASSES = {rospy.Time: "time", rospy.Duration: "duration"}
 ROS1 time/duration types mapped to type names.
 
list ROS_TIME_TYPES = ["time", "duration"]
 ROS1 time/duration types.
 
tuple SKIP_EXTENSIONS = (".bag.orig.active", )
 Bagfile extensions to skip.
 
float SLEEP_INTERVAL = 0.5
 Seconds between checking whether ROS master is available.
 
dict TYPECLASSES = {}
 {(typename, typehash): message type class}
 

Detailed Description

ROS1 interface.

Function Documentation

◆ canonical()

canonical (   typename,
  unbounded = False 
)

Returns "pkg/Type" for "pkg/subdir/Type".

Parameters
unboundeddrop array bounds, e.g. returning "uint8[]" for "uint8[10]"

Definition at line 536 of file ros1.py.

◆ create_publisher()

create_publisher (   topic,
  cls_or_typename,
  queue_size 
)

Returns a rospy.Publisher.

Definition at line 544 of file ros1.py.

◆ create_subscriber()

create_subscriber (   topic,
  typename,
  handler,
  queue_size 
)

Returns a rospy.Subscriber.

Local message packages are not required. Subscribes as AnyMsg, creates message class dynamically from connection info, and deserializes message before providing to handler.

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

The supplementary .get_message_xyz() methods should only be invoked after at least one message has been received from the topic, as they get populated from live connection metadata.

Definition at line 570 of file ros1.py.

◆ deserialize_message()

deserialize_message (   raw,
  cls_or_typename 
)

Returns ROS1 message or service request/response instantiated from serialized binary.

Definition at line 753 of file ros1.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 ROS time/duration (aligning seconds and nanoseconds).

Definition at line 603 of file ros1.py.

◆ generate_message_classes()

generate_message_classes (   typename,
  typedef 
)

Generates ROS message classes dynamically from given name and definition.

Modifies sys.path to include the generated Python module.

Parameters
typenamemessage type name like "std_msgs/String"
typedefmessage type definition full text, including all subtype definitions
Returns
dictionary of {typename: typeclass} for message type and all subtypes

Definition at line 622 of file ros1.py.

◆ get_message_class()

get_message_class (   typename)

Returns ROS1 message class.

Definition at line 627 of file ros1.py.

◆ get_message_definition()

get_message_definition (   msg_or_type)

Returns ROS1 message type definition full text, including subtype definitions.

Returns None if unknown type.

Definition at line 644 of file ros1.py.

◆ get_message_fields()

get_message_fields (   val)

Returns OrderedDict({field name: field type name}) if ROS1 message, else {}.

Parameters
valROS1 message class or instance

Definition at line 660 of file ros1.py.

◆ get_message_type()

get_message_type (   msg_or_cls)

Returns ROS1 message type name, like "std_msgs/Header".

Definition at line 667 of file ros1.py.

◆ get_message_type_hash()

get_message_type_hash (   msg_or_type)

Returns ROS message type MD5 hash, or "" if unknown type.

Definition at line 649 of file ros1.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 682 of file ros1.py.

◆ get_rostime()

get_rostime (   fallback = False)

Returns current ROS1 time, as rospy.Time.

Parameters
fallbackuse wall time if node not initialized

Definition at line 697 of file ros1.py.

◆ get_topic_types()

get_topic_types ( )

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

Omits topics that the current ROS1 node itself has published.

Definition at line 709 of file ros1.py.

◆ init_node()

init_node (   name)

Initializes a ROS1 node if not already initialized.

Blocks until ROS master available.

Definition at line 481 of file ros1.py.

◆ is_ros_message()

is_ros_message (   val,
  ignore_time = False 
)

Returns whether value is a ROS1 message or special like ROS1 time/duration class or instance.

Parameters
ignore_timewhether to ignore ROS1 time/duration types

Definition at line 724 of file ros1.py.

◆ is_ros_time()

is_ros_time (   val)

Returns whether value is a ROS1 time/duration class or instance.

Definition at line 729 of file ros1.py.

◆ make_duration()

make_duration (   secs = 0,
  nsecs = 0 
)

Returns a ROS1 duration, as rospy.Duration.

Definition at line 734 of file ros1.py.

◆ make_time()

make_time (   secs = 0,
  nsecs = 0 
)

Returns a ROS1 time, as rospy.Time.

Definition at line 739 of file ros1.py.

◆ scalar()

scalar (   typename)

Returns scalar type from ROS message data type, like "uint8" from "uint8[100]".

Returns type unchanged if already a scalar.

Definition at line 766 of file ros1.py.

◆ serialize_message()

serialize_message (   msg)

Returns ROS1 message as a serialized binary.

Definition at line 744 of file ros1.py.

◆ set_message_value()

set_message_value (   obj,
  name,
  value 
)

Sets message or object attribute value.

Definition at line 770 of file ros1.py.

◆ shutdown_node()

shutdown_node ( )

Shuts down live ROS1 node.

Definition at line 505 of file ros1.py.

◆ to_duration()

to_duration (   val)

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

Definition at line 775 of file ros1.py.

◆ to_nsec()

to_nsec (   val)

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

Definition at line 789 of file ros1.py.

◆ to_sec()

to_sec (   val)

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

Definition at line 794 of file ros1.py.

◆ to_sec_nsec()

to_sec_nsec (   val)

Returns value as (seconds, nanoseconds) if value is ROS1 time/duration, else value.

Definition at line 799 of file ros1.py.

◆ to_time()

to_time (   val)

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

Definition at line 804 of file ros1.py.

◆ validate()

validate (   live = False)

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

Parameters
livewhether environment must support launching a ROS node

Definition at line 518 of file ros1.py.

Variable Documentation

◆ Bag

Bag = ROS1Bag

Definition at line 472 of file ros1.py.

◆ BAG_EXTENSIONS

tuple BAG_EXTENSIONS = (".bag", ".bag.active")

Bagfile extensions to seek.

Definition at line 40 of file ros1.py.

◆ genpy_mtx

genpy_mtx = threading.RLock()

Mutex for ensuring exclusive access to genpy generator (genpy.dynamic is not thread-safe)

Definition at line 64 of file ros1.py.

◆ master

master = None

rospy.MasterProxy instance

Definition at line 61 of file ros1.py.

◆ ROS_ALIAS_TYPES

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

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

Definition at line 52 of file ros1.py.

◆ ROS_TIME_CLASSES

dict ROS_TIME_CLASSES = {rospy.Time: "time", rospy.Duration: "duration"}

ROS1 time/duration types mapped to type names.

Definition at line 49 of file ros1.py.

◆ ROS_TIME_TYPES

list ROS_TIME_TYPES = ["time", "duration"]

ROS1 time/duration types.

Definition at line 46 of file ros1.py.

◆ SKIP_EXTENSIONS

tuple SKIP_EXTENSIONS = (".bag.orig.active", )

Bagfile extensions to skip.

Definition at line 43 of file ros1.py.

◆ SLEEP_INTERVAL

float SLEEP_INTERVAL = 0.5

Seconds between checking whether ROS master is available.

Definition at line 58 of file ros1.py.

◆ TYPECLASSES

dict TYPECLASSES = {}

{(typename, typehash): message type class}

Definition at line 55 of file ros1.py.