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

ROS1 bag reader and writer. More...

Inheritance diagram for ROS1Bag:
Inheritance graph

Public Member Functions

 __init__ (self, *args, **kwargs)
 
 __contains__ (self, key)
 Returns whether bag contains given topic.
 
 __next__ (self)
 Retrieves next message from bag as (topic, message, timestamp).
 
 close (self)
 Closes the bag file.
 
 get_end_time (self)
 Returns the end time of the bag, as UNIX timestamp, or None if bag empty.
 
 get_message_class (self, typename, typehash=None)
 Returns rospy message class for typename, or None if unknown type.
 
 get_message_definition (self, msg_or_type)
 Returns ROS1 message type definition full text from bag, including subtype definitions.
 
 get_message_type_hash (self, msg_or_type)
 Returns ROS1 message type MD5 hash, or None if unknown type.
 
 get_start_time (self)
 Returns the start time of the bag, as UNIX timestamp, or None if bag empty.
 
 get_topic_info (self, *_, **__)
 Returns topic and message type metainfo as {(topic, typename, typehash): count}.
 
 open (self)
 Opens the bag file if not already open.
 
 read_messages (self, topics=None, start_time=None, end_time=None, raw=False, connection_filter=None, **__)
 Yields messages from the bag, optionally filtered by topic, timestamp and connection details.
 
 write (self, topic, msg, t=None, raw=False, connection_header=None, **__)
 Writes a message to the bag.
 
- Public Member Functions inherited from BaseBag
 __bool__ (self)
 
 __contains__ (self, key)
 Returns whether bag contains given topic.
 
 __copy__ (self)
 
 __deepcopy__ (self, memo=None)
 
 __enter__ (self)
 Context manager entry, opens bag if not open.
 
 __exit__ (self, exc_type, exc_value, traceback)
 Context manager exit, closes bag.
 
 __getitem__ (self, key)
 Returns an iterator yielding messages from the bag in given topic, supporting len().
 
 __iter__ (self)
 Iterates over all messages in the bag.
 
 __len__ (self)
 Returns the number of messages in the bag.
 
 __next__ (self)
 Retrieves next message from bag as (topic, message, timestamp).
 
 __nonzero__ (self)
 
 __str__ (self)
 Returns informative text for bag, with a full overview of topics and types.
 
 close (self)
 Closes the bag file.
 
 flush (self)
 Ensures all changes are written to bag file.
 
 get_end_time (self)
 Returns the end time of the bag, as UNIX timestamp, or None if bag empty.
 
 get_message_class (self, typename, typehash=None)
 Returns ROS message type class, or None if unknown message type for bag.
 
 get_message_count (self, topic_filters=None)
 Returns the number of messages in the bag.
 
 get_message_definition (self, msg_or_type)
 Returns ROS message type definition full text, including subtype definitions.
 
 get_message_type_hash (self, msg_or_type)
 Returns ROS message type MD5 hash, or None if unknown message type for bag.
 
 get_qoses (self, topic, typename)
 Returns topic Quality-of-Service profiles as a list of dicts, or None if not available.
 
 get_start_time (self)
 Returns the start time of the bag, as UNIX timestamp, or None if bag empty.
 
 get_topic_info (self, counts=True)
 Returns topic and message type metainfo as {(topic, typename, typehash): count}.
 
 get_type_and_topic_info (self, topic_filters=None)
 Returns thorough metainfo on topic and message types.
 
 open (self)
 Opens the bag file if not already open.
 
 read_messages (self, topics=None, start_time=None, end_time=None, raw=False, **__)
 Yields messages from the bag, optionally filtered by topic and timestamp.
 
 write (self, topic, msg, t=None, raw=False, **kwargs)
 Writes a message to the bag.
 

Static Public Member Functions

 reindex_file (f, progress, *args, **kwargs)
 Reindexes bag, making a backup copy in file directory.
 

Public Attributes

 filename
 
 mode
 

Properties

 closed = property
 Returns whether file is closed.
 
 topics = property
 Returns the list of topics in bag, in alphabetic order.
 
- Properties inherited from BaseBag
 closed = property
 Returns whether file is closed.
 
 filename = property
 Returns bag file path.
 
 mode = property
 Returns file open mode.
 
 size = property
 Returns current file size in bytes.
 
 stop_on_error = property
 Whether raising read error on unknown message type (ROS2 SQLite .db3 specific).
 
 topics = property
 Returns the list of topics in bag, in alphabetic order.
 

Additional Inherited Members

- Static Public Attributes inherited from BaseBag
 BagMessage = collections.namedtuple("BagMessage", "topic message timestamp")
 Returned from read_messages() as (topic name, ROS message, ROS timestamp object).
 
tuple MODES = ("r", "w", "a")
 Supported opening modes, overridden in subclasses.
 
 next
 
bool STREAMABLE = True
 Whether bag supports reading or writing stream objects, overridden in subclasses.
 
 TopicTuple
 Returned from get_type_and_topic_info() as (typename, message count, connection count, median frequency).
 
 TypesAndTopicsTuple = collections.namedtuple("TypesAndTopicsTuple", ["msg_types", "topics"])
 Returned from get_type_and_topic_info() as ({typename: typehash}, {topic name: TopicTuple}).
 

Detailed Description

ROS1 bag reader and writer.

Extends rosbag.Bag with more conveniences, smooths over the rosbag bug of ignoring topic and time filters in format v1.2, and smooths over the rosbag bug of yielding messages of wrong type, if message types in different topics have different packages but identical fields and hashes.

Does **not** smooth over the rosbag bug of writing different types to one topic.

rosbag does allow writing messages of different types to one topic, just like live ROS topics can have multiple message types published to one topic. And their serialized bytes will actually be in the bag, but rosbag will only register the first type for this topic (unless it is explicitly given another connection header with metadata on the other type).

All messages yielded will be deserialized by rosbag as that first type, and whether reading will raise an exception or not depends on whether the other type has enough bytes to be deserialized as that first type.

Definition at line 87 of file ros1.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ (   self,
args,
**  kwargs 
)
Parameters
fbag file path, or a stream object
modemode to open bag in, defaults to "r" (read mode)
reindexif true and bag is unindexed, make a copy of the file (unless unindexed format) and reindex original
progressshow progress bar with reindexing status
kwargsadditional keyword arguments for rosbag.Bag, like compression

Definition at line 117 of file ros1.py.

Member Function Documentation

◆ __contains__()

__contains__ (   self,
  key 
)

Returns whether bag contains given topic.

Reimplemented from BaseBag.

Definition at line 303 of file ros1.py.

◆ __next__()

__next__ (   self)

Retrieves next message from bag as (topic, message, timestamp).

Reimplemented from BaseBag.

Definition at line 308 of file ros1.py.

◆ close()

close (   self)

Closes the bag file.

Reimplemented from BaseBag.

Definition at line 295 of file ros1.py.

◆ get_end_time()

get_end_time (   self)

Returns the end time of the bag, as UNIX timestamp, or None if bag empty.

Reimplemented from BaseBag.

Definition at line 192 of file ros1.py.

◆ get_message_class()

get_message_class (   self,
  typename,
  typehash = None 
)

Returns rospy message class for typename, or None if unknown type.

Generates class dynamically if not already generated.

Parameters
typehashmessage type definition hash, if any

Reimplemented from BaseBag.

Definition at line 165 of file ros1.py.

◆ get_message_definition()

get_message_definition (   self,
  msg_or_type 
)

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

Reimplemented from BaseBag.

Definition at line 150 of file ros1.py.

◆ get_message_type_hash()

get_message_type_hash (   self,
  msg_or_type 
)

Returns ROS1 message type MD5 hash, or None if unknown type.

Reimplemented from BaseBag.

Definition at line 175 of file ros1.py.

◆ get_start_time()

get_start_time (   self)

Returns the start time of the bag, as UNIX timestamp, or None if bag empty.

Reimplemented from BaseBag.

Definition at line 186 of file ros1.py.

◆ get_topic_info()

get_topic_info (   self,
_,
**  __ 
)

Returns topic and message type metainfo as {(topic, typename, typehash): count}.

Reimplemented from BaseBag.

Definition at line 198 of file ros1.py.

◆ open()

open (   self)

Opens the bag file if not already open.

Reimplemented from BaseBag.

Definition at line 289 of file ros1.py.

◆ read_messages()

read_messages (   self,
  topics = None,
  start_time = None,
  end_time = None,
  raw = False,
  connection_filter = None,
**  __ 
)

Yields messages from the bag, optionally filtered by topic, timestamp and connection details.

Parameters
topicslist of topics or a single topic. If an empty list is given, all topics will be read.
start_timeearliest timestamp of messages to return, as ROS time or convertible (int/float/duration/datetime/decimal)
end_timelatest timestamp of messages to return, as ROS time or convertible (int/float/duration/datetime/decimal)
connection_filterfunction to filter connections to include
rawif true, then returned messages are tuples of
(typename, bytes, typehash, typeclass)
or (typename, bytes, typehash, position, typeclass), depending on file format
Returns
BagMessage namedtuples of (topic, message, timestamp as rospy.Time)

Reimplemented from BaseBag.

Definition at line 221 of file ros1.py.

◆ reindex_file()

reindex_file (   f,
  progress,
args,
**  kwargs 
)
static

Reindexes bag, making a backup copy in file directory.

Parameters
progressshow progress bar for reindexing status

Definition at line 411 of file ros1.py.

◆ write()

write (   self,
  topic,
  msg,
  t = None,
  raw = False,
  connection_header = None,
**  __ 
)

Writes a message to the bag.

Populates connection header if topic already in bag but with a different message type.

Parameters
topicname of topic
msgROS1 message
tmessage timestamp if not using current wall time, as ROS time or convertible (int/float/duration/datetime/decimal)
rawif true, msg is in raw format,
(typename, bytes, typehash, typeclass)
connection_headercustom connection record for topic, as {"topic", "type", "md5sum", "message_definition"}

Reimplemented from BaseBag.

Definition at line 282 of file ros1.py.

Member Data Documentation

◆ filename

filename

Definition at line 292 of file ros1.py.

◆ mode

mode

Definition at line 292 of file ros1.py.

Property Documentation

◆ closed

closed = property
static

Returns whether file is closed.

Definition at line 325 of file ros1.py.

◆ topics

topics = property
static

Returns the list of topics in bag, in alphabetic order.

Definition at line 317 of file ros1.py.


The documentation for this class was generated from the following file: