mcap_ros1.reader module

the mcap_ros1.reader module provides high-level ROS1 message reading capability. For more low-level control, consider using the underlying mcap_ros1.decoder.Decoder and mcap.reader.McapReader objects directly.

class mcap_ros1.reader.McapROS1Message(ros_msg: Any, message: Message, channel: Channel, schema: Schema)[source]

Bases: object

Contains a single ROS message and associated metadata.

Variables:
  • ros_msg – the decoded ROS1 message.

  • sequence_count – the message sequence count if included in the MCAP, or 0 otherwise.

  • topic – the topic that the message was published on.

  • channel_metadata – the metadata associated with this ROS1 topic, if any.

  • 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: Channel
channel_metadata: Dict[str, str]
property log_time: datetime

The timestamp representing when this message was logged by the recorder.

log_time_ns: int
property publish_time: datetime

The timestamp representing when this message was published.

publish_time_ns: int
ros_msg: Any
schema: Schema
sequence_count: int
topic: str
mcap_ros1.reader.read_ros1_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[McapROS1Message][source]

High-level generator that reads ROS1 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 and reverse 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 ros1 MCAP profile. If you need to decode ROS1 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 ROS1 messages with the mcap_ros1.decoder.Decoder class.