grepros 1.3.0
grep for ROS bag files and live topics
Loading...
Searching...
No Matches
BaseBag Class Reference
Inheritance diagram for BaseBag:
Inheritance graph

Public Member Functions

 __bool__ (self)
 
 __contains__ (self, key)
 
 __copy__ (self)
 
 __deepcopy__ (self, memo=None)
 
 __enter__ (self)
 
 __exit__ (self, exc_type, exc_value, traceback)
 
 __getitem__ (self, key)
 
 __iter__ (self)
 
 __len__ (self)
 
 __next__ (self)
 
 __nonzero__ (self)
 
 __str__ (self)
 
 close (self)
 
 closed (self)
 
 filename (self)
 
 flush (self)
 
 get_end_time (self)
 
 get_message_class (self, typename, typehash=None)
 
 get_message_count (self, topic_filters=None)
 
 get_message_definition (self, msg_or_type)
 
 get_message_type_hash (self, msg_or_type)
 
 get_qoses (self, topic, typename)
 
 get_start_time (self)
 
 get_topic_info (self, counts=True)
 
 get_type_and_topic_info (self, topic_filters=None)
 
 mode (self)
 
 open (self)
 
 read_messages (self, topics=None, start_time=None, end_time=None, raw=False, **__)
 
 size (self)
 
 stop_on_error (self)
 
 stop_on_error (self, flag)
 
 topics (self)
 
 write (self, topic, msg, t=None, raw=False, **kwargs)
 

Static Public Attributes

 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

ROS bag interface.

%Bag can be used a context manager, is an iterable providing (topic, message, timestamp) tuples
and supporting `len(bag)`; and supports topic-based membership
(`if mytopic in bag`, `for t, m, s in bag[mytopic]`, `len(bag[mytopic])`).

Extra methods and properties compared with rosbag.Bag: Bag.get_message_class(),
Bag.get_message_definition(), Bag.get_message_type_hash(), Bag.get_topic_info();
Bag.closed and Bag.topics.

Definition at line 85 of file api.py.

Member Function Documentation

◆ __bool__()

__bool__ (   self)

Definition at line 139 of file api.py.

◆ __contains__()

__contains__ (   self,
  key 
)
Returns whether bag contains given topic.

Reimplemented in EmbagReader, McapBag, ROS1Bag, and ROS2Bag.

Definition at line 141 of file api.py.

◆ __copy__()

__copy__ (   self)

Definition at line 145 of file api.py.

◆ __deepcopy__()

__deepcopy__ (   self,
  memo = None 
)

Definition at line 147 of file api.py.

◆ __enter__()

__enter__ (   self)
Context manager entry, opens bag if not open.

Definition at line 119 of file api.py.

◆ __exit__()

__exit__ (   self,
  exc_type,
  exc_value,
  traceback 
)
Context manager exit, closes bag.

Definition at line 124 of file api.py.

◆ __getitem__()

__getitem__ (   self,
  key 
)
Returns an iterator yielding messages from the bag in given topic, supporting len().

Definition at line 149 of file api.py.

◆ __iter__()

__iter__ (   self)
Iterates over all messages in the bag.

Definition at line 115 of file api.py.

◆ __len__()

__len__ (   self)
Returns the number of messages in the bag.

Definition at line 128 of file api.py.

◆ __next__()

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

Reimplemented in EmbagReader, McapBag, ROS1Bag, and ROS2Bag.

Definition at line 132 of file api.py.

◆ __nonzero__()

__nonzero__ (   self)

Definition at line 137 of file api.py.

◆ __str__()

__str__ (   self)
Returns informative text for bag, with a full overview of topics and types.

Definition at line 155 of file api.py.

◆ close()

close (   self)
Closes the bag file.

Reimplemented in EmbagReader, McapBag, ROS1Bag, and ROS2Bag.

Definition at line 306 of file api.py.

◆ closed()

closed (   self)
Returns whether file is closed.

Reimplemented in EmbagReader, McapBag, ROS1Bag, and ROS2Bag.

Definition at line 334 of file api.py.

◆ filename()

filename (   self)
Returns bag file path.

Reimplemented in EmbagReader, McapBag, and ROS2Bag.

Definition at line 319 of file api.py.

◆ flush()

flush (   self)
Ensures all changes are written to bag file.

Definition at line 310 of file api.py.

◆ get_end_time()

get_end_time (   self)
Returns the end time of the bag, as UNIX timestamp, or None if bag empty.

Reimplemented in EmbagReader, McapBag, ROS1Bag, and ROS2Bag.

Definition at line 223 of file api.py.

◆ get_message_class()

get_message_class (   self,
  typename,
  typehash = None 
)
Returns ROS message type class, or None if unknown message type for bag.

Reimplemented in EmbagReader, McapBag, ROS1Bag, and ROS2Bag.

Definition at line 255 of file api.py.

◆ get_message_count()

get_message_count (   self,
  topic_filters = None 
)
Returns the number of messages in the bag.

@param   topic_filters  list of topics or a single topic to filter by, if any

Reimplemented in EmbagReader, McapBag, and ROS2Bag.

Definition at line 211 of file api.py.

◆ get_message_definition()

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

Returns None if unknown message type for bag.

Reimplemented in EmbagReader, McapBag, ROS1Bag, and ROS2Bag.

Definition at line 259 of file api.py.

◆ get_message_type_hash()

get_message_type_hash (   self,
  msg_or_type 
)
Returns ROS message type MD5 hash, or None if unknown message type for bag.

Reimplemented in EmbagReader, McapBag, ROS1Bag, and ROS2Bag.

Definition at line 267 of file api.py.

◆ get_qoses()

get_qoses (   self,
  topic,
  typename 
)
Returns topic Quality-of-Service profiles as a list of dicts, or None if not available.

Functional only in ROS2.

Reimplemented in McapBag, and ROS2Bag.

Definition at line 247 of file api.py.

◆ get_start_time()

get_start_time (   self)
Returns the start time of the bag, as UNIX timestamp, or None if bag empty.

Reimplemented in EmbagReader, McapBag, ROS1Bag, and ROS2Bag.

Definition at line 219 of file api.py.

◆ get_topic_info()

get_topic_info (   self,
  counts = True 
)
Returns topic and message type metainfo as {(topic, typename, typehash): count}.

@param   counts  if false, counts may be returned as None if lookup is costly

Reimplemented in EmbagReader, McapBag, ROS1Bag, and ROS2Bag.

Definition at line 227 of file api.py.

◆ get_type_and_topic_info()

get_type_and_topic_info (   self,
  topic_filters = None 
)
Returns thorough metainfo on topic and message types.

@param   topic_filters  list of topics or a single topic to filter returned topics-dict by,
                        if any
@return                 TypesAndTopicsTuple(msg_types, topics) namedtuple,
                        msg_types as dict of {typename: typehash},
                        topics as a dict of {topic: TopicTuple() namedtuple}.

Reimplemented in EmbagReader, McapBag, and ROS2Bag.

Definition at line 235 of file api.py.

◆ mode()

mode (   self)
Returns file open mode.

Reimplemented in EmbagReader, McapBag, and ROS2Bag.

Definition at line 329 of file api.py.

◆ open()

open (   self)
Opens the bag file if not already open.

Reimplemented in EmbagReader, McapBag, ROS1Bag, and ROS2Bag.

Definition at line 302 of file api.py.

◆ read_messages()

read_messages (   self,
  topics = None,
  start_time = None,
  end_time = None,
  raw = False,
**  __ 
)
Yields messages from the bag, optionally filtered by topic and timestamp.

@param   topics      list of topics or a single topic to filter by, if any
@param   start_time  earliest timestamp of message to return, as ROS time or convertible
                     (int/float/duration/datetime/decimal)
@param   end_time    latest timestamp of message to return, as ROS time
                     (int/float/duration/datetime/decimal)
@param   raw         if true, then returned messages are tuples of
                     (typename, bytes, typehash, typeclass)
                     or (typename, bytes, typehash, position, typeclass),
                     depending on file format
@return              BagMessage namedtuples of (topic, message, timestamp as ROS time)

Reimplemented in EmbagReader, McapBag, ROS2Bag, and ROS1Bag.

Definition at line 271 of file api.py.

◆ size()

size (   self)
Returns current file size in bytes.

Reimplemented in EmbagReader, McapBag, and ROS2Bag.

Definition at line 324 of file api.py.

◆ stop_on_error() [1/2]

stop_on_error (   self)
Whether raising read error on unknown message type (ROS2 SQLite .db3 specific).

Definition at line 339 of file api.py.

◆ stop_on_error() [2/2]

stop_on_error (   self,
  flag 
)
Sets whether to raise read error on unknown message type (ROS2 SQLite .db3 specific).

Definition at line 344 of file api.py.

◆ topics()

topics (   self)
Returns the list of topics in bag, in alphabetic order.

Reimplemented in EmbagReader, McapBag, ROS1Bag, and ROS2Bag.

Definition at line 314 of file api.py.

◆ write()

write (   self,
  topic,
  msg,
  t = None,
  raw = False,
**  kwargs 
)
Writes a message to the bag.

@param   topic   name of topic
@param   msg     ROS message
@param   t       message timestamp if not using current wall time, as ROS time
                 or convertible (int/float/duration/datetime/decimal)
@param   raw     if true, `msg` is in raw format, (typename, bytes, typehash, typeclass)
@param   kwargs  ROS version-specific arguments,
                 like `connection_header` for ROS1 or `qoses` for ROS2

Reimplemented in McapBag, ROS1Bag, and ROS2Bag.

Definition at line 288 of file api.py.

Member Data Documentation

◆ BagMessage

BagMessage = collections.namedtuple("BagMessage", "topic message timestamp")
static

Returned from read_messages() as (topic name, ROS message, ROS timestamp object).

Definition at line 99 of file api.py.

◆ MODES

tuple MODES = ("r", "w", "a")
static

Supported opening modes, overridden in subclasses.

Definition at line 110 of file api.py.

◆ next

next
static

Definition at line 135 of file api.py.

◆ STREAMABLE

bool STREAMABLE = True
static

Whether bag supports reading or writing stream objects, overridden in subclasses.

Definition at line 113 of file api.py.

◆ TopicTuple

TopicTuple
static
Initial value:
= collections.namedtuple("TopicTuple", ["msg_type", "message_count",
"connections", "frequency"])

Returned from get_type_and_topic_info() as (typename, message count, connection count, median frequency).

Definition at line 103 of file api.py.

◆ TypesAndTopicsTuple

TypesAndTopicsTuple = collections.namedtuple("TypesAndTopicsTuple", ["msg_types", "topics"])
static

Returned from get_type_and_topic_info() as ({typename: typehash}, {topic name: TopicTuple}).

Definition at line 107 of file api.py.


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