diff --git a/src/fpm/cli.py b/src/fpm/cli.py index 5ad20c2..0c37019 100644 --- a/src/fpm/cli.py +++ b/src/fpm/cli.py @@ -65,10 +65,15 @@ def gazebo_world_model(g, model_name, base_path, **kwargs): model = {"instances": instances, "name": model_name} output_path = get_output_path(base_path, "gazebo/worlds") + if kwargs.get("ros_version", "ros2") == "ros2": + file_name = "{name}.sdf".format(name=model_name) + else: + file_name = "{name}.world".format(name=model_name) + generate_sdf_file( model, output_path, - "{name}.world".format(name=model_name), + file_name, template_name="gazebo/world.sdf.jinja", template_path=template_path, ) @@ -77,10 +82,19 @@ def gazebo_world_model(g, model_name, base_path, **kwargs): def gazebo_world_launch(model_name, base_path, **kwargs): template_path = kwargs.get("template_path") output_path = get_output_path(base_path, "ros/launch") + + if kwargs.get("ros_version", "ros2") == "ros2": + file_name = "{name}.ros2.launch".format(name=model_name) + template_name = "ros/world.ros2.launch.jinja" + else: + file_name = "{name}.ros1.launch".format(name=model_name) + template_name = "ros/world.ros1.launch.jinja" + generate_launch_file( model_name, output_path, - template_name="ros/world.launch.jinja", + file_name, + template_name=template_name, template_path=template_path, ) @@ -127,7 +141,13 @@ def get_output_path(base_path, subfolder, model_name=None): type=click.Path(exists=True, resolve_path=True), default=os.path.join("."), ) +@click.option( + "--ros-version", + type=click.STRING, + default="ros2", +) def generate(configfile, inputs, output_path, **kwargs): + print(kwargs) config = load_config_file(configfile) g = build_graph_from_directory(inputs) diff --git a/src/fpm/generators/ros.py b/src/fpm/generators/ros.py index d0ff2b3..8a64aa5 100644 --- a/src/fpm/generators/ros.py +++ b/src/fpm/generators/ros.py @@ -1,7 +1,7 @@ from fpm.utils import load_template, save_file -def generate_launch_file(model_name, output_path, **custom_args): +def generate_launch_file(model_name, output_path, file_name, **custom_args): template_name = custom_args.get("template_name", "world.launch.jinja") template_path = custom_args.get("template_path") template = load_template(template_name, template_path) @@ -10,4 +10,4 @@ def generate_launch_file(model_name, output_path, **custom_args): output = template.render(pkg_path=ros_pkg, model_name=model_name) - save_file(output_path, "{name}.launch".format(name=model_name), output) + save_file(output_path, file_name, output) diff --git a/src/fpm/templates/ros/world.launch.jinja b/src/fpm/templates/ros/world.ros1.launch.jinja similarity index 97% rename from src/fpm/templates/ros/world.launch.jinja rename to src/fpm/templates/ros/world.ros1.launch.jinja index 8b0d052..d8bfa65 100644 --- a/src/fpm/templates/ros/world.launch.jinja +++ b/src/fpm/templates/ros/world.ros1.launch.jinja @@ -1,5 +1,6 @@ + diff --git a/src/fpm/templates/ros/world.ros2.launch.jinja b/src/fpm/templates/ros/world.ros2.launch.jinja new file mode 100644 index 0000000..0fb08cd --- /dev/null +++ b/src/fpm/templates/ros/world.ros2.launch.jinja @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +