Convert with a Custom Typestore

When converting ROS bag files, the converter requires access to all relevant message definitions. If the source bag files include all necessary definitions, no further action is needed, the converter will automatically detect and use them. However, if any definitions are missing, you must supply them using a typestore.

Creating a Typestore Module

The rosbags-convert tool supports loading a typestore from a Python module. The easiest way to create a suitable typestore is to start with an existing one and extend it with any additional message types you need.

"""Example: Creating a Custom Typestore.

This module defines a global variable ``nmea_typestore``, which extends
the default Jazzy typestore by adding one additional message type.

If this file is saved as ``my_typestores.py``, the fully qualified
reference to the typestore is ``my_typestores:nmea_typestore``.

"""

from __future__ import annotations

from rosbags.typesys import Stores, get_typestore
from rosbags.typesys.msg import get_types_from_msg

NMEA_SENTENCE_MSG = """
std_msgs/msg/Header header
string sentence
"""

nmea_typestore = get_typestore(Stores.ROS2_JAZZY)
nmea_typestore.register(get_types_from_msg(NMEA_SENTENCE_MSG, 'nmea_msgs/msg/Sentence'))

Converting with a Typestore

To use your custom typestore during conversion, pass it to rosbags-convert via the –src-typestore-ref option.

rosbags-convert \
  --src-typestore-ref my_typestores:nmea_typestore \
  --src rosbag_without_types \
  --dst rosbag_with_types

Note

Ensure Python can locate your typestore module. If you encounter ModuleNotFoundError, verify that the directory containing your typestore is included in the PYTHONPATH environment variable.