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

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

Inheritance diagram for ROS2Bag:
Inheritance graph

Public Member Functions

 __init__ (self, filename, mode="a", *_, **__)
 
 __contains__ (self, key)
 Returns whether bag contains given topic.
 
 __next__ (self)
 Retrieves next message from bag as (topic, message, timestamp).
 
 autodetect (cls, f)
 Returns whether file is recognizable as SQLite format.
 
 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 ROS2 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 ROS2 message type definition full text, including subtype definitions.
 
 get_message_type_hash (self, msg_or_type)
 Returns ROS2 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, ensure_types=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, qoses=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.
 

Public Attributes

 CREATE_SQL
 

Static Public Attributes

str CREATE_SQL
 ROS2 bag SQLite schema.
 
str SQLITE_MAGIC = b"SQLite format 3\x00"
 SQLite file header magic start bytes.
 
bool STREAMABLE = False
 Whether bag supports reading or writing stream objects, overridden in subclasses.
 
- 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}).
 

Properties

 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 (including journaling files).
 
 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.
 

Detailed Description

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

Definition at line 91 of file ros2.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ (   self,
  filename,
  mode = "a",
_,
**  __ 
)
Parameters
filenamebag file path to open
modefile will be overwritten if "w"

Definition at line 129 of file ros2.py.

Member Function Documentation

◆ __contains__()

__contains__ (   self,
  key 
)

Returns whether bag contains given topic.

Reimplemented from BaseBag.

Definition at line 466 of file ros2.py.

◆ __next__()

__next__ (   self)

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

Reimplemented from BaseBag.

Definition at line 471 of file ros2.py.

◆ autodetect()

autodetect (   cls,
  f 
)

Returns whether file is recognizable as SQLite format.

Definition at line 550 of file ros2.py.

◆ close()

close (   self)

Closes the bag file.

Reimplemented from BaseBag.

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

◆ get_message_class()

get_message_class (   self,
  typename,
  typehash = None 
)

Returns ROS2 message type class, or None if unknown message type for bag.

Reimplemented from BaseBag.

Definition at line 255 of file ros2.py.

◆ get_message_count()

get_message_count (   self,
  topic_filters = None 
)

Returns the number of messages in the bag.

Parameters
topic_filterslist of topics or a single topic to filter by, if any

Reimplemented from BaseBag.

Definition at line 152 of file ros2.py.

◆ get_message_definition()

get_message_definition (   self,
  msg_or_type 
)

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

Returns None if unknown message type for bag.

Reimplemented from BaseBag.

Definition at line 271 of file ros2.py.

◆ get_message_type_hash()

get_message_type_hash (   self,
  msg_or_type 
)

Returns ROS2 message type MD5 hash, or None if unknown message type for bag.

Reimplemented from BaseBag.

Definition at line 279 of file ros2.py.

◆ get_qoses()

get_qoses (   self,
  topic,
  typename 
)

Returns topic Quality-of-Service profiles as a list of dicts, or None if not available.

Reimplemented from BaseBag.

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

◆ get_topic_info()

get_topic_info (   self,
  counts = True,
  ensure_types = True 
)

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

Can skip retrieving message counts, as this requires a full table scan. Can skip looking up message type classes, as those might be unavailable in ROS2 environment.

Parameters
countswhether to return actual message counts instead of None
ensure_typeswhether to look up type classes instead of returning typehash as None

Reimplemented from BaseBag.

Definition at line 194 of file ros2.py.

◆ get_type_and_topic_info()

get_type_and_topic_info (   self,
  topic_filters = None 
)

Returns thorough metainfo on topic and message types.

Parameters
topic_filterslist of topics or a single topic to filter returned topics-dict by, if any
Returns
TypesAndTopicsTuple(msg_types, topics) namedtuple, msg_types as dict of {typename: typehash}, topics as a dict of {topic: TopicTuple() namedtuple}.

Reimplemented from BaseBag.

Definition at line 209 of file ros2.py.

◆ open()

open (   self)

Opens the bag file if not already open.

Reimplemented from BaseBag.

Definition at line 408 of file ros2.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.

Parameters
topicslist of topics or a single topic to filter by, if any
start_timeearliest timestamp of message to return, as ROS time or convertible
(int/float/duration/datetime/decimal)
end_timelatest timestamp of message to return, as ROS time or convertible
(int/float/duration/datetime/decimal)
rawif True, then returned messages are tuples of (typename, bytes, typehash, typeclass). If message type unavailable, returns None for hash and class.
Returns
BagMessage namedtuples of (topic, message, timestamp as rclpy.time.Time)

Reimplemented from BaseBag.

Definition at line 303 of file ros2.py.

◆ write()

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

Writes a message to the bag.

Parameters
topicname of topic
msgROS2 message
tmessage timestamp if not using wall time, as ROS time or convertible
(int/float/duration/datetime/decimal)
qosestopic Quality-of-Service settings, if any, as a list of dicts

Reimplemented from BaseBag.

Definition at line 373 of file ros2.py.

Member Data Documentation

◆ CREATE_SQL [1/2]

str CREATE_SQL
static
Initial value:
= """
CREATE TABLE IF NOT EXISTS messages (
id INTEGER PRIMARY KEY,
topic_id INTEGER NOT NULL,
timestamp INTEGER NOT NULL,
data BLOB NOT NULL
);
CREATE TABLE IF NOT EXISTS topics (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
type TEXT NOT NULL,
serialization_format TEXT NOT NULL,
offered_qos_profiles TEXT NOT NULL
);
CREATE INDEX IF NOT EXISTS timestamp_idx ON messages (timestamp ASC);
PRAGMA journal_mode=WAL;
PRAGMA synchronous=NORMAL;
"""

ROS2 bag SQLite schema.

Definition at line 98 of file ros2.py.

◆ CREATE_SQL [2/2]

CREATE_SQL

Definition at line 492 of file ros2.py.

◆ SQLITE_MAGIC

str SQLITE_MAGIC = b"SQLite format 3\x00"
static

SQLite file header magic start bytes.

Definition at line 121 of file ros2.py.

◆ STREAMABLE

bool STREAMABLE = False
static

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

Definition at line 95 of file ros2.py.

Property Documentation

◆ closed

closed = property
static

Returns whether file is closed.

Definition at line 424 of file ros2.py.

◆ filename

filename = property
static

Returns bag file path.

Definition at line 440 of file ros2.py.

◆ mode

mode = property
static

Returns file open mode.

Definition at line 460 of file ros2.py.

◆ size

size = property
static

Returns current file size in bytes (including journaling files).

Definition at line 448 of file ros2.py.

◆ topics

topics = property
static

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

Definition at line 432 of file ros2.py.


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