Skip to content

Commit 95fd44a

Browse files
committed
Description and Bash generator cleanup
1 parent 54f18cd commit 95fd44a

File tree

8 files changed

+97
-149
lines changed

8 files changed

+97
-149
lines changed

clearpath_generator_common/clearpath_generator_common/bash/writer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class BashWriter():
3838

3939
def __init__(self, bash_file: BashFile):
4040
self.bash_file = bash_file
41-
self.file = open(self.bash_file.get_full_path(), 'w')
41+
self.file = open(self.bash_file.full_path, 'w')
4242

4343
def write(self, string, indent_level=0):
4444
self.file.write('{0}{1}\n'.format(self.tab * indent_level, string))
@@ -50,7 +50,7 @@ def add_unset(self, envar: str):
5050
self.write('unset {0}'.format(envar))
5151

5252
def add_source(self, bash_file: BashFile):
53-
self.write('source {0}'.format(bash_file.get_full_path()))
53+
self.write('source {0}'.format(bash_file.full_path))
5454

5555
def close(self):
5656
self.file.close()

clearpath_generator_common/clearpath_generator_common/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ def __init__(self,
200200
self.name = name
201201
self.file = '{0}.bash'.format(name)
202202

203-
def get_full_path(self):
203+
@property
204+
def full_path(self):
204205
if self.package:
205206
return os.path.join(
206207
get_package_share_directory(self.package.name), self.path, self.file)

clearpath_generator_common/clearpath_generator_common/description/attachments.py

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,13 @@ def __init__(self, platform: str, attachment: BaseAttachment) -> None:
5050

5151
self.parameters = {}
5252

53-
def get_parameters(self) -> dict:
54-
return self.parameters
53+
@property
54+
def xyz(self) -> List[float]:
55+
return self.attachment.xyz
5556

56-
def get_parameter(self, parameter: str) -> str:
57-
return self.parameters[parameter]
58-
59-
def get_package(self) -> str:
60-
return self.package
61-
62-
def get_path(self) -> str:
63-
return self.path
64-
65-
def get_file(self) -> str:
66-
return self.file
67-
68-
def get_xyz(self) -> List[float]:
69-
return self.attachment.get_xyz()
70-
71-
def get_rpy(self) -> List[float]:
72-
return self.attachment.get_rpy()
57+
@property
58+
def rpy(self) -> List[float]:
59+
return self.attachment.rpy
7360

7461
class BumperDescription(BaseDescription):
7562
NAME = 'name'
@@ -79,8 +66,8 @@ def __init__(self, platform: str, attachment: Bumper) -> None:
7966
super().__init__(platform, attachment)
8067
self.file = 'bumper'
8168
self.parameters.update({
82-
self.NAME: attachment.get_name(),
83-
self.EXTENSION: attachment.get_extension()
69+
self.NAME: attachment.name,
70+
self.EXTENSION: attachment.extension
8471
})
8572

8673
class TopPlateDescription(BaseDescription):
@@ -89,7 +76,7 @@ class TopPlateDescription(BaseDescription):
8976
def __init__(self, platform: str, attachment: TopPlate) -> None:
9077
super().__init__(platform, attachment)
9178
self.parameters.update({
92-
self.MODEL: attachment.get_model(),
79+
self.MODEL: attachment.model,
9380
})
9481

9582
class StructureDescription(BaseDescription):
@@ -99,8 +86,8 @@ class StructureDescription(BaseDescription):
9986
def __init__(self, platform: str, attachment: Structure) -> None:
10087
super().__init__(platform, attachment)
10188
self.parameters.update({
102-
self.PARENT_LINK: 'top_plate_link',
103-
self.MODEL: attachment.get_model()
89+
self.PARENT_LINK: attachment.parent,
90+
self.MODEL: attachment.model
10491
})
10592

10693
MODEL = {

clearpath_generator_common/clearpath_generator_common/description/generator.py

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def generate(self) -> None:
7979
self.xacro_writer.write_newline()
8080

8181
self.xacro_writer.close_file()
82+
print(f'Generated {self.xacro_writer.file_path}robot.urdf.xacro')
8283

8384
def generate_platform(self) -> None:
8485
self.platform = self.clearpath_config.platform.get_model()
@@ -87,10 +88,10 @@ def generate_platform(self) -> None:
8788
# Platform macro
8889
self.xacro_writer.write_comment('Platform')
8990
self.xacro_writer.write_include(
90-
package=platform_description.get_package(),
91-
file=platform_description.get_file(),
92-
path=platform_description.get_path())
93-
self.xacro_writer.write_macro(platform_description.get_macro())
91+
package=platform_description.package,
92+
file=platform_description.file,
93+
path=platform_description.path)
94+
self.xacro_writer.write_macro(platform_description.macro)
9495

9596
def generate_attachments(self) -> None:
9697
self.xacro_writer.write_comment('Attachments')
@@ -101,16 +102,16 @@ def generate_attachments(self) -> None:
101102
if attachment.get_enabled():
102103
attachment_description = AttachmentsDescription(self.platform, attachment)
103104
self.xacro_writer.write_include(
104-
package=attachment_description.get_package(),
105-
file=attachment_description.get_file(),
106-
path=attachment_description.get_path())
105+
package=attachment_description.package,
106+
file=attachment_description.file,
107+
path=attachment_description.path)
107108

108109
self.xacro_writer.write_macro(
109-
macro=attachment_description.get_file(),
110-
parameters=attachment_description.get_parameters(),
110+
macro=attachment_description.file,
111+
parameters=attachment_description.parameters,
111112
blocks=XacroWriter.add_origin(
112-
attachment_description.get_xyz(),
113-
attachment_description.get_rpy()))
113+
attachment_description.xyz,
114+
attachment_description.rpy))
114115
self.xacro_writer.write_newline()
115116

116117
def generate_links(self) -> None:
@@ -121,16 +122,16 @@ def generate_links(self) -> None:
121122
for link in links:
122123
link_description = LinkDescription(link)
123124
self.xacro_writer.write_include(
124-
package=link_description.get_package(),
125-
file=link_description.get_file(),
126-
path=link_description.get_path())
125+
package=link_description.package,
126+
file=link_description.file,
127+
path=link_description.path)
127128

128129
self.xacro_writer.write_macro(
129-
macro=link_description.get_file(),
130-
parameters=link_description.get_parameters(),
130+
macro=link_description.file,
131+
parameters=link_description.parameters,
131132
blocks=XacroWriter.add_origin(
132-
link_description.get_xyz(),
133-
link_description.get_rpy()))
133+
link_description.xyz,
134+
link_description.rpy))
134135
self.xacro_writer.write_newline()
135136

136137
def generate_mounts(self) -> None:
@@ -141,20 +142,20 @@ def generate_mounts(self) -> None:
141142
mount_description = MountDescription(mount)
142143

143144
self.xacro_writer.write_comment(
144-
'{0}'.format(mount_description.get_name())
145+
'{0}'.format(mount_description.name)
145146
)
146147

147148
self.xacro_writer.write_include(
148-
package=mount_description.get_package(),
149-
file=mount_description.get_model(),
150-
path=mount_description.get_path()
149+
package=mount_description.package,
150+
file=mount_description.model,
151+
path=mount_description.path
151152
)
152153

153154
self.xacro_writer.write_macro(
154-
macro='{0}'.format(mount_description.get_model()),
155-
parameters=mount_description.get_parameters(),
155+
macro='{0}'.format(mount_description.model),
156+
parameters=mount_description.parameters,
156157
blocks=XacroWriter.add_origin(
157-
mount_description.get_xyz(), mount_description.get_rpy())
158+
mount_description.xyz, mount_description.rpy)
158159
)
159160

160161
self.xacro_writer.write_newline()
@@ -167,20 +168,20 @@ def generate_sensors(self) -> None:
167168
sensor_description = SensorDescription(sensor)
168169

169170
self.xacro_writer.write_comment(
170-
'{0}'.format(sensor_description.get_name())
171+
'{0}'.format(sensor_description.name)
171172
)
172173

173174
self.xacro_writer.write_include(
174-
package=sensor_description.get_package(),
175-
file=sensor_description.get_model(),
176-
path=sensor_description.get_path()
175+
package=sensor_description.package,
176+
file=sensor_description.model,
177+
path=sensor_description.path
177178
)
178179

179180
self.xacro_writer.write_macro(
180-
macro='{0}'.format(sensor_description.get_model()),
181-
parameters=sensor_description.get_parameters(),
181+
macro='{0}'.format(sensor_description.model),
182+
parameters=sensor_description.parameters,
182183
blocks=XacroWriter.add_origin(
183-
sensor_description.get_xyz(), sensor_description.get_rpy())
184+
sensor_description.xyz, sensor_description.rpy)
184185
)
185186

186187
self.xacro_writer.write_newline()

clearpath_generator_common/clearpath_generator_common/description/links.py

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,38 +54,25 @@ def __init__(self, link: BaseLink) -> None:
5454
self.file = self.link.get_link_type()
5555

5656
self.parameters = {
57-
self.NAME: self.link.get_name(),
58-
self.PARENT_LINK: self.link.get_parent()
57+
self.NAME: self.link.name,
58+
self.PARENT_LINK: self.link.parent
5959
}
6060

61-
def get_parameters(self) -> dict:
62-
return self.parameters
61+
@property
62+
def xyz(self) -> List[float]:
63+
return self.link.xyz
6364

64-
def get_parameter(self, parameter: str) -> str:
65-
return self.parameters[parameter]
66-
67-
def get_package(self) -> str:
68-
return self.package
69-
70-
def get_path(self) -> str:
71-
return self.path
72-
73-
def get_file(self) -> str:
74-
return self.file
75-
76-
def get_xyz(self) -> List[float]:
77-
return self.link.get_xyz()
78-
79-
def get_rpy(self) -> List[float]:
80-
return self.link.get_rpy()
65+
@property
66+
def rpy(self) -> List[float]:
67+
return self.link.rpy
8168

8269
class BoxDescription(BaseDescription):
8370
SIZE = 'size'
8471

8572
def __init__(self, link: Box) -> None:
8673
super().__init__(link)
8774
self.parameters.update({
88-
self.SIZE: str(link.get_size()).strip('[]').replace(',', '')
75+
self.SIZE: str(link.size).strip('[]').replace(',', '')
8976
})
9077

9178
class CylinderDescription(BaseDescription):
@@ -95,8 +82,8 @@ class CylinderDescription(BaseDescription):
9582
def __init__(self, link: Cylinder) -> None:
9683
super().__init__(link)
9784
self.parameters.update({
98-
self.RADIUS: link.get_radius(),
99-
self.LENGTH: link.get_length()
85+
self.RADIUS: link.radius,
86+
self.LENGTH: link.length
10087
})
10188

10289
class SphereDescription(BaseDescription):
@@ -105,7 +92,7 @@ class SphereDescription(BaseDescription):
10592
def __init__(self, link: Sphere) -> None:
10693
super().__init__(link)
10794
self.parameters.update({
108-
self.RADIUS: link.get_radius()
95+
self.RADIUS: link.radius
10996
})
11097

11198
class MeshDescription(BaseDescription):
@@ -114,7 +101,7 @@ class MeshDescription(BaseDescription):
114101
def __init__(self, link: Mesh) -> None:
115102
super().__init__(link)
116103
self.parameters.update({
117-
self.VISUAL: link.get_visual()
104+
self.VISUAL: link.visual
118105
})
119106

120107
MODEL = {

clearpath_generator_common/clearpath_generator_common/description/mounts.py

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,40 +53,32 @@ def __init__(self, mount: BaseMount) -> None:
5353
self.path = 'urdf/'
5454

5555
self.parameters = {
56-
self.NAME: mount.get_name(),
57-
self.PARENT: mount.get_parent()
56+
self.NAME: mount.name,
57+
self.PARENT: mount.parent
5858
}
5959

60-
def get_parameters(self) -> dict:
61-
return self.parameters
62-
63-
def get_parameter(self, parameter: str) -> str:
64-
return self.parameters[parameter]
65-
66-
def get_name(self) -> str:
60+
@property
61+
def name(self) -> str:
6762
return self.parameters[self.NAME]
6863

69-
def get_model(self) -> str:
64+
@property
65+
def model(self) -> str:
7066
return self.mount.MOUNT_MODEL
7167

72-
def get_package(self) -> str:
73-
return self.package
74-
75-
def get_path(self) -> str:
76-
return self.path
77-
78-
def get_xyz(self) -> List[float]:
79-
return self.mount.get_xyz()
68+
@property
69+
def xyz(self) -> List[float]:
70+
return self.mount.xyz
8071

81-
def get_rpy(self) -> List[float]:
82-
return self.mount.get_rpy()
72+
@property
73+
def rpy(self) -> List[float]:
74+
return self.mount.rpy
8375

8476
class FathPivotDescription(BaseDescription):
8577
ANGLE = 'angle'
8678

8779
def __init__(self, mount: FathPivot) -> None:
8880
super().__init__(mount)
89-
self.parameters[self.ANGLE] = mount.get_angle()
81+
self.parameters[self.ANGLE] = mount.angle
9082

9183
class PACSRiserDescription(BaseDescription):
9284
ROWS = 'rows'
@@ -97,9 +89,9 @@ def __init__(self, mount: PACS.Riser) -> None:
9789
super().__init__(mount)
9890
self.path = 'urdf/pacs/'
9991
self.parameters.update({
100-
self.ROWS: mount.get_rows(),
101-
self.COLUMNS: mount.get_columns(),
102-
self.THICKNESS: mount.get_thickness()
92+
self.ROWS: mount.rows,
93+
self.COLUMNS: mount.columns,
94+
self.THICKNESS: mount.thickness
10395
})
10496

10597
class PACSBracketDescription(BaseDescription):
@@ -109,7 +101,7 @@ def __init__(self, mount: PACS.Bracket) -> None:
109101
super().__init__(mount)
110102
self.path = 'urdf/pacs/'
111103
self.parameters.update({
112-
self.MODEL: mount.get_model(),
104+
self.MODEL: mount.model,
113105
})
114106

115107
MODEL = {

clearpath_generator_common/clearpath_generator_common/description/platform.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,7 @@ def __init__(self, model: Platform) -> None:
4141
self.package = self.pkg_clearpath_platform_description
4242
self.file = model
4343
self.macro = self.file
44-
self.path = 'urdf/' + model + '/'
45-
46-
def get_file(self) -> str:
47-
return self.file
48-
49-
def get_macro(self) -> str:
50-
return self.macro
51-
52-
def get_package(self) -> str:
53-
return self.package
54-
55-
def get_path(self) -> str:
56-
return self.path
44+
self.path = f'urdf/{model}/'
5745

5846
MODEL = {
5947
Platform.A200: Base,

0 commit comments

Comments
 (0)