rosbags.rosbag1
Rosbags support for rosbag1 files.
Readers and writers provide access to metadata and raw message content saved in the rosbag1 format.
- Supported versions:
Rosbag1 v2.0
- class rosbags.rosbag1.Reader(path)
Bases:
object
Rosbag 1 version 2.0 reader.
This class is designed for a ROS2 world, it will automatically normalize message type names to be in line with their ROS2 counterparts.
- Parameters:
path (str | Path)
- close()
Close rosbag.
- Return type:
None
- property duration: int
Duration in nanoseconds between earliest and latest messages.
- property end_time: int
Timestamp in nanoseconds after the latest message.
- property message_count: int
Total message count.
- messages(connections=(), start=None, stop=None)
Read messages from bag.
- Parameters:
connections (
Iterable
[Connection
]) – Iterable with connections to filter for. An empty iterable disables filtering on connections.start (
int
|None
) – Yield only messages at or after this timestamp (ns).stop (
int
|None
) – Yield only messages before this timestamp (ns).
- Yields:
Tuples of connection, timestamp (ns), and rawdata.
- Raises:
ReaderError – Bag not open or data corrupt.
- Return type:
Generator
[tuple
[Connection
,int
,bytes
],None
,None
]
- open()
Open rosbag and read metadata.
- Return type:
None
- read_chunk()
Read chunk record header from current position.
- Return type:
Chunk
- read_chunk_info()
Read chunk info record from current position.
- Return type:
ChunkInfo
- read_connection()
Read connection record from current position.
- Return type:
Connection
- read_index_data(pos, indexes)
Read index data from position.
The implementation purposely avoids the generic Header class and its costly string processing.
- Parameters:
pos (
int
) – Seek position.indexes (
dict
[int
,list
[IndexData
]]) – Accumulated index data.
- Raises:
ReaderError – Record unreadable.
- Return type:
None
- property start_time: int
Timestamp in nanoseconds of the earliest message.
- property topics: dict[str, TopicInfo]
Topic information.
- exception rosbags.rosbag1.ReaderError
Bases:
Exception
Reader Error.
- class rosbags.rosbag1.Writer(path)
Bases:
object
Rosbag1 writer.
This class implements writing of rosbag1 files in version 2.0. It should be used as a contextmanager.
- Parameters:
path (Path | str)
- class CompressionFormat(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
IntEnum
Compession formats.
- add_connection(topic, msgtype, *, typestore=None, msgdef=None, md5sum=None, callerid=None, latching=None)
Add a connection.
This function can only be called after opening a bag.
- Parameters:
topic (
str
) – Topic name.msgtype (
str
) – Message type.typestore (
Typestore
|None
) – Typestore.msgdef (
str
|None
) – Message definiton.md5sum (
str
|None
) – Message hash.callerid (
str
|None
) – Caller id.latching (
int
|None
) – Latching information.
- Return type:
Connection
- Returns:
Connection id.
- Raises:
WriterError – Bag not open or identical topic previously registered.
- close()
Close rosbag1 after writing.
Closes open chunks and writes index.
- Return type:
None
- open()
Open rosbag1 for writing.
- Return type:
None
- set_compression(fmt)
Enable compression on rosbag1.
This function has to be called before opening.
- Parameters:
fmt (
CompressionFormat
) – Compressor to use, bz2 or lz4- Raises:
WriterError – Bag already open.
- Return type:
None
- write(connection, timestamp, data)
Write message to rosbag1.
- Parameters:
connection (
Connection
) – Connection to write message to.timestamp (
int
) – Message timestamp (ns).data (
bytes
|memoryview
) – Serialized message data.
- Raises:
WriterError – Bag not open or connection not registered.
- Return type:
None
- write_chunk(chunk)
Write open chunk to file.
- Return type:
None
- Parameters:
chunk (WriteChunk)
- static write_connection(connection, bio)
Write connection record.
- Return type:
None
- Parameters:
connection (Connection)
bio (BinaryIO)
- exception rosbags.rosbag1.WriterError
Bases:
Exception
Writer Error.