rosros 0.2.5
Simple unified interface to ROS1 / ROS2 Python API
Loading...
Searching...
No Matches
rosros.ros2.Bag Class Reference

ROS2 bag interface, partially mimicking rosbag.Bag. More...

Public Member Functions

 __init__ (self, filename, mode="a", *_, **__)
 
 __enter__ (self)
 Context manager entry.
 
 __exit__ (self, exc_type, exc_value, traceback)
 Context manager exit, closes bag.
 
 __iter__ (self)
 Iterates over all messages in the bag.
 
 __str__ (self)
 Returns informative text for bag, with a full overview of topics and types.
 
 close (self)
 Closes the bag file.
 
 flush (self)
 Does nothing (ROS1 API conformity stand-in).
 
 get_end_time (self)
 Returns the end time of the bag, as UNIX timestamp.
 
 get_message_class (self, typename, typehash=None)
 Returns ROS2 message type class.
 
 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.
 
 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.
 
 get_topic_info (self, counts=False)
 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.
 
 read_messages (self, topics=None, start_time=None, end_time=None, raw=False, *_, **__)
 Yields messages from the bag in chronological order.
 
 write (self, topic, msg, t=None, raw=False, qoses=None, **__)
 Writes a message to the bag.
 

Public Attributes

 filename
 Bagfile path.
 

Static Public Attributes

 BagMessage = collections.namedtuple("BagMessage", "topic message timestamp")
 Returned from read_messages() as (topic name, ROS message, rclpy.Time).
 
str CREATE_SQL
 ROS2 bag SQLite schema.
 
str EXTENSION = ".db3"
 Default extension for bag files.
 
 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}).
 

Protected Member Functions

 _has_table (self, name)
 Returns whether specified table exists in database.
 

Protected Attributes

 _counts
 
 _db
 
 _dbtopics
 
 _mode
 
 _qoses
 
 _types
 

Properties

 mode = property
 Returns file open mode.
 
 size = property
 Returns current file size in bytes (including journaling files).
 

Detailed Description

ROS2 bag interface, partially mimicking rosbag.Bag.

Definition at line 153 of file ros2.py.

Constructor & Destructor Documentation

◆ __init__()

rosros.ros2.Bag.__init__ (   self,
  filename,
  mode = "a",
_,
**  __ 
)
Parameters
filenamebag file path to open
modemode to open file in, one of "r", "w", "a"; file will be overwritten if "w", and unwriteable if "r"

Definition at line 198 of file ros2.py.

Member Function Documentation

◆ __enter__()

rosros.ros2.Bag.__enter__ (   self)

Context manager entry.

Definition at line 221 of file ros2.py.

◆ __exit__()

rosros.ros2.Bag.__exit__ (   self,
  exc_type,
  exc_value,
  traceback 
)

Context manager exit, closes bag.

Definition at line 226 of file ros2.py.

◆ __iter__()

rosros.ros2.Bag.__iter__ (   self)

Iterates over all messages in the bag.

Definition at line 216 of file ros2.py.

◆ __str__()

rosros.ros2.Bag.__str__ (   self)

Returns informative text for bag, with a full overview of topics and types.

Definition at line 516 of file ros2.py.

◆ _has_table()

rosros.ros2.Bag._has_table (   self,
  name 
)
protected

Returns whether specified table exists in database.

Definition at line 511 of file ros2.py.

◆ close()

rosros.ros2.Bag.close (   self)

Closes the bag file.

Definition at line 477 of file ros2.py.

◆ flush()

rosros.ros2.Bag.flush (   self)

Does nothing (ROS1 API conformity stand-in).

Definition at line 484 of file ros2.py.

◆ get_end_time()

rosros.ros2.Bag.get_end_time (   self)

Returns the end time of the bag, as UNIX timestamp.

Definition at line 258 of file ros2.py.

◆ get_message_class()

rosros.ros2.Bag.get_message_class (   self,
  typename,
  typehash = None 
)

Returns ROS2 message type class.

Definition at line 347 of file ros2.py.

◆ get_message_count()

rosros.ros2.Bag.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 at all

Definition at line 236 of file ros2.py.

◆ get_message_definition()

rosros.ros2.Bag.get_message_definition (   self,
  msg_or_type 
)

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

Definition at line 352 of file ros2.py.

◆ get_message_type_hash()

rosros.ros2.Bag.get_message_type_hash (   self,
  msg_or_type 
)

Returns ROS2 message type MD5 hash.

Definition at line 357 of file ros2.py.

◆ get_qoses()

rosros.ros2.Bag.get_qoses (   self,
  topic,
  typename 
)

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

Definition at line 333 of file ros2.py.

◆ get_start_time()

rosros.ros2.Bag.get_start_time (   self)

Returns the start time of the bag, as UNIX timestamp.

Definition at line 248 of file ros2.py.

◆ get_topic_info()

rosros.ros2.Bag.get_topic_info (   self,
  counts = False 
)

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

Parameters
countswhether to return actual message counts instead of None

Definition at line 273 of file ros2.py.

◆ get_type_and_topic_info()

rosros.ros2.Bag.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 by, if at all
Returns
TypesAndTopicsTuple(msg_types, topics) namedtuple, msg_types as dict of {typename: typehash}, topics as a dict of {topic: TopicTuple() namedtuple}.

Definition at line 306 of file ros2.py.

◆ read_messages()

rosros.ros2.Bag.read_messages (   self,
  topics = None,
  start_time = None,
  end_time = None,
  raw = False,
_,
**  __ 
)

Yields messages from the bag in chronological order.

Parameters
topicslist of topics or a single topic to filter by, if at all
start_timeearliest timestamp of message to return, as `rclpy.Time` or convertible
(int/float/duration/datetime/decimal/builtin_interfaces.Time)
end_timelatest timestamp of message to return, as `rclpy.Time` or convertible
(int/float/duration/datetime/decimal/builtin_interfaces.Time)
rawif True, then returned messages are tuples of
(typename, bytes, typehash, typeclass)
Returns
generator of BagMessage(topic, message, rclpy.time.Time) namedtuples

Definition at line 381 of file ros2.py.

◆ write()

rosros.ros2.Bag.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 current wall time, as `rclpy.Time` or convertible
(int/float/duration/datetime/decimal/builtin_interfaces.Time)
rawif true, msg is expected as a tuple starting with
(typename, bytes, typehash, )
qoseslist of Quality-of-Service profile dictionaries for topic, if any; inserted to topics-table only if first message for topic in bag

Definition at line 444 of file ros2.py.

Member Data Documentation

◆ _counts

rosros.ros2.Bag._counts
protected

Definition at line 203 of file ros2.py.

◆ _db

rosros.ros2.Bag._db
protected

Definition at line 199 of file ros2.py.

◆ _dbtopics

rosros.ros2.Bag._dbtopics
protected

Definition at line 201 of file ros2.py.

◆ _mode

rosros.ros2.Bag._mode
protected

Definition at line 200 of file ros2.py.

◆ _qoses

rosros.ros2.Bag._qoses
protected

Definition at line 204 of file ros2.py.

◆ _types

rosros.ros2.Bag._types
protected

Definition at line 202 of file ros2.py.

◆ BagMessage

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

Returned from read_messages() as (topic name, ROS message, rclpy.Time).

Definition at line 160 of file ros2.py.

◆ CREATE_SQL

str rosros.ros2.Bag.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 171 of file ros2.py.

◆ EXTENSION

str rosros.ros2.Bag.EXTENSION = ".db3"
static

Default extension for bag files.

Definition at line 157 of file ros2.py.

◆ filename

rosros.ros2.Bag.filename

Bagfile path.

Definition at line 207 of file ros2.py.

◆ TopicTuple

rosros.ros2.Bag.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 164 of file ros2.py.

◆ TypesAndTopicsTuple

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

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

Definition at line 168 of file ros2.py.

Property Documentation

◆ mode

rosros.ros2.Bag.mode = property
static

Returns file open mode.

Definition at line 502 of file ros2.py.

◆ size

rosros.ros2.Bag.size = property
static

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

Definition at line 490 of file ros2.py.


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