Unmodeled Adapter
mosaicolabs.ros_bridge.adapters.unmodeled ¶
UnmodeledAdapter ¶
Bases: ROSAdapterBase[T], Generic[T]
Adapter for translating ROS messages to Mosaico Unmodeled subclasses.
translate
classmethod
¶
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 |
from_dict
classmethod
¶
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 |
to_ros
classmethod
¶
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 |
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
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The constructed ROS message, or raises an error if:
|
schema_metadata
classmethod
¶
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
¶
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
¶
Returns the specific ROS message type handled by this adapter.
is_rosmsg_type_valid
classmethod
¶
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., |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
|
unpack_mosaico_msg
classmethod
¶
Extracts the typed Mosaico payload and its Header (if present) from a wrapped or bare message.
Handles two input cases:
Messagewrapper: the typed data is extracted viaget_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 |
required |
Returns:
| Type | Description |
|---|---|
T
|
tuple[T, Header]: A |
Header
|
header is the corresponding |
tuple[T, Header]
|
zero |
Raises:
| Type | Description |
|---|---|
TypeError
|
If mosaico_msg is neither a |
ontology_data_type
classmethod
¶
Returns the Ontology class type associated with this adapter.
pack_unmodeled ¶
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 |
required |
msg_def
|
Fielddefs
|
The rosbags field definitions ( |
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 |
Raises:
| Type | Description |
|---|---|
TypeError
|
If a field's definition doesn't match any of the node types
rosbags is expected to produce ( |