std_msgs¶
mosaicolabs.ros_bridge.adapters.std_msgs ¶
Standard ROS Message Adapters.
This module provides adapters for translating standard ROS messages (std_msgs) into Mosaico ontology types. Instead of manually defining a class for every single primitive type (Int8, String, Bool, etc.), we use a dynamic factory pattern.
Architecture
_ROS_MSGTYPE_MSCO_BASE_TYPE_MAPdefines the relationship between a ROS message type string (e.g., "std_msgs/msg/String") and the corresponding Mosaico Serializable class (e.g.,String).GenericStdAdapterimplements the commontranslateandfrom_dictlogics shared by all standard types (wrapping the 'data' field).- At module load time, we iterate through the mapping, dynamically create
a unique subclass of
GenericStdAdapterfor each type and register it in the ROSBridge.
GenericStdAdapter ¶
Bases: ROSAdapterBase[Serializable]
Template for dynamic factory-based adaptation of standard ROS primitive messages.
This class provides the core translation logic for the std_msgs family. To avoid manual
definition of dozens of repetitive classes (e.g., Int8Adapter, StringAdapter), the ROS
Bridge employs a Dynamic Factory Pattern.
Supported ROS Types:
std_msgs/msg/Stringstd_msgs/msg/Int8std_msgs/msg/Int16std_msgs/msg/Int32std_msgs/msg/Int64std_msgs/msg/UInt8std_msgs/msg/UInt16std_msgs/msg/UInt32std_msgs/msg/UInt64std_msgs/msg/Float32std_msgs/msg/Float64std_msgs/msg/Bool
Architecture & Dynamic Generation¶
At module load time, the SDK iterates through a configuration mapping
(_ROS_MSGTYPE_MSCO_BASE_TYPE_MAP) and programmatically generates concrete
subclasses of GenericStdAdapter.
Each generated subclass is:
- Injected with a specific
ros_msgtype(e.g.,"std_msgs/msg/String"). - Injected with a specific target
__mosaico_ontology_type__(e.g.,String). - Registered automatically in the
ROSBridgeusing the@register_adaptermechanism.
"Adaptation" Strategy¶
Following the philosophy of "Adaptation, Not Just Parsing," these adapters do not simply extract raw values. They perform:
- Schema Enforcement: Validating that the ROS message contains the mandatory
'data'field. - Strong Typing: Wrapping the primitive value into a Mosaico
Serializableobject with its own metadata and queryable headers. - Temporal Alignment: Preserving nanosecond-precise timestamps and optional frame information from the source bag file.
Example
# Logic effectively generated by the factory:
class StringStdAdapter(GenericStdAdapter):
ros_msgtype = "std_msgs/msg/String"
__mosaico_ontology_type__ = String
# Usage within the Bridge:
ros_msg = ROSMessage(
timestamp=1707760800.123456789,
topic="/log",
msg_type="std_msgs/msg/String",
data={"data": "System OK"}
)
mosaico_string = StringStdAdapter.translate(ros_msg)
translate
classmethod
¶
Translates a standard ROS message to a Mosaico Message.
Standard messages typically contain a 'data' field and metadata. This method extracts the header/timestamp and wraps the payload using the specific ontology type defined for this adapter class.
from_dict
classmethod
¶
Converts the raw dictionary data into the specific Mosaico type.
schema_metadata
classmethod
¶
Standard types do not carry additional schema metadata.
ros_msg_type
abstractmethod
classmethod
¶
Returns the specific ROS message type handled by this adapter.
ontology_data_type
classmethod
¶
Returns the Ontology class type associated with this adapter.