From 2844b8bd64187beda577982a3844fbc8795ab3ca Mon Sep 17 00:00:00 2001 From: Luca Della Vedova Date: Tue, 23 Jan 2024 15:37:55 +0800 Subject: [PATCH] Remove generator options Signed-off-by: Luca Della Vedova --- .../building_map/building.py | 46 +-- .../building_map/doors/door.py | 13 +- .../building_map/doors/double_sliding_door.py | 8 +- .../building_map/doors/double_swing_door.py | 8 +- .../building_map/doors/sliding_door.py | 5 +- .../building_map/doors/swing_door.py | 5 +- .../building_map/generator.py | 31 +- rmf_building_map_tools/building_map/level.py | 8 +- rmf_building_map_tools/building_map/lift.py | 2 +- .../building_map/templates/gz_world.sdf | 297 +++++++++++++++++- .../building_map/templates/ign_world.sdf | 297 ------------------ rmf_building_map_tools/building_map/utils.py | 11 +- .../building_map_generator/_init_argparse.py | 10 +- .../building_map_generator.py | 13 +- 14 files changed, 329 insertions(+), 425 deletions(-) delete mode 100644 rmf_building_map_tools/building_map/templates/ign_world.sdf diff --git a/rmf_building_map_tools/building_map/building.py b/rmf_building_map_tools/building_map/building.py index 42ea3f0b0..5955689ae 100644 --- a/rmf_building_map_tools/building_map/building.py +++ b/rmf_building_map_tools/building_map/building.py @@ -394,15 +394,9 @@ def generate_nav_graphs(self): nav_graphs[f'{i}'] = g return nav_graphs - def generate_sdf_world(self, options): + def generate_sdf_world(self): """ Return an etree of this Building in SDF starting from a template""" - print(f'generator options: {options}') - if 'gazebo' in options: - template_name = 'gz_world.sdf' - elif 'ignition' in options: - template_name = 'ign_world.sdf' - else: - raise RuntimeError("expected either gazebo or ignition in options") + template_name = 'gz_world.sdf' template_path = os.path.join( get_package_share_directory('rmf_building_map_tools'), @@ -414,7 +408,7 @@ def generate_sdf_world(self, options): for level_name, level in self.levels.items(): level.generate_sdf_models(world) # todo: a better name - level.generate_doors(world, options) + level.generate_doors(world) level_include_ele = SubElement(world, 'include') level_model_name = f'{self.name}_{level_name}' @@ -436,7 +430,7 @@ def generate_sdf_world(self, options): print(f'[{lift_name}] is not serving any floor, ignoring.') continue lift.generate_shaft_doors(world) - lift.generate_cabin(world, options) + lift.generate_cabin(world) charger_waypoints_ele = SubElement( world, @@ -487,30 +481,14 @@ def generate_sdf_world(self, options): else: camera_pose = f'{c[0]} {c[1]-20} 10 0 0.6 1.57' # add floor-toggle GUI plugin parameters - if 'gazebo' in options: - camera_pose_ele = gui_ele.find('camera').find('pose') - camera_pose_ele.text = camera_pose - - toggle_charge_ele = SubElement( - gui_ele, - 'plugin', - {'name': 'toggle_charging', - 'filename': 'libtoggle_charging.so'}) - - toggle_floors_ele = SubElement( - gui_ele, - 'plugin', - {'name': 'toggle_floors', 'filename': 'libtoggle_floors.so'}) - - elif 'ignition' in options: - plugin_ele = gui_ele.find('.//plugin[@filename="MinimalScene"]') - camera_pose_ele = plugin_ele.find('camera_pose') - camera_pose_ele.text = camera_pose - - toggle_floors_ele = SubElement( - gui_ele, - 'plugin', - {'name': 'toggle_floors', 'filename': 'toggle_floors'}) + plugin_ele = gui_ele.find('.//plugin[@filename="MinimalScene"]') + camera_pose_ele = plugin_ele.find('camera_pose') + camera_pose_ele.text = camera_pose + + toggle_floors_ele = SubElement( + gui_ele, + 'plugin', + {'name': 'toggle_floors', 'filename': 'toggle_floors'}) for level_name, level in self.levels.items(): floor_ele = SubElement( diff --git a/rmf_building_map_tools/building_map/doors/door.py b/rmf_building_map_tools/building_map/doors/door.py index 5cdd74017..5639eb636 100644 --- a/rmf_building_map_tools/building_map/doors/door.py +++ b/rmf_building_map_tools/building_map/doors/door.py @@ -29,14 +29,14 @@ def __init__(self, door_edge, level_elevation=0.0): static_ele = SubElement(self.model_ele, 'static') static_ele.text = 'true' - def generate_section(self, name, width, x_offset, options): + def generate_section(self, name, width, x_offset): pose_ele = Element('pose') pose_ele.text = f'{x_offset} 0 {self.height/2+0.01} 0 0 0' size = [width, self.thickness, self.height] link_ele = box_link(name, size, pose_ele, - material=door_material(options), + material=door_material(), bitmask='0x02') mass = 50.0 @@ -54,8 +54,8 @@ def generate_section(self, name, width, x_offset, options): self.model_ele.append(link_ele) return link_ele - def generate_sliding_section(self, name, width, x_offset, bounds, options): - self.generate_section(name, width, x_offset, options) + def generate_sliding_section(self, name, width, x_offset, bounds): + self.generate_section(name, width, x_offset) self.model_ele.append(joint(f'{name}_joint', 'prismatic', @@ -83,10 +83,9 @@ def generate_swing_section( x_offset, bounds, axis_pose, - axis, - options + axis ): - self.generate_section(name, width, x_offset, options) + self.generate_section(name, width, x_offset) pose_ele = Element('pose') pose_ele.text = f'{axis_pose[0]} {axis_pose[1]} {axis_pose[2]} 0 0 0' diff --git a/rmf_building_map_tools/building_map/doors/double_sliding_door.py b/rmf_building_map_tools/building_map/doors/double_sliding_door.py index 00132f699..58af6605a 100644 --- a/rmf_building_map_tools/building_map/doors/double_sliding_door.py +++ b/rmf_building_map_tools/building_map/doors/double_sliding_door.py @@ -9,7 +9,7 @@ def __init__(self, door_edge, level_elevation): if 'right_left_ratio' in door_edge.params: self.right_left_ratio = door_edge.params['right_left_ratio'].value - def generate(self, world_ele, options): + def generate(self, world_ele): right_segment_length = \ (self.right_left_ratio / (1 + self.right_left_ratio)) * self.length left_segment_length = self.length - right_segment_length @@ -18,15 +18,13 @@ def generate(self, world_ele, options): 'right', right_segment_length - 0.01, self.length / 2 - right_segment_length / 2, - (0.0, right_segment_length), - options) + (0.0, right_segment_length)) self.generate_sliding_section( 'left', left_segment_length - 0.01, -self.length / 2 + left_segment_length / 2, - (-left_segment_length, 0.0), - options) + (-left_segment_length, 0.0)) if not self.plugin == 'none': plugin_ele = SubElement(self.model_ele, 'plugin') diff --git a/rmf_building_map_tools/building_map/doors/double_swing_door.py b/rmf_building_map_tools/building_map/doors/double_swing_door.py index d768849f7..c3b65c17f 100644 --- a/rmf_building_map_tools/building_map/doors/double_swing_door.py +++ b/rmf_building_map_tools/building_map/doors/double_swing_door.py @@ -12,7 +12,7 @@ def __init__(self, door_edge, level_elevation): if 'right_left_ratio' in door_edge.params: self.right_left_ratio = door_edge.params['right_left_ratio'].value - def generate(self, world_ele, options): + def generate(self, world_ele): right_segment_length = \ (self.right_left_ratio / (1 + self.right_left_ratio)) * self.length left_segment_length = self.length - right_segment_length @@ -34,8 +34,7 @@ def generate(self, world_ele, options): x_offsets[0], bounds[0], axis_pose[0], - axis, - options) + axis) self.generate_swing_section( 'left', @@ -43,8 +42,7 @@ def generate(self, world_ele, options): x_offsets[1], bounds[1], axis_pose[1], - axis, - options) + axis) if not self.plugin == 'none': plugin_ele = SubElement(self.model_ele, 'plugin') diff --git a/rmf_building_map_tools/building_map/doors/sliding_door.py b/rmf_building_map_tools/building_map/doors/sliding_door.py index ab93f2291..adec3cb04 100644 --- a/rmf_building_map_tools/building_map/doors/sliding_door.py +++ b/rmf_building_map_tools/building_map/doors/sliding_door.py @@ -6,13 +6,12 @@ class SlidingDoor(Door): def __init__(self, door_edge, level_elevation): super().__init__(door_edge, level_elevation) - def generate(self, world_ele, options): + def generate(self, world_ele): self.generate_sliding_section( 'right', self.length - 0.01, 0, - (0.0, self.length), - options) + (0.0, self.length)) if not self.plugin == 'none': plugin_ele = SubElement(self.model_ele, 'plugin') diff --git a/rmf_building_map_tools/building_map/doors/swing_door.py b/rmf_building_map_tools/building_map/doors/swing_door.py index dcf3ef700..e7abe2486 100644 --- a/rmf_building_map_tools/building_map/doors/swing_door.py +++ b/rmf_building_map_tools/building_map/doors/swing_door.py @@ -9,7 +9,7 @@ def __init__(self, door_edge, level_elevation): self.motion_radians = 3.14 * motion_degrees / 180.0 self.motion_direction = door_edge.params['motion_direction'].value - def generate(self, world_ele, options): + def generate(self, world_ele): # This is configured to be negative by default to reflect how it is # rendered on rmf_traffic_editor. axis = 'z' if self.motion_direction < 0 else '-z' @@ -20,8 +20,7 @@ def generate(self, world_ele, options): 0, (0, self.motion_radians), (self.length / 2, 0, 0), - axis, - options) + axis) if not self.plugin == 'none': plugin_ele = SubElement(self.model_ele, 'plugin') diff --git a/rmf_building_map_tools/building_map/generator.py b/rmf_building_map_tools/building_map/generator.py index ec50a240c..f47d5afa1 100644 --- a/rmf_building_map_tools/building_map/generator.py +++ b/rmf_building_map_tools/building_map/generator.py @@ -21,8 +21,7 @@ def generate_sdf( self, input_filename, output_filename, - output_models_dir, - options + output_models_dir) ): print('generating {} from {}'.format(output_filename, input_filename)) @@ -41,7 +40,7 @@ def generate_sdf( building.generate_sdf_models(output_models_dir) # generate a top-level SDF for convenience - sdf = building.generate_sdf_world(options) + sdf = building.generate_sdf_world() indent_etree(sdf) sdf_str = str(ElementToString(sdf), 'utf-8') @@ -49,32 +48,6 @@ def generate_sdf( f.write(sdf_str) print(f'{len(sdf_str)} bytes written to {output_filename}') - def generate_gazebo_sdf( - self, - input_filename, - output_filename, - output_models_dir, - options - ): - self.generate_sdf( - input_filename, - output_filename, - output_models_dir, - options + ['gazebo']) - - def generate_ignition_sdf( - self, - input_filename, - output_filename, - output_models_dir, - options - ): - self.generate_sdf( - input_filename, - output_filename, - output_models_dir, - options + ['ignition']) - def generate_nav(self, input_filename, output_dir): building = self.parse_editor_yaml(input_filename) nav_graphs = building.generate_nav_graphs() diff --git a/rmf_building_map_tools/building_map/level.py b/rmf_building_map_tools/building_map/level.py index 66b036aea..71b00b6a3 100644 --- a/rmf_building_map_tools/building_map/level.py +++ b/rmf_building_map_tools/building_map/level.py @@ -256,12 +256,12 @@ def generate_sdf_models(self, world_ele): if 'spawn_robot_type' in vertex.params: self.generate_robot_at_vertex_idx(vertex_idx, world_ele) - def generate_doors(self, world_ele, options): + def generate_doors(self, world_ele): for door_edge in self.doors: door_edge.calc_statistics(self.transformed_vertices) - self.generate_door(door_edge, world_ele, options) + self.generate_door(door_edge, world_ele) - def generate_door(self, door_edge, world_ele, options): + def generate_door(self, door_edge, world_ele): door_name = door_edge.params['name'].value door_type = door_edge.params['type'].value print(f'generate door name={door_name} type={door_type}') @@ -279,7 +279,7 @@ def generate_door(self, door_edge, world_ele, options): print(f'door type {door_type} not yet implemented') if door: - door.generate(world_ele, options) + door.generate(world_ele) def generate_robot_at_vertex_idx(self, vertex_idx, world_ele): vertex = self.transformed_vertices[vertex_idx] diff --git a/rmf_building_map_tools/building_map/lift.py b/rmf_building_map_tools/building_map/lift.py index 2002c25e0..22fc7ec76 100644 --- a/rmf_building_map_tools/building_map/lift.py +++ b/rmf_building_map_tools/building_map/lift.py @@ -333,7 +333,7 @@ def generate_wall(self, side, pair, name, platform): platform.append(visual(f'{name}_visual', pose, dims, lift_material())) platform.append(collision(f'{name}_collision', pose, dims, '0x01')) - def generate_cabin(self, world_ele, options): + def generate_cabin(self, world_ele): # materials missing for now lift_model_name = f'{self.name}' lift_model_ele = SubElement(world_ele, 'model') diff --git a/rmf_building_map_tools/building_map/templates/gz_world.sdf b/rmf_building_map_tools/building_map/templates/gz_world.sdf index 7dc243700..e8e959acf 100644 --- a/rmf_building_map_tools/building_map/templates/gz_world.sdf +++ b/rmf_building_map_tools/building_map/templates/gz_world.sdf @@ -1,21 +1,296 @@ - + + + 0.01 + 1.0 + + + + + + + + + + + + - 0.8 0.8 0.8 1.0 - 0 0 0 + 1 1 1 + 0.8 0.8 0.8 false - - model://sun - + + + + 1000 + 845 +