Skip to content

Unmodeled Adapter

mosaicolabs.ros_bridge.adapters.unmodeled

UnmodeledAdapter

Bases: ROSAdapterBase[T], Generic[T]

Adapter for translating ROS messages to Mosaico Unmodeled subclasses.

translate classmethod

translate(ros_msg, **kwargs)

Main entry point for translating a high-level ROSMessage.

Parameters:

Name Type Description Default
ros_msg ROSMessage

The source ROS message yielded by the loader.

required
**kwargs Any

Additional context for the translation.

{}

Returns:

Name Type Description
Message Message

A Mosaico Message containing the normalized Unmodeled payload.

from_dict classmethod

from_dict(ros_data)

Converts the raw dictionary data into the specific Mosaico Unmodeled type.

Parameters:

Name Type Description Default
ros_data dict

The raw dictionary from the ROS message.

required

Returns:

Name Type Description
T T

The constructed Unmodeled subclass instance wrapping ros_data.

to_ros classmethod

to_ros(mosaico_data, typestore, ros_msg_type=None)

Converts a Mosaico Unmodeled subclass (or a Message wrapping one) into the corresponding ROS message.

Parameters:

Name Type Description Default
mosaico_data Union[Message, T]

A Message wrapping an Unmodeled instance, or a raw instance.

required
typestore Typestore

The rosbags typestore for target type resolution.

required
ros_msg_type Optional[str]

Override for the output ROS type. Defaults to the adapter's default ROS type if None.

None

Returns:

Name Type Description
Any Any

The constructed ROS message, 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)

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.

get_or_create classmethod

get_or_create(ontology_type, msgtype)

Gets or create an unmodeled adapter for the provided ontology type and msgtype. If the adapter if found within _UNMODELED_ADAPTERS_REGISTRY it is returned immediately. Conversely, it is first registered and then returned.

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.

pack_unmodeled

pack_unmodeled(raw_data, msg_def, typestore)

Recursively replaces nested-message dicts in raw_data with the actual ros message instances required to construct a ROS message.

Unmodeled.raw_data stores nested ROS messages as plain dicts, but rosbags message classes expect their nested-message fields to be instances of the corresponding rosbags type, not dicts. This walks msg_def alongside raw_data and, for every field describing a nested message (Nodetype.NAME), instantiates that message type from its (recursively packed) dict. Fields holding a base type, array or sequence are left as-is, since they can be passed straight through via **raw_data.

Parameters:

Name Type Description Default
raw_data dict[str, Any]

The payload to pack, keyed by field name exactly as declared in msg_def. Mutated in place for nested-message fields.

required
msg_def Fielddefs

The rosbags field definitions (Typestore.get_msgdef(...).fields) describing the expected shape of raw_data.

required
typestore Typestore

The rosbags typestore used to resolve nested message types by name and look up their own field definitions.

required

Returns:

Type Description
dict[str, Any]

dict[str, Any]: The updated raw_data, with every nested-message dict replaced by an instance of its corresponding rosbags message type.

Raises:

Type Description
TypeError

If a field's definition doesn't match any of the node types rosbags is expected to produce (NAME, BASE, SEQUENCE, ARRAY).