Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fenders #27

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions clearpath_config/platform/attachments/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from clearpath_config.common.utils.dictionary import merge_dict
from clearpath_config.platform.types.attachment import BaseAttachment
from clearpath_config.platform.types.bumper import Bumper
from clearpath_config.platform.types.fender import Fender
from clearpath_config.platform.types.structure import Structure
from clearpath_config.platform.types.top_plate import TopPlate
from typing import List
Expand Down Expand Up @@ -67,6 +68,10 @@ def __init__(self) -> None:
uid=ListConfig.uid_name,
obj_type=Structure,
uid_type=str)
self.__fenders = ListConfig[Fender, str](
uid=ListConfig.uid_name,
obj_type=Fender,
uid_type=str)

def to_dict(self):
d = {}
Expand Down Expand Up @@ -119,9 +124,25 @@ def structures(self, value: List[Structure] | ListConfig) -> None:
"Structures must be list of 'Structure' or 'ListConfig'"
)

@property
def fenders(self):
return self.__fenders

@fenders.setter
def fenders(self, value: List[Fender] | ListConfig) -> None:
if isinstance(value, list):
self.__fenders.set_all(value)
elif isinstance(value, ListConfig):
self.__fenders = value
else:
assert isinstance(value, list) or isinstance(value, ListConfig), (
"Fenders must be list of 'Fender' or 'ListConfig'"
)

def get_all(self) -> List[BaseAttachment]:
attachments = []
attachments.extend(self.bumpers.get_all())
attachments.extend(self.top_plates.get_all())
attachments.extend(self.structures.get_all())
attachments.extend(self.fenders.get_all())
return attachments
69 changes: 69 additions & 0 deletions clearpath_config/platform/attachments/j100.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from clearpath_config.common.utils.dictionary import flip_dict
from clearpath_config.platform.attachments.config import BaseAttachmentsConfig
from clearpath_config.platform.types.bumper import Bumper
from clearpath_config.platform.types.fender import Fender


# J100 Jackal Attachments Configuration
Expand All @@ -40,11 +41,15 @@ class J100AttachmentsConfig(BaseConfig, BaseAttachmentsConfig):
ATTACHMENTS = "attachments"
FRONT_BUMPER = "front_bumper"
REAR_BUMPER = "rear_bumper"
FRONT_FENDER = "front_fender"
REAR_FENDER = "rear_fender"

TEMPLATE = {
ATTACHMENTS: {
FRONT_BUMPER: FRONT_BUMPER,
REAR_BUMPER: REAR_BUMPER,
FRONT_FENDER: FRONT_FENDER,
REAR_FENDER: REAR_FENDER
}
}

Expand All @@ -62,6 +67,16 @@ class J100AttachmentsConfig(BaseConfig, BaseAttachmentsConfig):
'extension': Bumper.EXTENSION,
'model': Bumper.DEFAULT
},
FRONT_FENDER: {
'name': FRONT_FENDER,
'enabled': Fender.ENABLED,
'model': Fender.DEFAULT
},
REAR_FENDER: {
'name': REAR_FENDER,
'enabled': Fender.ENABLED,
'model': Fender.DEFAULT
},
}

def __init__(
Expand All @@ -73,10 +88,14 @@ def __init__(
self._config = {}
self.front_bumper = self.DEFAULTS[self.FRONT_BUMPER]
self.rear_bumper = self.DEFAULTS[self.REAR_BUMPER]
self.front_fender = self.DEFAULTS[self.FRONT_FENDER]
self.rear_fender = self.DEFAULTS[self.REAR_FENDER]
# Setter Template
setters = {
self.KEYS[self.FRONT_BUMPER]: J100AttachmentsConfig.front_bumper,
self.KEYS[self.REAR_BUMPER]: J100AttachmentsConfig.rear_bumper,
self.KEYS[self.FRONT_FENDER]: J100AttachmentsConfig.front_fender,
self.KEYS[self.REAR_FENDER]: J100AttachmentsConfig.rear_fender,
}
# Set from Config
BaseConfig.__init__(self, setters, config, self.ATTACHMENTS)
Expand Down Expand Up @@ -130,3 +149,53 @@ def rear_bumper(self, value: dict | Bumper):
assert isinstance(value, dict) or isinstance(value, Bumper), (
"Bumper must be of type 'dict' or 'Bumper'"
)

@property
def front_fender(self):
front_fender = self.fenders.get(self.FRONT_FENDER)
self.set_config_param(
key=self.KEYS[self.FRONT_FENDER],
value=front_fender.to_dict()[self.FRONT_FENDER]
)
return front_fender

@front_fender.setter
def front_fender(self, value: dict | Fender):
if isinstance(value, dict):
new = Fender(name=self.FRONT_FENDER)
new.from_dict(value)
self.fenders.set(new)
elif isinstance(value, Fender):
assert value.get_name() == self.FRONT_FENDER, (
"Front fender must be Fender with name %s" % self.FRONT_FENDER
)
self.fenders.set(new)
else:
assert isinstance(value, dict) or isinstance(value, Fender), (
"Fender must be of type 'dict' or 'Fender'"
)

@property
def rear_fender(self):
rear_fender = self.fenders.get(self.REAR_FENDER)
self.set_config_param(
key=self.KEYS[self.REAR_FENDER],
value=rear_fender.to_dict()[self.REAR_FENDER]
)
return rear_fender

@rear_fender.setter
def rear_fender(self, value: dict | Fender):
if isinstance(value, dict):
new = Fender(name=self.REAR_FENDER)
new.from_dict(value)
self.fenders.set(new)
elif isinstance(value, Fender):
assert value.get_name() == self.REAR_FENDER, (
"Rear fender must be Fender with name %s" % self.FRONT_FENDER
)
self.fenders.set(new)
else:
assert isinstance(value, dict) or isinstance(value, Fender), (
"Fender must be of type 'dict' or 'Fender'"
)
2 changes: 1 addition & 1 deletion clearpath_config/platform/types/attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

class BaseAttachment(Accessory):
ATTACHMENT_MODEL = "base_attachment"
ENABLED = True
ENABLED = False
DEFAULT = "default"
MODELS = [DEFAULT]

Expand Down
55 changes: 55 additions & 0 deletions clearpath_config/platform/types/fender.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 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.accessory import Accessory
from clearpath_config.platform.types.attachment import BaseAttachment
from typing import List


class Fender(BaseAttachment):
ATTACHMENT_MODEL = "fender"
DEFAULT = "default"
SENSOR = "sensor"
MODELS = [DEFAULT, SENSOR]

def __init__(
self,
name: str = ATTACHMENT_MODEL,
enabled: bool = BaseAttachment.ENABLED,
model: str = DEFAULT,
parent: str = Accessory.PARENT,
xyz: List[float] = Accessory.XYZ,
rpy: List[float] = Accessory.RPY
) -> None:
super().__init__(
name,
enabled,
model,
parent,
xyz,
rpy
)
2 changes: 1 addition & 1 deletion clearpath_config/platform/types/mux.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AttachmentMux():
MODEL = {
BUMPER: Bumper,
TOP_PLATE: TopPlate,
STRUCTURE: Structure
STRUCTURE: Structure,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra comma?

}

def __new__(cls, model: str) -> BaseAttachment:
Expand Down
1 change: 0 additions & 1 deletion clearpath_config/platform/types/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class Structure(BaseAttachment):
ARCH_300 = "sensor_arch_300"
ARCH_510 = "sensor_arch_510"
DEFAULT = ARCH_300
ENABLED = False
MODELS = [DEFAULT, ARCH_300, ARCH_510]

def __init__(
Expand Down