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

ROS1 bag reader and writer. More...

Inheritance diagram for rosros.ros1.Bag:
Inheritance graph

Public Member Functions

 __init__ (self, f, mode="r", compression=rosbag.Compression.NONE, chunk_threshold=768 *1024, allow_unindexed=False, options=None, skip_index=False)
 Opens a ROS1 bag file.
 
 get_message_class (self, typename, typehash=None)
 Returns ROS1 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.
 
 get_qoses (self, topic, typename)
 Returns None (ROS2 bag API conformity stand-in).
 
 get_topic_info (self, *_, **__)
 Returns topic and message type metainfo as {(topic, typename, typehash): count}.
 
 read_messages (self, topics=None, start_time=None, end_time=None, connection_filter=None, raw=False)
 Yields messages from the bag in chronological order.
 
 write (self, topic, msg, t=None, raw=False, connection_header=None, **__)
 Writes a message to the bag.
 

Static Public Member Functions

 reindex_file (f)
 Reindexes bag file on disk.
 

Static Public Attributes

str EXTENSION = ".bag"
 Default extension for bag files.
 

Detailed Description

ROS1 bag reader and writer.

Extends `rosbag.Bag` with more conveniences, 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 126 of file ros1.py.

Constructor & Destructor Documentation

◆ __init__()

rosros.ros1.Bag.__init__ (   self,
  f,
  mode = "r",
  compression = rosbag.Compression.NONE,
  chunk_threshold = 768 * 1024,
  allow_unindexed = False,
  options = None,
  skip_index = False 
)

Opens a ROS1 bag file.

Parameters
fbag file path to open
modemode to open bag in, one of "r", "w", "a"
compressionbag write compression mode, one of Compression
chunk_thresholdminimum number of uncompressed bytes per chunk to write
allow_unindexedallow opening unindexed bags
optionsoptional dict with values for "compression" and "chunk_threshold"
skip_indexskip reading the connection index records on open

Definition at line 161 of file ros1.py.

Member Function Documentation

◆ get_message_class()

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

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

Generates class dynamically if not already generated.

Parameters
typehashmessage type definition hash, if any

Definition at line 185 of file ros1.py.

◆ get_message_definition()

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

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

Definition at line 170 of file ros1.py.

◆ get_message_type_hash()

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

Returns ROS1 message type MD5 hash.

Definition at line 195 of file ros1.py.

◆ get_qoses()

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

Returns None (ROS2 bag API conformity stand-in).

Definition at line 206 of file ros1.py.

◆ get_topic_info()

rosros.ros1.Bag.get_topic_info (   self,
_,
**  __ 
)

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

Definition at line 211 of file ros1.py.

◆ read_messages()

rosros.ros1.Bag.read_messages (   self,
  topics = None,
  start_time = None,
  end_time = None,
  connection_filter = None,
  raw = False 
)

Yields messages from the bag in chronological order.

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 `rospy.Time` or convertible
(int/float/duration/datetime/decimal)
end_timelatest timestamp of messages to return as `rospy.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, md5sum, typeclass)
or (typename, bytes, md5sum, position, typeclass), depending on file format version
Returns
generator of BagMessage(topic, message, timestamp) namedtuples

Definition at line 239 of file ros1.py.

◆ reindex_file()

rosros.ros1.Bag.reindex_file (   f)
static

Reindexes bag file on disk.

Makes a temporary copy in file directory.

Definition at line 341 of file ros1.py.

◆ write()

rosros.ros1.Bag.write (   self,
  topic,
  msg,
  t = None,
  raw = False,
  connection_header = None,
**  __ 
)

Writes a message to the bag.

Parameters
topicname of topic
msgROS message to write, or tuple if raw
tmessage timestamp if not using current wall time, as `rospy.Time` or convertible
(int/float/duration/datetime/decimal)
rawif true, msg is expected as (typename, bytes, typehash, typeclass) or (typename, bytes, typehash, position, typeclass)
connection_headercustom connection header dict if any, as {"topic", "type", "md5sum", "message_definition"}

Definition at line 280 of file ros1.py.

Member Data Documentation

◆ EXTENSION

str rosros.ros1.Bag.EXTENSION = ".bag"
static

Default extension for bag files.

Definition at line 129 of file ros1.py.


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