Skip to content

Commit

Permalink
Added battery to platform
Browse files Browse the repository at this point in the history
  • Loading branch information
luis-camero committed Oct 23, 2023
1 parent cea316d commit fce1183
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 2 deletions.
155 changes: 155 additions & 0 deletions clearpath_config/platform/battery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# Software License Agreement (BSD)
#
# @author Luis Camero <lcamero@clearpathrobotics.com>
# @copyright (c) 2023, 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:
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Clearpath Robotics nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# 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.config import BaseConfig
from clearpath_config.common.types.platform import Platform
from clearpath_config.common.utils.dictionary import flip_dict


class BatteryConfig(BaseConfig):
BATTERY = "battery"

# Models
MODEL = "model"
UNKNOWN = "unknown"
# Husky Lead Acid
ES20_12C = "ES20-12C"
# Husky/Jackal Li_ION
HE2613 = "HE2613"
# Warthog Lead Acid
U1_35 = "U1-35"
# Warthog LiFEPO4
ALM12V35 = "ALM12V35"
U24_12XP = "U24-12XP"
U27_12XP = "U27-12XP"

# Configurations
CONFIGURATION = "configuration"
_2S1P = "2S1P"
_1S3P = "1S3P"
_1S4P = "1S4P"
_1S1P = "1S1P"
_4S3P = "4S3P"
_4S1P = "4S1P"

VALID = {
Platform.GENERIC: {
UNKNOWN: [UNKNOWN]
},
Platform.A200: {
ES20_12C: [_2S1P],
HE2613: [_1S3P, _1S4P],
},
Platform.J100: {
HE2613: [_1S1P],
},
Platform.W200: {
U1_35: [_4S3P],
ALM12V35: [_4S3P],
U24_12XP: [_4S1P],
U27_12XP: [_4S1P],
},
}

TEMPLATE = {
BATTERY: {
MODEL: MODEL,
CONFIGURATION: CONFIGURATION
}
}

KEYS = flip_dict(TEMPLATE)

DEFAULTS = {
MODEL: UNKNOWN,
CONFIGURATION: UNKNOWN
}

def __init__(
self,
config: dict = {},
model: str = DEFAULTS[MODEL],
configuration: str = DEFAULTS[CONFIGURATION],
) -> None:
# Initialization
self._config = {}
self.model = model
self.configuration = configuration
# Setter Template
setters = {
self.KEYS[self.MODEL]: BatteryConfig.model,
self.KEYS[self.CONFIGURATION]: BatteryConfig.configuration,
}
super().__init__(setters, config, self.BATTERY)

def update(self, serial_number: bool = False) -> None:
if serial_number:
platform = BaseConfig.get_platform_model()
self.model = list(self.VALID[platform])[0]
self.configuration = list(self.VALID[platform][self.model])[0]

@property
def model(self) -> str:
self.set_config_param(
key=self.KEYS[self.MODEL],
value=self._model
)
return self._model

@model.setter
def model(self, value: str) -> None:
platform = BaseConfig.get_platform_model()
assert platform in self.VALID, (
"Platform must be one of: %s" % self.VALID
)
assert value in self.VALID[platform], (
"Battery model for platform '%s' must be one of: %s" % (platform, self.VALID[platform])
)
self._model = value

@property
def configuration(self) -> str:
self.set_config_param(
key=self.KEYS[self.CONFIGURATION],
value=self._configuration
)
return self._configuration

@configuration.setter
def configuration(self, value: str) -> None:
platform = BaseConfig.get_platform_model()
assert platform in self.VALID, (
"Platform must be one of: %s" % self.VALID
)
assert self.model in self.VALID[platform], (
"Battery model for platform '%s' must be one of: %s" % (platform, self.VALID[platform])
)
assert value in self.VALID[platform][self.model], (
"Battery configuration for platform '%s', and battery model '%s' must be one of: %s" % (
platform, self.model, self.VALID[platform][self.model])
)
self._configuration = value
35 changes: 33 additions & 2 deletions clearpath_config/platform/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# POSSIBILITY OF SUCH DAMAGE.
from clearpath_config.common.types.config import BaseConfig
from clearpath_config.common.utils.dictionary import flip_dict
from clearpath_config.platform.battery import BatteryConfig
from clearpath_config.platform.extras import ExtrasConfig
from clearpath_config.platform.attachments.config import BaseAttachmentsConfig
from clearpath_config.platform.attachments.mux import AttachmentsConfigMux
Expand All @@ -38,15 +39,19 @@ class PlatformConfig(BaseConfig):
# Controllers
PS4 = "ps4"
LOGITECH = "logitech"

CONTROLLER = "controller"
ATTACHMENTS = "attachments"
# Extras
EXTRAS = "extras"
# Battery
BATTERY = "battery"

TEMPLATE = {
PLATFORM: {
CONTROLLER: CONTROLLER,
ATTACHMENTS: ATTACHMENTS,
BATTERY: BATTERY,
EXTRAS: EXTRAS
}
}
Expand All @@ -57,25 +62,29 @@ class PlatformConfig(BaseConfig):
# PLATFORM
CONTROLLER: PS4,
ATTACHMENTS: {},
EXTRAS: ExtrasConfig.DEFAULTS
BATTERY: BatteryConfig.DEFAULTS,
EXTRAS: ExtrasConfig.DEFAULTS,
}

def __init__(
self,
config: dict = {},
controller: str = DEFAULTS[CONTROLLER],
attachments: str = DEFAULTS[ATTACHMENTS],
extras: str = DEFAULTS[EXTRAS]
battery: dict = DEFAULTS[BATTERY],
extras: dict = DEFAULTS[EXTRAS],
) -> None:
# Initialization
self._config = {}
self.controller = controller
self.attachments = attachments
self._battery = BatteryConfig(battery)
self._extras = ExtrasConfig(extras)
# Setter Template
setters = {
self.KEYS[self.CONTROLLER]: PlatformConfig.controller,
self.KEYS[self.ATTACHMENTS]: PlatformConfig.attachments,
self.KEYS[self.BATTERY]: PlatformConfig.battery,
self.KEYS[self.EXTRAS]: PlatformConfig.extras
}
super().__init__(setters, config, self.PLATFORM)
Expand All @@ -87,6 +96,8 @@ def update(self, serial_number=False) -> None:
# TODO: Set PACS Profile
# Reload extras
self.extras.update(serial_number=serial_number)
# Reload battery
self.battery.update(serial_number=serial_number)

@property
def controller(self) -> str:
Expand Down Expand Up @@ -139,3 +150,23 @@ def extras(self, value: dict | ExtrasConfig) -> None:

def get_controller(self) -> str:
return self.controller

@property
def battery(self) -> BatteryConfig:
self.set_config_param(
key=self.KEYS[self.BATTERY],
value=self._battery.config[self.BATTERY]
)
return self._battery

@battery.setter
def battery(self, value: dict | BatteryConfig) -> None:
if isinstance(value, dict):
self._battery.config = value
elif isinstance(value, BatteryConfig):
self._battery = value
else:
assert isinstance(value, dict) or (
isinstance(value, BatteryConfig)), (
"Battery configuration must be of type 'dict' or 'BatteryConfig'"
)
3 changes: 3 additions & 0 deletions clearpath_config/sample/a200/a200_default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ system:
workspaces: []
platform:
controller: ps4
battery:
model: ES20-12C
configuration: 2S1P
attachments:
front_bumper:
enabled: true
Expand Down
3 changes: 3 additions & 0 deletions clearpath_config/sample/a200/a200_dual_laser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ system:
workspaces: []
platform:
controller: ps4
battery:
model: ES20-12C
configuration: 2S1P
attachments:
front_bumper:
enabled: true
Expand Down
3 changes: 3 additions & 0 deletions clearpath_config/sample/a200/a200_sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ system:
workspaces: []
platform:
controller: ps4
battery:
model: ES20-12C
configuration: 2S1P
attachments:
front_bumper:
enabled: true
Expand Down
3 changes: 3 additions & 0 deletions clearpath_config/sample/a200/a200_velodyne.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ system:
workspaces: []
platform:
controller: ps4
battery:
model: ES20-12C
configuration: 2S1P
attachments:
front_bumper:
enabled: true
Expand Down
3 changes: 3 additions & 0 deletions clearpath_config/sample/j100/j100_default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ system:
workspaces: []
platform:
controller: ps4
battery:
model: HE2613
configuration: 1S1P
attachments:
front_fender:
enabled: true
Expand Down
3 changes: 3 additions & 0 deletions clearpath_config/sample/j100/j100_dual_laser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ system:
workspaces: []
platform:
controller: ps4
battery:
model: HE2613
configuration: 1S1P
attachments:
front_fender:
enabled: true
Expand Down
3 changes: 3 additions & 0 deletions clearpath_config/sample/j100/j100_sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ system:
workspaces: []
platform:
controller: ps4
battery:
model: HE2613
configuration: 1S1P
attachments:
front_fender:
enabled: true
Expand Down
3 changes: 3 additions & 0 deletions clearpath_config/sample/j100/j100_velodyne.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ system:
workspaces: []
platform:
controller: ps4
battery:
model: HE2613
configuration: 1S1P
attachments:
front_fender:
enabled: true
Expand Down

0 comments on commit fce1183

Please sign in to comment.