Skip to content

tf2_msgs

mosaicolabs.ros_bridge.adapters.tf2_msgs

FrameTransformAdapter

Bases: ROSAdapterBase

Adapter for translating ROS TF2 messages to Mosaico FrameTransform.

Supported ROS Types:

Example
ros_msg = ROSMessage(
    timestamp=17000,
    topic="/tf",
    msg_type="tf2_msgs/msg/TFMessage",
    data={
        "transforms": [
            {
                "header": {
                    "stamp": {
                        "sec": 17000,
                        "nanosec": 0,
                    },
                    "frame_id": "map",
                    "child_frame_id": "base_link",
                },
                "transform": {
                    "translation": {
                        "x": 0.0,
                        "y": 0.0,
                        "z": 0.0,
                    },
                    "rotation": {
                        "x": 0.0,
                        "y": 0.0,
                        "z": 0.0,
                        "w": 1.0,
                    },
                },
            }
        ]
    },
)
# Automatically resolves to a flat Mosaico FrameTransform with attached metadata
mosaico_frame_transform = FrameTransformAdapter.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 FrameTransform object.

Raises:

Type Description
Exception

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

from_dict classmethod

from_dict(ros_data)

Converts the raw dictionary data into the specific Mosaico type.

Example
ros_data={
    "transforms": [
        {
            "header": {
                "stamp": {
                    "sec": 17000,
                    "nanosec": 0,
                },
                "frame_id": "map",
                "child_frame_id": "base_link",
            },
            "transform": {
                "translation": {
                    "x": 0.0,
                    "y": 0.0,
                    "z": 0.0,
                },
                "rotation": {
                    "x": 0.0,
                    "y": 0.0,
                    "z": 0.0,
                    "w": 1.0,
                },
            },
        }
    ]
}
# Automatically resolves to a flat Mosaico FrameTransform with attached metadata
mosaico_frame_transform = FrameTransformAdapter.from_dict(ros_data)

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.