Skip to content

Commit

Permalink
Add Zenoh support (#113)
Browse files Browse the repository at this point in the history
* Add Zenoh to the list of supported RMW implementations

* Add zenoh_router_config_uri parameter to middleware config

* Add a sanity check to make sure we aren't trying to use Zenoh on a MicroROS-using platform

* Allow Zenoh on generic platforms
  • Loading branch information
civerachb-cpr authored Jan 16, 2025
1 parent 5317ebc commit d0d3e72
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
6 changes: 6 additions & 0 deletions clearpath_config/clearpath_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ def __init__(self, config: dict | str = None) -> None:
# Set from Config
super().__init__(setters, config)

# Sanity validation
# Run any additional assertions that depend across fields
# e.g. if there's something in system that can conflict with
# a setting from platform, it should be checked here
self._system.middleware.assert_is_supported_on_patform(self.get_platform_model())

def read(self, file: str | dict) -> None:
self._file = None
if isinstance(file, dict):
Expand Down
4 changes: 2 additions & 2 deletions clearpath_config/common/types/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def is_valid(cls, mode: str) -> bool:

@classmethod
def assert_valid(cls, mode: str) -> None:
assert cls.is_valid(mode), ('\n'.join[
assert cls.is_valid(mode), ('\n'.join([
f'Discovery mode "{mode}" not supported.'
f'Discovery mode must be one of: "{cls.ALL_SUPPORTED}"'
])
]))
19 changes: 19 additions & 0 deletions clearpath_config/common/types/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,22 @@ def __init__(self, message):
@param message A message indicating why this platform is not supported
"""
super().__init__(message)


class UnsupportedMiddlewareException(AssertionError):
"""
Indicates that the requested middleware is not supported.
This could be because the platform does not support the middleware in question,
or support for that middleware is not available in this ROS release.
Support may or may not be available in the future.
"""

def __init__(self, message):
"""
Create a new exception.
@param message A message indicating why this middleware is not supported
"""
super().__init__(message)
7 changes: 4 additions & 3 deletions clearpath_config/common/types/rmw_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ class RMWImplementation:
CYCLONE_DDS = 'rmw_cyclonedds_cpp'
FAST_RTPS = 'rmw_fastrtps_cpp'
GURUM_DDS = 'rmw_gurumdds_cpp'
ZENOH_DDS = 'rmw_zenoh_cpp'

ALL_SUPPORTED = [FAST_RTPS]
ALL_SUPPORTED = [FAST_RTPS, ZENOH_DDS]

DEFAULT = FAST_RTPS

Expand Down Expand Up @@ -60,7 +61,7 @@ def is_valid(cls, rmw: str) -> bool:

@classmethod
def assert_valid(cls, rmw: str) -> None:
assert cls.is_valid(rmw), ('\n'.join[
assert cls.is_valid(rmw), ('\n'.join([
'RMW "%s" not supported.' % rmw,
'RMW must be one of: "%s"' % cls.ALL_SUPPORTED
])
]))
21 changes: 20 additions & 1 deletion clearpath_config/system/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@

from clearpath_config.common.types.config import BaseConfig
from clearpath_config.common.types.discovery import Discovery
from clearpath_config.common.types.exception import UnsupportedMiddlewareException
from clearpath_config.common.types.hostname import Hostname
from clearpath_config.common.types.platform import Platform
from clearpath_config.common.types.rmw_implementation import RMWImplementation
from clearpath_config.common.utils.dictionary import flip_dict
from clearpath_config.system.hosts import HostListConfig
Expand Down Expand Up @@ -74,7 +76,7 @@ def __init__(
override_server_id: bool = DEFAULTS[OVERRIDE_SERVER_ID],
servers: List[dict] | ServerListConfig = DEFAULTS[SERVERS],
hosts: HostListConfig = None,
localhost: Hostname = None
localhost: Hostname = None,
) -> None:
# Initialization
self._config = {}
Expand Down Expand Up @@ -282,3 +284,20 @@ def get_local_server(self) -> ServerConfig:
s.enabled)), None)
# returns None if the localhost is not listed in the server list
return local_server

def assert_is_supported_on_patform(self, platform) -> None:
"""
Make sure that the user's middleware is compatible.
FastDDS is supported on everything.
Zenoh is only supported on platforms that do not use MicroROS.
@param platform The type of platform we're running on
@exception Raises an UnsupportedMiddlewareException if the platform cannot use
this middleware
"""
if self.rmw_implementation == RMWImplementation.ZENOH_DDS:
if (platform != Platform.A200 and platform != Platform.GENERIC):
raise UnsupportedMiddlewareException(f'Cannot use {self.rmw_implementation} on platform {platform}') # noqa: E501

0 comments on commit d0d3e72

Please sign in to comment.