Skip to content

Base Adapter

mosaicolabs.ros_bridge.adapter_base

ROSAdapterBase

Bases: ABC, Generic[T]

Abstract Base Class for converting ROS messages to Mosaico Ontology types.

The Adaptation Layer is the semantic core of the ROS Bridge. Rather than performing simple parsing, adapters actively translate raw ROS data into standardized, strongly-typed Mosaico Ontology objects.

Attributes:

Name Type Description
ros_msgtype str | Tuple[str, ...]

The ROS message type string (e.g., 'sensor_msgs/msg/Imu') or a tuple of supported types.

__mosaico_ontology_type__ Type[T]

The target Mosaico class (e.g., IMU).

_REQUIRED_KEYS Tuple[str, ...]

Internal validation list for mandatory ROS message fields.

ros_msg_type abstractmethod classmethod

ros_msg_type()

Returns the specific ROS message type handled by this adapter.

translate classmethod

translate(ros_msg, **kwargs)

Translates a ROS message instance into a Mosaico Message.

Implementation should handle recursive unwrapping, unit conversion, and validation.

Parameters:

Name Type Description Default
ros_msg ROSMessage

The source container yielded by the ROSLoader.

required
**kwargs Any

Contextual data such as calibration parameters or frame overrides.

{}

Returns:

Type Description
Message

A Mosaico Message object containing the instantiated ontology data.

from_dict abstractmethod classmethod

from_dict(ros_data)

Maps the raw ROS dictionary to the EncoderTicks Pydantic model.

This method performs field validation and header reconstruction.

schema_metadata abstractmethod classmethod

schema_metadata(ros_data, **kwargs)

Extracts ROS-specific schema metadata for the Mosaico platform.

This allows preserving original ROS attributes that may not fit directly into the physical ontology fields.

ontology_data_type classmethod

ontology_data_type()

Returns the Ontology class type associated with this adapter.