Skip to content

Commit

Permalink
Merge pull request #59 from clearpathrobotics/lcamero/extra_launch
Browse files Browse the repository at this point in the history
Extra launch file
  • Loading branch information
tonybaltovski authored Mar 18, 2024
2 parents 5adec7c + fb9dead commit 19ad4b3
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions clearpath_config/platform/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class ExtrasConfig(BaseConfig):

EXTRAS = "extras"
URDF = "urdf"
LAUNCH = "launch"
ROS_PARAMETERS = "ros_parameters"

PLATFORM_VELOCITY_CONTROLLER = "platform_velocity_controller"
Expand All @@ -154,6 +155,7 @@ class ExtrasConfig(BaseConfig):
TEMPLATE = {
EXTRAS: {
URDF: URDF,
LAUNCH: LAUNCH,
ROS_PARAMETERS: {
PLATFORM_VELOCITY_CONTROLLER: {
WHEEL_RADIUS: WHEEL_RADIUS,
Expand All @@ -175,13 +177,15 @@ class ExtrasConfig(BaseConfig):

DEFAULTS = {
URDF: None,
LAUNCH: None,
ROS_PARAMETERS: ROSParameterDefaults(BaseConfig.get_platform_model()),
}

def __init__(
self,
config: dict = {},
urdf: dict = DEFAULTS[URDF],
launch: dict = DEFAULTS[LAUNCH],
ros_parameters: dict = {},
) -> None:
# ROS Parameter Setter Template
Expand All @@ -199,12 +203,14 @@ def __init__(
# Setter Template
self.setters = {
self.KEYS[self.URDF]: ExtrasConfig.urdf,
self.KEYS[self.LAUNCH]: ExtrasConfig.launch,
self.KEYS[self.ROS_PARAMETERS]: ExtrasConfig.ros_parameters,
}
# Initialization
self._init_ros_parameter()
self._config = {}
self.urdf = urdf
self.launch = launch
self.ros_parameters = ros_parameters
# Set from Config
super().__init__(self.setters, config, self.EXTRAS)
Expand Down Expand Up @@ -235,6 +241,31 @@ def urdf(self, value: dict | PackagePath) -> None:
"Extras URDF must be null or of type `dict` or `PackagePath`"
)

@property
def launch(self) -> dict:
if (self._launch == self.DEFAULTS[self.LAUNCH]):
launch = None
else:
launch = dict(self._launch.to_dict())
self.set_config_param(
key=self.KEYS[self.LAUNCH],
value=launch,
)
return launch

@launch.setter
def launch(self, value: dict | PackagePath) -> None:
if isinstance(value, dict) and PackagePath.PATH in value and value[PackagePath.PATH]:
self._launch = PackagePath()
self._launch.from_dict(value)
elif isinstance(value, PackagePath) and value.path:
self._launch = value
else:
self._launch = self.DEFAULTS[self.LAUNCH]
assert not value or isinstance(value, dict) or (isinstance(value, PackagePath)), (
"Extras LAUNCH must be null or of type `dict` or `PackagePath`"
)

def _is_ros_parameter(self, key) -> bool:
return any([key in i for i in self._ros_parameters_setters])

Expand Down

0 comments on commit 19ad4b3

Please sign in to comment.