Skip to content

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_MAP defines the relationship between a ROS message type string (e.g., "std_msgs/msg/String") and the corresponding Mosaico Serializable class (e.g., String).
  • GenericStdAdapter implements the common translate and from_dict logics shared by all standard types (wrapping the 'data' field).
  • At module load time, we iterate through the mapping, dynamically create a unique subclass of GenericStdAdapter for 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:

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:

  1. Injected with a specific ros_msgtype (e.g., "std_msgs/msg/String").
  2. Injected with a specific target __mosaico_ontology_type__ (e.g., String).
  3. Registered automatically in the ROSBridge using the @register_adapter mechanism.
"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 Serializable object 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

translate(ros_msg, **kwargs)

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

from_dict(ros_data)

Converts the raw dictionary data into the specific Mosaico type.

schema_metadata classmethod

schema_metadata(ros_data, **kwargs)

Standard types do not carry additional schema metadata.

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.