Skip to content

Commit

Permalink
Add support for ROS2 launch files and Gazebo worlds
Browse files Browse the repository at this point in the history
  • Loading branch information
argenos committed Jul 19, 2024
1 parent e61ea38 commit f12ac22
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
24 changes: 22 additions & 2 deletions src/fpm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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,
)

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/fpm/generators/ros.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0"?>

<!-- ROS1 Launch File -->
<launch>

<!-- GAZEBO SETUP ARGUMENTS -->
Expand Down
27 changes: 27 additions & 0 deletions src/fpm/templates/ros/world.ros2.launch.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>

<!-- ROS2 Launch File - Supports ROS2 Jazzy -->
<launch>


<!-- GAZEBO SETUP ARGUMENTS -->
<arg name="use_sim_time" default="true"/>
<arg name="gazebo_gui" default="false"/>
<arg name="headless" default="true"/>
<arg name="debug" default="false"/>
<arg name="paused" default="false"/>
<arg name="world_name" default="worlds/{{model_name}}.world"/>

<set_env name="GAZEBO_MODEL_PATH" value="$(find-pkg-prefix floorplan_models)/models:$(find-pkg-prefix floorplan_models)/worlds:$(env GAZEBO_MODEL_PATH)"/>

<!-- launch gazebo with empty world -->
<include file="$(find floorplan_models)/launch/gazebo_world.launch">
<let name="world_name" value="$(var world_name)"/>
<let name="paused" value="$(var paused)"/>
<let name="use_sim_time" value="$(var use_sim_time)"/>
<let name="gui" value="$(var gazebo_gui)"/>
<let name="headless" value="$(var headless)"/>
<let name="debug" value="$(var debug)"/>
</include>

</launch>

0 comments on commit f12ac22

Please sign in to comment.