Skip to content

Commit 53928fa

Browse files
authored
Add the ability to customize the base world file (#519)
* Add the ability to customize the base world file This PR adds a small feature which allows end users to add a custom base simulation file. This allows power users to customize their simulation environments with custom gazebo plugins. Signed-off-by: Arjo Chakravarty <[email protected]>
1 parent 893e566 commit 53928fa

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

rmf_building_map_tools/building_map/building.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,15 @@ def generate_nav_graphs(self):
394394
nav_graphs[f'{i}'] = g
395395
return nav_graphs
396396

397-
def generate_sdf_world(self):
397+
def generate_sdf_world(self, template_file):
398398
""" Return an etree of this Building in SDF starting from a template"""
399-
template_name = 'gz_world.sdf'
400-
401-
template_path = os.path.join(
402-
get_package_share_directory('rmf_building_map_tools'),
403-
f'templates/{template_name}')
399+
if template_file == "":
400+
template_name = 'gz_world.sdf'
401+
template_path = os.path.join(
402+
get_package_share_directory('rmf_building_map_tools'),
403+
f'templates/{template_name}')
404+
else:
405+
template_path = template_file
404406
tree = parse(template_path)
405407
sdf = tree.getroot()
406408

rmf_building_map_tools/building_map/generator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def generate_sdf(
2121
self,
2222
input_filename,
2323
output_filename,
24-
output_models_dir
24+
output_models_dir,
25+
template_file
2526
):
2627
print('generating {} from {}'.format(output_filename, input_filename))
2728

@@ -40,7 +41,7 @@ def generate_sdf(
4041
building.generate_sdf_models(output_models_dir)
4142

4243
# generate a top-level SDF for convenience
43-
sdf = building.generate_sdf_world()
44+
sdf = building.generate_sdf_world(template_file)
4445

4546
indent_etree(sdf)
4647
sdf_str = str(ElementToString(sdf), 'utf-8')

rmf_building_map_tools/building_map_generator/_init_argparse.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
help="Name of the .world file to output")
1717
shared_parser.add_argument("OUTPUT_MODEL_DIR", type=str,
1818
help="Path to output the map model files")
19-
19+
shared_parser.add_argument("--TEMPLATE_WORLD_FILE", type=str, default="",
20+
help="Specify the template for"
21+
+ " the base simulation.")
2022
# Create subparsers for Gazebo and Nav generation
2123
gazebo_parser = subparsers.add_parser(
2224
'gazebo',

rmf_building_map_tools/building_map_generator/building_map_generator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def main():
1616
g.generate_sdf(
1717
args.INPUT,
1818
args.OUTPUT_WORLD,
19-
args.OUTPUT_MODEL_DIR
19+
args.OUTPUT_MODEL_DIR,
20+
args.TEMPLATE_WORLD_FILE
2021
)
2122

2223
if args.command == "nav":

0 commit comments

Comments
 (0)