Skip to content

Commit

Permalink
Description and Bash generator cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
roni-kreinin committed Jul 19, 2023
1 parent 54f18cd commit 95fd44a
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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')
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,38 +54,25 @@ 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'

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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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):
Expand All @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 95fd44a

Please sign in to comment.