nav_msgs Adapters
mosaicolabs.ros_bridge.adapters.nav_msgs ¶
OdometryAdapter ¶
Bases: ROSAdapterBase[MotionState]
Adapter for translating ROS Odometry messages to Mosaico MotionState.
Supported ROS Types:
Example
ros_msg = ROSMessage(
timestamp=17000,
topic="/odometry",
msg_type="nav_msgs/msg/Odometry",
data = {
"header": {"frame_id": "map", "stamp": {"sec": 17000, "nanosec": 0}},
"pose": {
"position": {"x": 1.0, "y": 2.0, "z": 0.0},
"orientation": {"x": 0, "y": 0, "z": 0, "w": 1}
},
"twist": {
"linear": {"x": 0.0, "y": 0.0, "z": 0.0},
"angular": {"x": 0.0, "y": 0.0, "z": 0.0}
},
"child_frame_id": "base_link"
}
)
# Automatically resolves to a flat Mosaico MotionState with attached metadata
mosaico_odometry = OdometryAdapter.translate(ros_msg)
translate
classmethod
¶
Translates a ROS message into a Mosaico Message.
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
The translated message containing a |
Raises:
| Type | Description |
|---|---|
Exception
|
Wraps any translation error with context (topic name, timestamp). |
from_dict
classmethod
¶
Parses a dictionary to extract a MotionState object.
Example
ros_data = {
"header": {"frame_id": "map", "stamp": {"sec": 17000, "nanosec": 0}},
"pose": {
"position": {"x": 1.0, "y": 2.0, "z": 0.0},
"orientation": {"x": 0, "y": 0, "z": 0, "w": 1}
},
"twist": {
"linear": {"x": 0.0, "y": 0.0, "z": 0.0},
"angular": {"x": 0.0, "y": 0.0, "z": 0.0}
},
"child_frame_id": "base_link"
}
# Automatically resolves to a flat Mosaico MotionState with attached metadata
mosaico_odometry = OdometryAdapter.from_dict(ros_data)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ros_data
|
dict
|
The raw dictionary from the ROS message. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
MotionState |
MotionState
|
The constructed Mosaico MotionState object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a required key is missing from |
to_ros
classmethod
¶
Converts a Mosaico MotionState (or a Message wrapping one) into a
nav_msgs/msg/Odometry message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mosaico_data
|
Union[Message, MotionState]
|
A |
required |
typestore
|
Typestore
|
The rosbags typestore for target type resolution. |
required |
ros_msg_type
|
Optional[str]
|
Override for the output ROS type. Only
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
MsgType |
MsgType
|
A
|
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. |
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.
RobotPathAdapter ¶
Bases: ROSAdapterBase[RobotPath]
Adapter for translating ROS Path messages to Mosaico RobotPath.
Supported ROS Types:
Example
ros_msg = ROSMessage(
timestamp=17000,
topic="/path",
msg_type="nav_msgs/msg/Path",
data = {
"header": {"frame_id": "map", "stamp": {"sec": 17000, "nanosec": 0}},
"poses":[
{
"header": {"frame_id": "base_link", "stamp": {"sec": 17000, "nanosec": 0}},
"position": {"x": 1.0, "y": 2.0, "z": 0.0},
"orientation": {"x": 0, "y": 0, "z": 0, "w": 1}
},
{
"header": {"frame_id": "base_link", "stamp": {"sec": 18000, "nanosec": 0}},
"position": {"x": 2.0, "y": 3.0, "z": 0.0},
"orientation": {"x": 0, "y": 0, "z": 0, "w": 1}
},
{
"header": {"frame_id": "base_link", "stamp": {"sec": 19000, "nanosec": 0}},
"position": {"x": 3.0, "y": 4.0, "z": 0.0},
"orientation": {"x": 0, "y": 0, "z": 0, "w": 1}
}
]
}
)
# Automatically resolves to a Mosaico RobotPath with attached metadata
mosaico_path = RobotPathAdapter.translate(ros_msg)
translate
classmethod
¶
Translates a ROS message into a Mosaico Message.
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
The translated message containing a |
Raises:
| Type | Description |
|---|---|
Exception
|
Wraps any translation error with context (topic name, timestamp). |
from_dict
classmethod
¶
Parses a dictionary to extract a RobotPath object.
Example
ros_data = {
"header": {"frame_id": "map", "stamp": {"sec": 17000, "nanosec": 0}},
"poses":[
{
"header": {"frame_id": "base_link", "stamp": {"sec": 17000, "nanosec": 0}},
"position": {"x": 1.0, "y": 2.0, "z": 0.0},
"orientation": {"x": 0, "y": 0, "z": 0, "w": 1}
},
{
"header": {"frame_id": "base_link", "stamp": {"sec": 18000, "nanosec": 0}},
"position": {"x": 2.0, "y": 3.0, "z": 0.0},
"orientation": {"x": 0, "y": 0, "z": 0, "w": 1}
},
{
"header": {"frame_id": "base_link", "stamp": {"sec": 19000, "nanosec": 0}},
"position": {"x": 3.0, "y": 4.0, "z": 0.0},
"orientation": {"x": 0, "y": 0, "z": 0, "w": 1}
}
]
}
# Automatically resolves to a Mosaico RobotPath with attached metadata
mosaico_robot_path = RobotPathAdapter.from_dict(ros_data)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ros_data
|
dict
|
The raw dictionary from the ROS message. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
RobotPath |
RobotPath
|
The constructed Mosaico RobotPath object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the 'poses' key exists but is not a list, or if required keys are missing. |
to_ros
classmethod
¶
Converts a Mosaico RobotPath (or a Message wrapping one) into a
nav_msgs/msg/Path message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mosaico_data
|
Union[Message, RobotPath]
|
A |
required |
typestore
|
Typestore
|
The rosbags typestore for target type resolution. |
required |
ros_msg_type
|
Optional[str]
|
Override for the output ROS type. Only
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
MsgType |
MsgType
|
A
|
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. |
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.
GridCellsAdapter ¶
Bases: ROSAdapterBase[GridCells]
Adapter for translating ROS GridCells messages to Mosaico GridCells.
Supported ROS Types:
Example:
ros_msg = ROSMessage(
topic="/gridcells",
timestamp=17000,
msg_type="nav_msgs/msg/GridCells",
data={
"cell_width": 10,
"cell_height": 10,
"cells": [
{
"x": 1,
"y": 2,
"z": 4,
},
{
"x": 40,
"y": 39,
"z": 10,
},
]
}
)
mosaico_grid_cells = GridCellsAdapter.translate(ros_msg)
translate
classmethod
¶
Translates a ROS message into a Mosaico Message.
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
The translated message containing a |
Raises:
| Type | Description |
|---|---|
Exception
|
Wraps any translation error with context (topic name, timestamp). |
from_dict
classmethod
¶
Parses ROS GridCells data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ros_data
|
dict
|
The raw dictionary from the ROS message. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
GridCells |
GridCells
|
The constructed Mosaico GridCells object. |
to_ros
classmethod
¶
Converts a Mosaico GridCells (or a Message wrapping one) into a
nav_msgs/msg/GridCells message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mosaico_data
|
Union[Message, GridCells]
|
A |
required |
typestore
|
Typestore
|
The rosbags typestore for target type resolution. |
required |
ros_msg_type
|
Optional[str]
|
Override for the output ROS type. Only
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
MsgType |
MsgType
|
A
|
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. |
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.
MapMetadataAdapter ¶
Bases: ROSAdapterBase[MapMetadata]
Adapter for translating ROS MapMetadata messages to Mosaico MapMetadata.
Supported ROS Types:
Example:
ros_msg = ROSMessage(
topic="/mapmetadata",
timestamp=17000,
msg_type="nav_msgs/msg/MapMetaData",
data={
"map_load_time": {
"sec": 100000,
"nanosec": 1000
},
"resolution": 10000,
"width": 100,
"height": 100,
"origin": {
"position": {"x": 1.0, "y": 2.0, "z": 0.0},
"orientation": {"x": 0, "y": 0, "z": 0, "w": 1}
}
}
)
mosaico_map_metadata = MapMetadataAdapter.translate(ros_msg)
translate
classmethod
¶
Translates a ROS message into a Mosaico Message.
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
The translated message containing a |
Raises:
| Type | Description |
|---|---|
Exception
|
Wraps any translation error with context (topic name, timestamp). |
from_dict
classmethod
¶
Parses ROS MapMetadata data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ros_data
|
dict
|
The raw dictionary from the ROS message. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
MapMetadata |
MapMetadata
|
The constructed Mosaico MapMetadata object. |
to_ros
classmethod
¶
Converts a Mosaico MapMetadata (or a Message wrapping one) into a
nav_msgs/msg/MapMetaData message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mosaico_data
|
Union[Message, MapMetadata]
|
A |
required |
typestore
|
Typestore
|
The rosbags typestore for target type resolution. |
required |
ros_msg_type
|
Optional[str]
|
Override for the output ROS type. Only
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
MsgType |
MsgType
|
A
|
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. |
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.
OccupancyGridAdapter ¶
Bases: ROSAdapterBase[OccupancyGrid]
Adapter for translating ROS OccupancyGrid messages to Mosaico OccupancyGrid.
Supported ROS Types:
Example:
ros_msg = ROSMessage(
topic="/occupancygrid",
timestamp=17000,
msg_type="nav_msgs/msg/OccupancyGrid",
data={
"info": {
"map_load_time": {
"sec": 100000,
"nanosec": 1000
},
"resolution": 4,
"width": 2,
"height": 2,
"origin": {
"position": {"x": 1.0, "y": 2.0, "z": 0.0},
"orientation": {"x": 0, "y": 0, "z": 0, "w": 1}
}
},
data: [1, -1, 0.5, 0]
}
)
mosaico_occupancy_grid = OccupancyGridAdapter.translate(ros_msg)
translate
classmethod
¶
Translates a ROS message into a Mosaico Message.
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
The translated message containing a |
Raises:
| Type | Description |
|---|---|
Exception
|
Wraps any translation error with context (topic name, timestamp). |
from_dict
classmethod
¶
Parses ROS OccupancyGrid data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ros_data
|
dict
|
The raw dictionary from the ROS message. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
OccupancyGrid |
OccupancyGrid
|
The constructed Mosaico OccupancyGrid object. |
to_ros
classmethod
¶
Converts a Mosaico OccupancyGrid (or a Message wrapping one) into a
nav_msgs/msg/OccupancyGrid message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mosaico_data
|
Union[Message, OccupancyGrid]
|
A |
required |
typestore
|
Typestore
|
The rosbags typestore for target type resolution. |
required |
ros_msg_type
|
Optional[str]
|
Override for the output ROS type. Only
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
MsgType |
MsgType
|
A
|
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. |
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.