Skip to content

nav_msgs

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 the recursive 'pose' key exists but is not a dict, or if required keys are missing.

schema_metadata classmethod

schema_metadata(ros_data, **kwargs)

Extract the ROS message specific schema metadata, if any.

ros_msg_type abstractmethod classmethod

ros_msg_type()

Returns the specific ROS message type handled by this adapter.

ontology_data_type classmethod

ontology_data_type()

Returns the Ontology class type associated with this adapter.