mcap_ros2.reader module¶
the mcap_ros1.reader
module is deprecated. For similar functionality,
instantiate the mcap.reader.McapReader
with a
mcap_ros1.decoder.DecoderFactory
instance, eg:
>>> from mcap.reader import make_reader
>>> from mcap_ros1.decoder import DecoderFactory
>>> reader = make_reader(open("ros1.mcap", "rb"), decoder_factories=[DecoderFactory()])
>>> for schema_, channel_, message_, ros1_msg in reader.iter_decoded_messages():
>>> print(ros1_msg)
String(data="hello")
String(data="goodbye")
- class mcap_ros2.reader.McapROS2Message(ros_msg: Any, message: Message, channel: Channel, schema: Schema)[source]¶
Bases:
object
Contains a single ROS2 message and associated metadata.
- Variables:
ros_msg – the decoded ROS2 message.
sequence_count – the message sequence count if included in the MCAP, or 0 otherwise.
log_time_ns – the time this message was logged by the recorder, as a POSIX nanosecond timestamp.
log_time_ns – the time this message was published, as a POSIX nanosecond timestamp.
channel – the MCAP Channel record referenced by the Message record
schema – the MCAP Schema record referenced by the Channel record
- channel¶
- property log_time: datetime¶
Return the timestamp representing when this message was logged by the recorder.
- log_time_ns: int¶
- property publish_time: datetime¶
Return the timestamp representing when this message was published.
- publish_time_ns: int¶
- ros_msg¶
- schema¶
- sequence_count: int¶
- mcap_ros2.reader.read_ros2_messages(source: str | bytes | PathLike[str] | McapReader | IO[bytes], topics: Iterable[str] | None = None, start_time: int | datetime | None = None, end_time: int | datetime | None = None, log_time_order: bool = True, reverse: bool = False) Iterator[McapROS2Message] [source]¶
High-level generator that reads ROS2 messages from an MCAP file.
- Parameters:
source – some source of MCAP file data. Supply a stream of bytes, an McapReader instance, or the path to a valid MCAP file in the filesystem.
topics – an optional list of topics to read from the MCAP file.
start_time – if not None, messages logged before this time will not be included.
end_time – if not None, messages logged at this timestamp or after will not be included.
log_time_order – if True, messages will be yielded in ascending log time order. If False, messages will be yielded in the order they appear in the MCAP file.
reverse – if both
log_time_order
andreverse
are True, messages will be yielded in descending log time order.
- Yields:
an McapROS1Message instance for each ROS1 message in the MCAP file.
Note
this generator assumes the source MCAP conforms to the ros2 MCAP profile. If you need to decode ROS2 messages from a file containing other encodings, use the
mcap.reader.McapReader.iter_messages()
function to iterate through Message records in your MCAP, and decode the ROS2 messages with themcap_ros2.decoder.Decoder
class.