Skip to content

Commit

Permalink
Merge pull request #58 from clearpathrobotics/discovery-server
Browse files Browse the repository at this point in the history
Discovery server support
  • Loading branch information
luis-camero authored Mar 8, 2024
2 parents cfb0321 + bdc0243 commit c3ac7d1
Show file tree
Hide file tree
Showing 26 changed files with 766 additions and 359 deletions.
1 change: 1 addition & 0 deletions clearpath_config/common/types/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(
parent_key: str = None,
) -> None:
# Dictionaries are Stored Flat
self._config = {}
self.template = template
self._parent_key = parent_key
if self._parent_key is not None and self._parent_key not in config:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Software License Agreement (BSD)
#
# @author Luis Camero <lcamero@clearpathrobotics.com>
# @copyright (c) 2023, Clearpath Robotics, Inc., All rights reserved.
# @author Hilary Luo <hluo@clearpathrobotics.com>
# @copyright (c) 2024, Clearpath Robotics, Inc., All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
Expand All @@ -25,44 +25,42 @@
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
from clearpath_config.common.types.hostname import Hostname
from clearpath_config.common.types.ip import IP

class Discovery:
SIMPLE = "simple"
SERVER = "server"

# All supported discovery modes, currently only set up for FastDDS
ALL_SUPPORTED = [SIMPLE, SERVER]

# The discovery mode that the system will default to
DEFAULT = SIMPLE

# Host
# - hostname and config pair
class Host:
def __init__(
self,
hostname: str = "hostname",
ip: str = "0.0.0.0"
mode: str = DEFAULT
) -> None:
self.hostname = Hostname()
self.ip = IP()
self.set_hostname(hostname)
self.set_ip(ip)
self.assert_valid(mode)
self.mode = mode

def __eq__(self, other) -> bool:
return self.hostname == other.hostname and self.ip == other.ip
def __eq__(self, other: object) -> bool:
if isinstance(other, str):
return self.mode == other
elif isinstance(other, Discovery):
return self.mode == other.mode
else:
return False

def __str__(self) -> str:
return "{ hostname: %s, ip: %s }" % (str(self.hostname), str(self.ip))

def to_dict(self) -> dict:
return {str(self.hostname): str(self.ip)}

# Hostname:
# - the hostname of this host
def get_hostname(self) -> str:
return str(self.hostname)

def set_hostname(self, hostname: str) -> None:
self.hostname = Hostname(hostname)
return self.mode

# IP
# - the ip of this host
def get_ip(self) -> str:
return str(self.ip)
@classmethod
def is_valid(cls, mode: str) -> bool:
return mode in cls.ALL_SUPPORTED

def set_ip(self, ip: str) -> None:
self.ip = IP(ip)
@classmethod
def assert_valid(cls, mode: str) -> None:
assert cls.is_valid(mode), ("\n".join[
f"Discovery mode '{mode}' not supported."
f"Discovery mode must be one of: '{cls.ALL_SUPPORTED}'"
])
4 changes: 4 additions & 0 deletions clearpath_config/common/types/hostname.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def assert_valid(hostname: str):
assert isinstance(hostname, str), (
"Hostname '%s' must be of type 'str'" % hostname
)
# Min 1 ASCII Characters
assert len(hostname) > 0, (
"Hostname '%s' is blank." % hostname
)
# Max 253 ASCII Characters
assert len(hostname) < 254, (
"Hostname '%s' exceeds 253 ASCII character limit." % hostname
Expand Down
1 change: 1 addition & 0 deletions clearpath_config/common/types/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def set_all(
except AssertionError:
self.__list = tmp_list

# TODO: the below UID methods are not supported by most implementations of this class
# Unique Identifier: Name
@staticmethod
def uid_name(T) -> str:
Expand Down
10 changes: 6 additions & 4 deletions clearpath_config/common/types/rmw_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ class RMWImplementation:
FAST_RTPS = "rmw_fastrtps_cpp"
GURUM_DDS = "rmw_gurumdds_cpp"

MIDDLEWARE = [FAST_RTPS]
ALL_SUPPORTED = [FAST_RTPS]

DEFAULT = FAST_RTPS

def __init__(
self,
rmw: str = FAST_RTPS
rmw: str = DEFAULT
) -> None:
self.assert_valid(rmw)
self.rmw = rmw
Expand All @@ -54,11 +56,11 @@ def __str__(self) -> str:

@classmethod
def is_valid(cls, rmw: str) -> bool:
return rmw in cls.MIDDLEWARE
return rmw in cls.ALL_SUPPORTED

@classmethod
def assert_valid(cls, rmw: str) -> None:
assert cls.is_valid(rmw), ("\n".join[
"RMW '%s' not supported." % rmw,
"RMW must be one of: '%s'" % cls.MIDDLEWARE
"RMW must be one of: '%s'" % cls.ALL_SUPPORTED
])
10 changes: 4 additions & 6 deletions clearpath_config/sample/a200/a200_default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ version: 0
system:
username: administrator
hosts:
self: cpr-a200-0000
platform:
cpr-a200-0000: 192.168.131.1
onboard: {}
remote: {}
- hostname: cpr-a200-0000
ip: 192.168.131.1
ros2:
namespace: a200_0000
domain_id: 0
rmw_implementation: rmw_fastrtps_cpp
middleware:
implementation: rmw_fastrtps_cpp
workspaces: []
platform:
controller: ps4
Expand Down
10 changes: 4 additions & 6 deletions clearpath_config/sample/a200/a200_dual_laser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ version: 0
system:
username: administrator
hosts:
self: cpr-a200-0000
platform:
cpr-a200-0000: 192.168.131.1
onboard: {}
remote: {}
- hostname: cpr-a200-0000
ip: 192.168.131.1
ros2:
namespace: a200_0000
domain_id: 0
rmw_implementation: rmw_fastrtps_cpp
middleware:
implementation: rmw_fastrtps_cpp
workspaces: []
platform:
controller: ps4
Expand Down
10 changes: 4 additions & 6 deletions clearpath_config/sample/a200/a200_sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ version: 0
system:
username: administrator
hosts:
self: cpr-a200-0000
platform:
cpr-a200-0000: 192.168.131.1
onboard: {}
remote: {}
- hostname: cpr-a200-0000
ip: 192.168.131.1
ros2:
namespace: a200_0000
domain_id: 0
rmw_implementation: rmw_fastrtps_cpp
middleware:
implementation: rmw_fastrtps_cpp
workspaces: []
platform:
controller: ps4
Expand Down
10 changes: 4 additions & 6 deletions clearpath_config/sample/a200/a200_velodyne.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ version: 0
system:
username: administrator
hosts:
self: cpr-a200-0000
platform:
cpr-a200-0000: 192.168.131.1
onboard: {}
remote: {}
- hostname: cpr-a200-0000
ip: 192.168.131.1
ros2:
namespace: a200_0000
domain_id: 0
rmw_implementation: rmw_fastrtps_cpp
middleware:
implementation: rmw_fastrtps_cpp
workspaces: []
platform:
controller: ps4
Expand Down
10 changes: 4 additions & 6 deletions clearpath_config/sample/dd100/dd100_default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ version: 0
system:
username: administrator
hosts:
self: cpr-dd100-0000
platform:
cpr-dd100-0000: 192.168.131.1
onboard: {}
remote: {}
- hostname: cpr-dd100-0000
ip: 192.168.131.1
ros2:
namespace: dd100_0000
domain_id: 0
rmw_implementation: rmw_fastrtps_cpp
middleware:
implementation: rmw_fastrtps_cpp
workspaces: []
platform:
controller: ps4
Expand Down
10 changes: 4 additions & 6 deletions clearpath_config/sample/dd100/dd100_dual_laser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ version: 0
system:
username: administrator
hosts:
self: cpr-dd100-0000
platform:
cpr-dd100-0000: 192.168.131.1
onboard: {}
remote: {}
- hostname: cpr-dd100-0000
ip: 192.168.131.1
ros2:
namespace: dd100_0000
domain_id: 0
rmw_implementation: rmw_fastrtps_cpp
middleware:
implementation: rmw_fastrtps_cpp
workspaces: []
platform:
controller: ps4
Expand Down
10 changes: 4 additions & 6 deletions clearpath_config/sample/dd100/dd100_velodyne.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ version: 0
system:
username: administrator
hosts:
self: cpr-dd100-0000
platform:
cpr-dd100-0000: 192.168.131.1
onboard: {}
remote: {}
- hostname: cpr-dd100-0000
ip: 192.168.131.1
ros2:
namespace: dd100_0000
domain_id: 0
rmw_implementation: rmw_fastrtps_cpp
middleware:
implementation: rmw_fastrtps_cpp
workspaces: []
platform:
controller: ps4
Expand Down
10 changes: 4 additions & 6 deletions clearpath_config/sample/dd150/dd150_default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ version: 0
system:
username: administrator
hosts:
self: cpr-dd150-0000
platform:
cpr-dd150-0000: 192.168.131.1
onboard: {}
remote: {}
- hostname: cpr-dd150-0000
ip: 192.168.131.1
ros2:
namespace: dd150_0000
domain_id: 0
rmw_implementation: rmw_fastrtps_cpp
middleware:
implementation: rmw_fastrtps_cpp
workspaces: []
platform:
controller: ps4
Expand Down
10 changes: 4 additions & 6 deletions clearpath_config/sample/dd150/dd150_dual_laser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ version: 0
system:
username: administrator
hosts:
self: cpr-dd150-0000
platform:
cpr-dd150-0000: 192.168.131.1
onboard: {}
remote: {}
- hostname: cpr-dd150-0000
ip: 192.168.131.1
ros2:
namespace: dd150_0000
domain_id: 0
rmw_implementation: rmw_fastrtps_cpp
middleware:
implementation: rmw_fastrtps_cpp
workspaces: []
platform:
controller: ps4
Expand Down
10 changes: 4 additions & 6 deletions clearpath_config/sample/dd150/dd150_velodyne.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ version: 0
system:
username: administrator
hosts:
self: cpr-dd150-0000
platform:
cpr-dd150-0000: 192.168.131.1
onboard: {}
remote: {}
- hostname: cpr-dd150-0000
ip: 192.168.131.1
ros2:
namespace: dd150_0000
domain_id: 0
rmw_implementation: rmw_fastrtps_cpp
middleware:
implementation: rmw_fastrtps_cpp
workspaces: []
platform:
controller: ps4
Expand Down
10 changes: 4 additions & 6 deletions clearpath_config/sample/j100/j100_default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ version: 0
system:
username: administrator
hosts:
self: cpr-j100-0000
platform:
cpr-j100-0000: 192.168.131.1
onboard: {}
remote: {}
- hostname: cpr-j100-0000
ip: 192.168.131.1
ros2:
namespace: j100_0000
domain_id: 0
rmw_implementation: rmw_fastrtps_cpp
middleware:
implementation: rmw_fastrtps_cpp
workspaces: []
platform:
controller: ps4
Expand Down
10 changes: 4 additions & 6 deletions clearpath_config/sample/j100/j100_dual_laser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ version: 0
system:
username: administrator
hosts:
self: cpr-j100-0000
platform:
cpr-j100-0000: 192.168.131.1
onboard: {}
remote: {}
- hostname: cpr-j100-0000
ip: 192.168.131.1
ros2:
namespace: j100_0000
domain_id: 0
rmw_implementation: rmw_fastrtps_cpp
middleware:
implementation: rmw_fastrtps_cpp
workspaces: []
platform:
controller: ps4
Expand Down
Loading

0 comments on commit c3ac7d1

Please sign in to comment.