diff --git a/clearpath_generator_common/clearpath_generator_common/bash/writer.py b/clearpath_generator_common/clearpath_generator_common/bash/writer.py index 0ed47a08..981dc2e5 100644 --- a/clearpath_generator_common/clearpath_generator_common/bash/writer.py +++ b/clearpath_generator_common/clearpath_generator_common/bash/writer.py @@ -38,7 +38,7 @@ class BashWriter(): def __init__(self, bash_file: BashFile): self.bash_file = bash_file - self.file = open(self.bash_file.get_full_path(), 'w') + self.file = open(self.bash_file.full_path, 'w') def write(self, string, indent_level=0): self.file.write('{0}{1}\n'.format(self.tab * indent_level, string)) @@ -50,7 +50,7 @@ def add_unset(self, envar: str): self.write('unset {0}'.format(envar)) def add_source(self, bash_file: BashFile): - self.write('source {0}'.format(bash_file.get_full_path())) + self.write('source {0}'.format(bash_file.full_path)) def close(self): self.file.close() diff --git a/clearpath_generator_common/clearpath_generator_common/common.py b/clearpath_generator_common/clearpath_generator_common/common.py index f856c0f6..bfe465c1 100644 --- a/clearpath_generator_common/clearpath_generator_common/common.py +++ b/clearpath_generator_common/clearpath_generator_common/common.py @@ -200,7 +200,8 @@ def __init__(self, self.name = name self.file = '{0}.bash'.format(name) - def get_full_path(self): + @property + def full_path(self): if self.package: return os.path.join( get_package_share_directory(self.package.name), self.path, self.file) diff --git a/clearpath_generator_common/clearpath_generator_common/description/attachments.py b/clearpath_generator_common/clearpath_generator_common/description/attachments.py index 34d9baa7..4bf41087 100644 --- a/clearpath_generator_common/clearpath_generator_common/description/attachments.py +++ b/clearpath_generator_common/clearpath_generator_common/description/attachments.py @@ -50,26 +50,13 @@ def __init__(self, platform: str, attachment: BaseAttachment) -> None: self.parameters = {} - def get_parameters(self) -> dict: - return self.parameters + @property + def xyz(self) -> List[float]: + return self.attachment.xyz - def get_parameter(self, parameter: str) -> str: - return self.parameters[parameter] - - def get_package(self) -> str: - return self.package - - def get_path(self) -> str: - return self.path - - def get_file(self) -> str: - return self.file - - def get_xyz(self) -> List[float]: - return self.attachment.get_xyz() - - def get_rpy(self) -> List[float]: - return self.attachment.get_rpy() + @property + def rpy(self) -> List[float]: + return self.attachment.rpy class BumperDescription(BaseDescription): NAME = 'name' @@ -79,8 +66,8 @@ def __init__(self, platform: str, attachment: Bumper) -> None: super().__init__(platform, attachment) self.file = 'bumper' self.parameters.update({ - self.NAME: attachment.get_name(), - self.EXTENSION: attachment.get_extension() + self.NAME: attachment.name, + self.EXTENSION: attachment.extension }) class TopPlateDescription(BaseDescription): @@ -89,7 +76,7 @@ class TopPlateDescription(BaseDescription): def __init__(self, platform: str, attachment: TopPlate) -> None: super().__init__(platform, attachment) self.parameters.update({ - self.MODEL: attachment.get_model(), + self.MODEL: attachment.model, }) class StructureDescription(BaseDescription): @@ -99,8 +86,8 @@ class StructureDescription(BaseDescription): def __init__(self, platform: str, attachment: Structure) -> None: super().__init__(platform, attachment) self.parameters.update({ - self.PARENT_LINK: 'top_plate_link', - self.MODEL: attachment.get_model() + self.PARENT_LINK: attachment.parent, + self.MODEL: attachment.model }) MODEL = { diff --git a/clearpath_generator_common/clearpath_generator_common/description/generator.py b/clearpath_generator_common/clearpath_generator_common/description/generator.py index 7e2c555b..37e46210 100644 --- a/clearpath_generator_common/clearpath_generator_common/description/generator.py +++ b/clearpath_generator_common/clearpath_generator_common/description/generator.py @@ -79,6 +79,7 @@ def generate(self) -> None: self.xacro_writer.write_newline() self.xacro_writer.close_file() + print(f'Generated {self.xacro_writer.file_path}robot.urdf.xacro') def generate_platform(self) -> None: self.platform = self.clearpath_config.platform.get_model() @@ -87,10 +88,10 @@ def generate_platform(self) -> None: # Platform macro self.xacro_writer.write_comment('Platform') self.xacro_writer.write_include( - package=platform_description.get_package(), - file=platform_description.get_file(), - path=platform_description.get_path()) - self.xacro_writer.write_macro(platform_description.get_macro()) + package=platform_description.package, + file=platform_description.file, + path=platform_description.path) + self.xacro_writer.write_macro(platform_description.macro) def generate_attachments(self) -> None: self.xacro_writer.write_comment('Attachments') @@ -101,16 +102,16 @@ def generate_attachments(self) -> None: if attachment.get_enabled(): attachment_description = AttachmentsDescription(self.platform, attachment) self.xacro_writer.write_include( - package=attachment_description.get_package(), - file=attachment_description.get_file(), - path=attachment_description.get_path()) + package=attachment_description.package, + file=attachment_description.file, + path=attachment_description.path) self.xacro_writer.write_macro( - macro=attachment_description.get_file(), - parameters=attachment_description.get_parameters(), + macro=attachment_description.file, + parameters=attachment_description.parameters, blocks=XacroWriter.add_origin( - attachment_description.get_xyz(), - attachment_description.get_rpy())) + attachment_description.xyz, + attachment_description.rpy)) self.xacro_writer.write_newline() def generate_links(self) -> None: @@ -121,16 +122,16 @@ def generate_links(self) -> None: for link in links: link_description = LinkDescription(link) self.xacro_writer.write_include( - package=link_description.get_package(), - file=link_description.get_file(), - path=link_description.get_path()) + package=link_description.package, + file=link_description.file, + path=link_description.path) self.xacro_writer.write_macro( - macro=link_description.get_file(), - parameters=link_description.get_parameters(), + macro=link_description.file, + parameters=link_description.parameters, blocks=XacroWriter.add_origin( - link_description.get_xyz(), - link_description.get_rpy())) + link_description.xyz, + link_description.rpy)) self.xacro_writer.write_newline() def generate_mounts(self) -> None: @@ -141,20 +142,20 @@ def generate_mounts(self) -> None: mount_description = MountDescription(mount) self.xacro_writer.write_comment( - '{0}'.format(mount_description.get_name()) + '{0}'.format(mount_description.name) ) self.xacro_writer.write_include( - package=mount_description.get_package(), - file=mount_description.get_model(), - path=mount_description.get_path() + package=mount_description.package, + file=mount_description.model, + path=mount_description.path ) self.xacro_writer.write_macro( - macro='{0}'.format(mount_description.get_model()), - parameters=mount_description.get_parameters(), + macro='{0}'.format(mount_description.model), + parameters=mount_description.parameters, blocks=XacroWriter.add_origin( - mount_description.get_xyz(), mount_description.get_rpy()) + mount_description.xyz, mount_description.rpy) ) self.xacro_writer.write_newline() @@ -167,20 +168,20 @@ def generate_sensors(self) -> None: sensor_description = SensorDescription(sensor) self.xacro_writer.write_comment( - '{0}'.format(sensor_description.get_name()) + '{0}'.format(sensor_description.name) ) self.xacro_writer.write_include( - package=sensor_description.get_package(), - file=sensor_description.get_model(), - path=sensor_description.get_path() + package=sensor_description.package, + file=sensor_description.model, + path=sensor_description.path ) self.xacro_writer.write_macro( - macro='{0}'.format(sensor_description.get_model()), - parameters=sensor_description.get_parameters(), + macro='{0}'.format(sensor_description.model), + parameters=sensor_description.parameters, blocks=XacroWriter.add_origin( - sensor_description.get_xyz(), sensor_description.get_rpy()) + sensor_description.xyz, sensor_description.rpy) ) self.xacro_writer.write_newline() diff --git a/clearpath_generator_common/clearpath_generator_common/description/links.py b/clearpath_generator_common/clearpath_generator_common/description/links.py index 89c24c43..f72350f1 100644 --- a/clearpath_generator_common/clearpath_generator_common/description/links.py +++ b/clearpath_generator_common/clearpath_generator_common/description/links.py @@ -54,30 +54,17 @@ def __init__(self, link: BaseLink) -> None: self.file = self.link.get_link_type() self.parameters = { - self.NAME: self.link.get_name(), - self.PARENT_LINK: self.link.get_parent() + self.NAME: self.link.name, + self.PARENT_LINK: self.link.parent } - def get_parameters(self) -> dict: - return self.parameters + @property + def xyz(self) -> List[float]: + return self.link.xyz - def get_parameter(self, parameter: str) -> str: - return self.parameters[parameter] - - def get_package(self) -> str: - return self.package - - def get_path(self) -> str: - return self.path - - def get_file(self) -> str: - return self.file - - def get_xyz(self) -> List[float]: - return self.link.get_xyz() - - def get_rpy(self) -> List[float]: - return self.link.get_rpy() + @property + def rpy(self) -> List[float]: + return self.link.rpy class BoxDescription(BaseDescription): SIZE = 'size' @@ -85,7 +72,7 @@ class BoxDescription(BaseDescription): def __init__(self, link: Box) -> None: super().__init__(link) self.parameters.update({ - self.SIZE: str(link.get_size()).strip('[]').replace(',', '') + self.SIZE: str(link.size).strip('[]').replace(',', '') }) class CylinderDescription(BaseDescription): @@ -95,8 +82,8 @@ class CylinderDescription(BaseDescription): def __init__(self, link: Cylinder) -> None: super().__init__(link) self.parameters.update({ - self.RADIUS: link.get_radius(), - self.LENGTH: link.get_length() + self.RADIUS: link.radius, + self.LENGTH: link.length }) class SphereDescription(BaseDescription): @@ -105,7 +92,7 @@ class SphereDescription(BaseDescription): def __init__(self, link: Sphere) -> None: super().__init__(link) self.parameters.update({ - self.RADIUS: link.get_radius() + self.RADIUS: link.radius }) class MeshDescription(BaseDescription): @@ -114,7 +101,7 @@ class MeshDescription(BaseDescription): def __init__(self, link: Mesh) -> None: super().__init__(link) self.parameters.update({ - self.VISUAL: link.get_visual() + self.VISUAL: link.visual }) MODEL = { diff --git a/clearpath_generator_common/clearpath_generator_common/description/mounts.py b/clearpath_generator_common/clearpath_generator_common/description/mounts.py index dbcc6046..d28bdbaf 100644 --- a/clearpath_generator_common/clearpath_generator_common/description/mounts.py +++ b/clearpath_generator_common/clearpath_generator_common/description/mounts.py @@ -53,40 +53,32 @@ def __init__(self, mount: BaseMount) -> None: self.path = 'urdf/' self.parameters = { - self.NAME: mount.get_name(), - self.PARENT: mount.get_parent() + self.NAME: mount.name, + self.PARENT: mount.parent } - def get_parameters(self) -> dict: - return self.parameters - - def get_parameter(self, parameter: str) -> str: - return self.parameters[parameter] - - def get_name(self) -> str: + @property + def name(self) -> str: return self.parameters[self.NAME] - def get_model(self) -> str: + @property + def model(self) -> str: return self.mount.MOUNT_MODEL - def get_package(self) -> str: - return self.package - - def get_path(self) -> str: - return self.path - - def get_xyz(self) -> List[float]: - return self.mount.get_xyz() + @property + def xyz(self) -> List[float]: + return self.mount.xyz - def get_rpy(self) -> List[float]: - return self.mount.get_rpy() + @property + def rpy(self) -> List[float]: + return self.mount.rpy class FathPivotDescription(BaseDescription): ANGLE = 'angle' def __init__(self, mount: FathPivot) -> None: super().__init__(mount) - self.parameters[self.ANGLE] = mount.get_angle() + self.parameters[self.ANGLE] = mount.angle class PACSRiserDescription(BaseDescription): ROWS = 'rows' @@ -97,9 +89,9 @@ def __init__(self, mount: PACS.Riser) -> None: super().__init__(mount) self.path = 'urdf/pacs/' self.parameters.update({ - self.ROWS: mount.get_rows(), - self.COLUMNS: mount.get_columns(), - self.THICKNESS: mount.get_thickness() + self.ROWS: mount.rows, + self.COLUMNS: mount.columns, + self.THICKNESS: mount.thickness }) class PACSBracketDescription(BaseDescription): @@ -109,7 +101,7 @@ def __init__(self, mount: PACS.Bracket) -> None: super().__init__(mount) self.path = 'urdf/pacs/' self.parameters.update({ - self.MODEL: mount.get_model(), + self.MODEL: mount.model, }) MODEL = { diff --git a/clearpath_generator_common/clearpath_generator_common/description/platform.py b/clearpath_generator_common/clearpath_generator_common/description/platform.py index 6c693632..877ad7c1 100644 --- a/clearpath_generator_common/clearpath_generator_common/description/platform.py +++ b/clearpath_generator_common/clearpath_generator_common/description/platform.py @@ -41,19 +41,7 @@ def __init__(self, model: Platform) -> None: self.package = self.pkg_clearpath_platform_description self.file = model self.macro = self.file - self.path = 'urdf/' + model + '/' - - def get_file(self) -> str: - return self.file - - def get_macro(self) -> str: - return self.macro - - def get_package(self) -> str: - return self.package - - def get_path(self) -> str: - return self.path + self.path = f'urdf/{model}/' MODEL = { Platform.A200: Base, diff --git a/clearpath_generator_common/clearpath_generator_common/description/sensors.py b/clearpath_generator_common/clearpath_generator_common/description/sensors.py index e28a1fd2..e180dcc1 100644 --- a/clearpath_generator_common/clearpath_generator_common/description/sensors.py +++ b/clearpath_generator_common/clearpath_generator_common/description/sensors.py @@ -56,33 +56,25 @@ def __init__(self, sensor: BaseSensor) -> None: self.path = 'urdf/' self.parameters = { - self.NAME: sensor.get_name(), - self.PARENT: sensor.get_parent() + self.NAME: sensor.name, + self.PARENT: sensor.parent } - def get_parameters(self) -> dict: - return self.parameters + @property + def name(self) -> str: + return self.sensor.name - def get_parameter(self, parameter: str) -> str: - return self.parameters[parameter] - - def get_name(self) -> str: - return self.parameters[self.NAME] - - def get_model(self) -> str: + @property + def model(self) -> str: return self.sensor.SENSOR_MODEL - def get_package(self) -> str: - return self.package - - def get_path(self) -> str: - return self.path - - def get_xyz(self) -> List[float]: - return self.sensor.get_xyz() + @property + def xyz(self) -> List[float]: + return self.sensor.xyz - def get_rpy(self) -> List[float]: - return self.sensor.get_rpy() + @property + def rpy(self) -> List[float]: + return self.sensor.rpy class Lidar2dDescription(BaseDescription): ANGULAR_RESOLUTION = 'ang_res' @@ -97,8 +89,8 @@ def __init__(self, sensor: BaseLidar2D) -> None: self.parameters.update({ self.ANGULAR_RESOLUTION: 0.5, - self.MINIMUM_ANGLE: sensor.get_min_angle(), - self.MAXIMUM_ANGLE: sensor.get_max_angle(), + self.MINIMUM_ANGLE: sensor.min_angle, + self.MAXIMUM_ANGLE: sensor.max_angle, self.MINIMUM_RANGE: 0.05, self.MAXIMUM_RANGE: 25.0, self.UPDATE_RATE: 50 @@ -147,7 +139,7 @@ def __init__(self, sensor: BaseCamera) -> None: super().__init__(sensor) self.parameters.update({ - self.UPDATE_RATE: sensor.get_fps() + self.UPDATE_RATE: sensor.fps }) class IntelRealsenseDescription(CameraDescription): @@ -158,8 +150,8 @@ def __init__(self, sensor: IntelRealsense) -> None: super().__init__(sensor) self.parameters.update({ - self.IMAGE_HEIGHT: sensor.get_color_height(), - self.IMAGE_WIDTH: sensor.get_color_width(), + self.IMAGE_HEIGHT: sensor.color_height, + self.IMAGE_WIDTH: sensor.color_width, }) MODEL = {