Skip to content

nav_msgs Adapters

mosaicolabs.ros_bridge.adapters.nav_msgs

OdometryAdapter

Bases: ROSAdapterBase[MotionState]

Adapter for translating ROS Odometry messages to Mosaico MotionState.

Supported ROS Types:

Example
ros_msg = ROSMessage(
    timestamp=17000,
    topic="/odometry",
    msg_type="nav_msgs/msg/Odometry",
    data = {
        "header": {"frame_id": "map", "stamp": {"sec": 17000, "nanosec": 0}},
        "pose": {
            "position": {"x": 1.0, "y": 2.0, "z": 0.0},
            "orientation": {"x": 0, "y": 0, "z": 0, "w": 1}
        },
        "twist": {
            "linear": {"x": 0.0, "y": 0.0, "z": 0.0},
            "angular": {"x": 0.0, "y": 0.0, "z": 0.0}
        },
        "child_frame_id": "base_link"
    }
)
# Automatically resolves to a flat Mosaico MotionState with attached metadata
mosaico_odometry = OdometryAdapter.translate(ros_msg)

translate classmethod

translate(ros_msg, **kwargs)

Translates a ROS message into a Mosaico Message.

Returns:

Name Type Description
Message Message

The translated message containing a MotionState object.

Raises:

Type Description
Exception

Wraps any translation error with context (topic name, timestamp).

from_dict classmethod

from_dict(ros_data)

Parses a dictionary to extract a MotionState object.

Example
ros_data = {
    "header": {"frame_id": "map", "stamp": {"sec": 17000, "nanosec": 0}},
    "pose": {
        "position": {"x": 1.0, "y": 2.0, "z": 0.0},
        "orientation": {"x": 0, "y": 0, "z": 0, "w": 1}
    },
    "twist": {
        "linear": {"x": 0.0, "y": 0.0, "z": 0.0},
        "angular": {"x": 0.0, "y": 0.0, "z": 0.0}
    },
    "child_frame_id": "base_link"
}
# Automatically resolves to a flat Mosaico MotionState with attached metadata
mosaico_odometry = OdometryAdapter.from_dict(ros_data)

Parameters:

Name Type Description Default
ros_data dict

The raw dictionary from the ROS message.

required

Returns:

Name Type Description
MotionState MotionState

The constructed Mosaico MotionState object.

Raises:

Type Description
ValueError

If a required key is missing from ros_data.

to_ros classmethod

to_ros(mosaico_data, typestore, ros_msg_type=None)

Converts a Mosaico MotionState (or a Message wrapping one) into a nav_msgs/msg/Odometry message.

Parameters:

Name Type Description Default
mosaico_data Union[Message, MotionState]

A Message wrapping a MotionState instance, or a raw MotionState.

required
typestore Typestore

The rosbags typestore for target type resolution.

required
ros_msg_type Optional[str]

Override for the output ROS type. Only nav_msgs/msg/Odometry is supported.

None

Returns:

Name Type Description
MsgType MsgType

A nav_msgs/msg/Odometry instance, or raises an error if:

  • the ros_msg_type is unsupported by adapter (TypeError)
  • the ros_msg_type or default type are unsupported by typestore (TypeError)
  • the ros_msg_type or default type are supported but translation is not implemented (NotImplementedError)

schema_metadata classmethod

schema_metadata(typestore, ros_msg_type, ros_version)

Extract the ROS message specific schema metadata, if any.

Parameters:

Name Type Description Default
typestore Typestore

The rosbags typestore for target type resolution.

required
ros_msg_type str

The ROS message type to extract metadata for.

required
ros_version int

The ROS version (1 or 2) to consider for metadata extraction.

required

Returns:

Type Description
Optional[dict]

Optional[dict]: A dictionary containing the schema metadata, or None if not applicable.

ros_msg_type abstractmethod classmethod

ros_msg_type()

Returns the specific ROS message type handled by this adapter.

is_rosmsg_type_valid classmethod

is_rosmsg_type_valid(type_to_validate)

Checks whether a given ROS message type string is handled by this adapter.

Parameters:

Name Type Description Default
type_to_validate str

The full ROS message type string to check (e.g., "sensor_msgs/msg/Imu").

required

Returns:

Name Type Description
bool bool

True if the adapter supports this type, False otherwise.

unpack_mosaico_msg classmethod

unpack_mosaico_msg(mosaico_msg)

Extracts the typed Mosaico payload and its Header (if present) from a wrapped or bare message.

Handles two input cases:

  • Message wrapper: the typed data is extracted via get_data().
  • Raw ontology instance: returned as-is with

the Header is extracted from the ontology (if supported), otherwise an default Header (empty frame_id and zero Time) is returned.

Parameters:

Name Type Description Default
mosaico_msg Union[Message, T]

Either a Message envelope or a raw instance of cls.__mosaico_ontology_type__.

required

Returns:

Type Description
T

tuple[T, Header]: A (data, header) tuple where data is the typed ontology object and

Header

header is the corresponding Header, or a default Header (empty frame_id and

tuple[T, Header]

zero Time) if not present.

Raises:

Type Description
TypeError

If mosaico_msg is neither a Message nor an instance of the expected ontology type.

ontology_data_type classmethod

ontology_data_type()

Returns the Ontology class type associated with this adapter.

RobotPathAdapter

Bases: ROSAdapterBase[RobotPath]

Adapter for translating ROS Path messages to Mosaico RobotPath.

Supported ROS Types:

Example
ros_msg = ROSMessage(
    timestamp=17000,
    topic="/path",
    msg_type="nav_msgs/msg/Path",
    data = {
        "header": {"frame_id": "map", "stamp": {"sec": 17000, "nanosec": 0}},
        "poses":[
            {
                "header": {"frame_id": "base_link", "stamp": {"sec": 17000, "nanosec": 0}},
                "position": {"x": 1.0, "y": 2.0, "z": 0.0},
                "orientation": {"x": 0, "y": 0, "z": 0, "w": 1}
            },
            {
                "header": {"frame_id": "base_link", "stamp": {"sec": 18000, "nanosec": 0}},
                "position": {"x": 2.0, "y": 3.0, "z": 0.0},
                "orientation": {"x": 0, "y": 0, "z": 0, "w": 1}
            },
            {
                "header": {"frame_id": "base_link", "stamp": {"sec": 19000, "nanosec": 0}},
                "position": {"x": 3.0, "y": 4.0, "z": 0.0},
                "orientation": {"x": 0, "y": 0, "z": 0, "w": 1}
            }
        ]
    }
)
# Automatically resolves to a Mosaico RobotPath with attached metadata
mosaico_path = RobotPathAdapter.translate(ros_msg)

translate classmethod

translate(ros_msg, **kwargs)

Translates a ROS message into a Mosaico Message.

Returns:

Name Type Description
Message Message

The translated message containing a RobotPath object.

Raises:

Type Description
Exception

Wraps any translation error with context (topic name, timestamp).

from_dict classmethod

from_dict(ros_data)

Parses a dictionary to extract a RobotPath object.

Example
ros_data = {
    "header": {"frame_id": "map", "stamp": {"sec": 17000, "nanosec": 0}},
    "poses":[
        {
            "header": {"frame_id": "base_link", "stamp": {"sec": 17000, "nanosec": 0}},
            "position": {"x": 1.0, "y": 2.0, "z": 0.0},
            "orientation": {"x": 0, "y": 0, "z": 0, "w": 1}
        },
        {
            "header": {"frame_id": "base_link", "stamp": {"sec": 18000, "nanosec": 0}},
            "position": {"x": 2.0, "y": 3.0, "z": 0.0},
            "orientation": {"x": 0, "y": 0, "z": 0, "w": 1}
        },
        {
            "header": {"frame_id": "base_link", "stamp": {"sec": 19000, "nanosec": 0}},
            "position": {"x": 3.0, "y": 4.0, "z": 0.0},
            "orientation": {"x": 0, "y": 0, "z": 0, "w": 1}
        }
    ]
}
# Automatically resolves to a Mosaico RobotPath with attached metadata
mosaico_robot_path = RobotPathAdapter.from_dict(ros_data)

Parameters:

Name Type Description Default
ros_data dict

The raw dictionary from the ROS message.

required

Returns:

Name Type Description
RobotPath RobotPath

The constructed Mosaico RobotPath object.

Raises:

Type Description
ValueError

If the 'poses' key exists but is not a list, or if required keys are missing.

to_ros classmethod

to_ros(mosaico_data, typestore, ros_msg_type=None)

Converts a Mosaico RobotPath (or a Message wrapping one) into a nav_msgs/msg/Path message.

Parameters:

Name Type Description Default
mosaico_data Union[Message, RobotPath]

A Message wrapping a RobotPath instance, or a raw RobotPath.

required
typestore Typestore

The rosbags typestore for target type resolution.

required
ros_msg_type Optional[str]

Override for the output ROS type. Only nav_msgs/msg/Path is supported.

None

Returns:

Name Type Description
MsgType MsgType

A nav_msgs/msg/Path instance, or raises an error if:

  • the ros_msg_type is unsupported by adapter (TypeError)
  • the ros_msg_type or default type are unsupported by typestore (TypeError)
  • the ros_msg_type or default type are supported but translation is not implemented (NotImplementedError)

schema_metadata classmethod

schema_metadata(typestore, ros_msg_type, ros_version)

Extract the ROS message specific schema metadata, if any.

Parameters:

Name Type Description Default
typestore Typestore

The rosbags typestore for target type resolution.

required
ros_msg_type str

The ROS message type to extract metadata for.

required
ros_version int

The ROS version (1 or 2) to consider for metadata extraction.

required

Returns:

Type Description
Optional[dict]

Optional[dict]: A dictionary containing the schema metadata, or None if not applicable.

ros_msg_type abstractmethod classmethod

ros_msg_type()

Returns the specific ROS message type handled by this adapter.

is_rosmsg_type_valid classmethod

is_rosmsg_type_valid(type_to_validate)

Checks whether a given ROS message type string is handled by this adapter.

Parameters:

Name Type Description Default
type_to_validate str

The full ROS message type string to check (e.g., "sensor_msgs/msg/Imu").

required

Returns:

Name Type Description
bool bool

True if the adapter supports this type, False otherwise.

unpack_mosaico_msg classmethod

unpack_mosaico_msg(mosaico_msg)

Extracts the typed Mosaico payload and its Header (if present) from a wrapped or bare message.

Handles two input cases:

  • Message wrapper: the typed data is extracted via get_data().
  • Raw ontology instance: returned as-is with

the Header is extracted from the ontology (if supported), otherwise an default Header (empty frame_id and zero Time) is returned.

Parameters:

Name Type Description Default
mosaico_msg Union[Message, T]

Either a Message envelope or a raw instance of cls.__mosaico_ontology_type__.

required

Returns:

Type Description
T

tuple[T, Header]: A (data, header) tuple where data is the typed ontology object and

Header

header is the corresponding Header, or a default Header (empty frame_id and

tuple[T, Header]

zero Time) if not present.

Raises:

Type Description
TypeError

If mosaico_msg is neither a Message nor an instance of the expected ontology type.

ontology_data_type classmethod

ontology_data_type()

Returns the Ontology class type associated with this adapter.

GridCellsAdapter

Bases: ROSAdapterBase[GridCells]

Adapter for translating ROS GridCells messages to Mosaico GridCells.

Supported ROS Types:

Example:

ros_msg = ROSMessage(
    topic="/gridcells",
    timestamp=17000,
    msg_type="nav_msgs/msg/GridCells",
    data={
        "cell_width": 10,
        "cell_height": 10,
        "cells": [
            {
                "x": 1,
                "y": 2,
                "z": 4,
            },
            {
                "x": 40,
                "y": 39,
                "z": 10,
            },
        ]
    }
)

mosaico_grid_cells = GridCellsAdapter.translate(ros_msg)

translate classmethod

translate(ros_msg, **kwargs)

Translates a ROS message into a Mosaico Message.

Returns:

Name Type Description
Message Message

The translated message containing a GridCells object.

Raises:

Type Description
Exception

Wraps any translation error with context (topic name, timestamp).

from_dict classmethod

from_dict(ros_data)

Parses ROS GridCells data.

Parameters:

Name Type Description Default
ros_data dict

The raw dictionary from the ROS message.

required

Returns:

Name Type Description
GridCells GridCells

The constructed Mosaico GridCells object.

to_ros classmethod

to_ros(mosaico_data, typestore, ros_msg_type=None)

Converts a Mosaico GridCells (or a Message wrapping one) into a nav_msgs/msg/GridCells message.

Parameters:

Name Type Description Default
mosaico_data Union[Message, GridCells]

A Message wrapping a GridCells instance, or a raw GridCells.

required
typestore Typestore

The rosbags typestore for target type resolution.

required
ros_msg_type Optional[str]

Override for the output ROS type. Only nav_msgs/msg/GridCells is supported.

None

Returns:

Name Type Description
MsgType MsgType

A nav_msgs/msg/GridCells instance, or raises an error if:

  • the ros_msg_type is unsupported by adapter (TypeError)
  • the ros_msg_type or default type are unsupported by typestore (TypeError)
  • the ros_msg_type or default type are supported but translation is not implemented (NotImplementedError)

schema_metadata classmethod

schema_metadata(typestore, ros_msg_type, ros_version)

Extract the ROS message specific schema metadata, if any.

Parameters:

Name Type Description Default
typestore Typestore

The rosbags typestore for target type resolution.

required
ros_msg_type str

The ROS message type to extract metadata for.

required
ros_version int

The ROS version (1 or 2) to consider for metadata extraction.

required

Returns:

Type Description
Optional[dict]

Optional[dict]: A dictionary containing the schema metadata, or None if not applicable.

ros_msg_type abstractmethod classmethod

ros_msg_type()

Returns the specific ROS message type handled by this adapter.

is_rosmsg_type_valid classmethod

is_rosmsg_type_valid(type_to_validate)

Checks whether a given ROS message type string is handled by this adapter.

Parameters:

Name Type Description Default
type_to_validate str

The full ROS message type string to check (e.g., "sensor_msgs/msg/Imu").

required

Returns:

Name Type Description
bool bool

True if the adapter supports this type, False otherwise.

unpack_mosaico_msg classmethod

unpack_mosaico_msg(mosaico_msg)

Extracts the typed Mosaico payload and its Header (if present) from a wrapped or bare message.

Handles two input cases:

  • Message wrapper: the typed data is extracted via get_data().
  • Raw ontology instance: returned as-is with

the Header is extracted from the ontology (if supported), otherwise an default Header (empty frame_id and zero Time) is returned.

Parameters:

Name Type Description Default
mosaico_msg Union[Message, T]

Either a Message envelope or a raw instance of cls.__mosaico_ontology_type__.

required

Returns:

Type Description
T

tuple[T, Header]: A (data, header) tuple where data is the typed ontology object and

Header

header is the corresponding Header, or a default Header (empty frame_id and

tuple[T, Header]

zero Time) if not present.

Raises:

Type Description
TypeError

If mosaico_msg is neither a Message nor an instance of the expected ontology type.

ontology_data_type classmethod

ontology_data_type()

Returns the Ontology class type associated with this adapter.

MapMetadataAdapter

Bases: ROSAdapterBase[MapMetadata]

Adapter for translating ROS MapMetadata messages to Mosaico MapMetadata.

Supported ROS Types:

Example:

ros_msg = ROSMessage(
    topic="/mapmetadata",
    timestamp=17000,
    msg_type="nav_msgs/msg/MapMetaData",
    data={
        "map_load_time": {
            "sec": 100000,
            "nanosec": 1000
        },
        "resolution": 10000,
        "width": 100,
        "height": 100,
        "origin": {
            "position": {"x": 1.0, "y": 2.0, "z": 0.0},
            "orientation": {"x": 0, "y": 0, "z": 0, "w": 1}
        }
    }
)

mosaico_map_metadata = MapMetadataAdapter.translate(ros_msg)

translate classmethod

translate(ros_msg, **kwargs)

Translates a ROS message into a Mosaico Message.

Returns:

Name Type Description
Message Message

The translated message containing a MapMetadata object.

Raises:

Type Description
Exception

Wraps any translation error with context (topic name, timestamp).

from_dict classmethod

from_dict(ros_data)

Parses ROS MapMetadata data.

Parameters:

Name Type Description Default
ros_data dict

The raw dictionary from the ROS message.

required

Returns:

Name Type Description
MapMetadata MapMetadata

The constructed Mosaico MapMetadata object.

to_ros classmethod

to_ros(mosaico_data, typestore, ros_msg_type=None)

Converts a Mosaico MapMetadata (or a Message wrapping one) into a nav_msgs/msg/MapMetaData message.

Parameters:

Name Type Description Default
mosaico_data Union[Message, MapMetadata]

A Message wrapping a MapMetadata instance, or a raw MapMetadata.

required
typestore Typestore

The rosbags typestore for target type resolution.

required
ros_msg_type Optional[str]

Override for the output ROS type. Only nav_msgs/msg/MapMetaData is supported.

None

Returns:

Name Type Description
MsgType MsgType

A nav_msgs/msg/MapMetaData instance, or raises an error if:

  • the ros_msg_type is unsupported by adapter (TypeError)
  • the ros_msg_type or default type are unsupported by typestore (TypeError)
  • the ros_msg_type or default type are supported but translation is not implemented (NotImplementedError)

schema_metadata classmethod

schema_metadata(typestore, ros_msg_type, ros_version)

Extract the ROS message specific schema metadata, if any.

Parameters:

Name Type Description Default
typestore Typestore

The rosbags typestore for target type resolution.

required
ros_msg_type str

The ROS message type to extract metadata for.

required
ros_version int

The ROS version (1 or 2) to consider for metadata extraction.

required

Returns:

Type Description
Optional[dict]

Optional[dict]: A dictionary containing the schema metadata, or None if not applicable.

ros_msg_type abstractmethod classmethod

ros_msg_type()

Returns the specific ROS message type handled by this adapter.

is_rosmsg_type_valid classmethod

is_rosmsg_type_valid(type_to_validate)

Checks whether a given ROS message type string is handled by this adapter.

Parameters:

Name Type Description Default
type_to_validate str

The full ROS message type string to check (e.g., "sensor_msgs/msg/Imu").

required

Returns:

Name Type Description
bool bool

True if the adapter supports this type, False otherwise.

unpack_mosaico_msg classmethod

unpack_mosaico_msg(mosaico_msg)

Extracts the typed Mosaico payload and its Header (if present) from a wrapped or bare message.

Handles two input cases:

  • Message wrapper: the typed data is extracted via get_data().
  • Raw ontology instance: returned as-is with

the Header is extracted from the ontology (if supported), otherwise an default Header (empty frame_id and zero Time) is returned.

Parameters:

Name Type Description Default
mosaico_msg Union[Message, T]

Either a Message envelope or a raw instance of cls.__mosaico_ontology_type__.

required

Returns:

Type Description
T

tuple[T, Header]: A (data, header) tuple where data is the typed ontology object and

Header

header is the corresponding Header, or a default Header (empty frame_id and

tuple[T, Header]

zero Time) if not present.

Raises:

Type Description
TypeError

If mosaico_msg is neither a Message nor an instance of the expected ontology type.

ontology_data_type classmethod

ontology_data_type()

Returns the Ontology class type associated with this adapter.

OccupancyGridAdapter

Bases: ROSAdapterBase[OccupancyGrid]

Adapter for translating ROS OccupancyGrid messages to Mosaico OccupancyGrid.

Supported ROS Types:

Example:

ros_msg = ROSMessage(
    topic="/occupancygrid",
    timestamp=17000,
    msg_type="nav_msgs/msg/OccupancyGrid",
    data={
        "info": {
            "map_load_time": {
                "sec": 100000,
                "nanosec": 1000
            },
            "resolution": 4,
            "width": 2,
            "height": 2,
            "origin": {
                "position": {"x": 1.0, "y": 2.0, "z": 0.0},
                "orientation": {"x": 0, "y": 0, "z": 0, "w": 1}
            }
        },
        data: [1, -1, 0.5, 0]
    }
)

mosaico_occupancy_grid = OccupancyGridAdapter.translate(ros_msg)

translate classmethod

translate(ros_msg, **kwargs)

Translates a ROS message into a Mosaico Message.

Returns:

Name Type Description
Message Message

The translated message containing a OccupancyGrid object.

Raises:

Type Description
Exception

Wraps any translation error with context (topic name, timestamp).

from_dict classmethod

from_dict(ros_data)

Parses ROS OccupancyGrid data.

Parameters:

Name Type Description Default
ros_data dict

The raw dictionary from the ROS message.

required

Returns:

Name Type Description
OccupancyGrid OccupancyGrid

The constructed Mosaico OccupancyGrid object.

to_ros classmethod

to_ros(mosaico_data, typestore, ros_msg_type=None)

Converts a Mosaico OccupancyGrid (or a Message wrapping one) into a nav_msgs/msg/OccupancyGrid message.

Parameters:

Name Type Description Default
mosaico_data Union[Message, OccupancyGrid]

A Message wrapping a OccupancyGrid instance, or a raw OccupancyGrid.

required
typestore Typestore

The rosbags typestore for target type resolution.

required
ros_msg_type Optional[str]

Override for the output ROS type. Only nav_msgs/msg/OccupancyGrid is supported.

None

Returns:

Name Type Description
MsgType MsgType

A nav_msgs/msg/OccupancyGrid instance, or raises an error if:

  • the ros_msg_type is unsupported by adapter (TypeError)
  • the ros_msg_type or default type are unsupported by typestore (TypeError)
  • the ros_msg_type or default type are supported but translation is not implemented (NotImplementedError)

schema_metadata classmethod

schema_metadata(typestore, ros_msg_type, ros_version)

Extract the ROS message specific schema metadata, if any.

Parameters:

Name Type Description Default
typestore Typestore

The rosbags typestore for target type resolution.

required
ros_msg_type str

The ROS message type to extract metadata for.

required
ros_version int

The ROS version (1 or 2) to consider for metadata extraction.

required

Returns:

Type Description
Optional[dict]

Optional[dict]: A dictionary containing the schema metadata, or None if not applicable.

ros_msg_type abstractmethod classmethod

ros_msg_type()

Returns the specific ROS message type handled by this adapter.

is_rosmsg_type_valid classmethod

is_rosmsg_type_valid(type_to_validate)

Checks whether a given ROS message type string is handled by this adapter.

Parameters:

Name Type Description Default
type_to_validate str

The full ROS message type string to check (e.g., "sensor_msgs/msg/Imu").

required

Returns:

Name Type Description
bool bool

True if the adapter supports this type, False otherwise.

unpack_mosaico_msg classmethod

unpack_mosaico_msg(mosaico_msg)

Extracts the typed Mosaico payload and its Header (if present) from a wrapped or bare message.

Handles two input cases:

  • Message wrapper: the typed data is extracted via get_data().
  • Raw ontology instance: returned as-is with

the Header is extracted from the ontology (if supported), otherwise an default Header (empty frame_id and zero Time) is returned.

Parameters:

Name Type Description Default
mosaico_msg Union[Message, T]

Either a Message envelope or a raw instance of cls.__mosaico_ontology_type__.

required

Returns:

Type Description
T

tuple[T, Header]: A (data, header) tuple where data is the typed ontology object and

Header

header is the corresponding Header, or a default Header (empty frame_id and

tuple[T, Header]

zero Time) if not present.

Raises:

Type Description
TypeError

If mosaico_msg is neither a Message nor an instance of the expected ontology type.

ontology_data_type classmethod

ontology_data_type()

Returns the Ontology class type associated with this adapter.