Skip to content

Commit

Permalink
Merge pull request #7 from ika-rwth-aachen/launch-file-improvements
Browse files Browse the repository at this point in the history
Improve launch file with remappable topics and use_sim_time
  • Loading branch information
lreiher authored Dec 6, 2024
2 parents c7b3afc + ef3af6d commit 14c49a9
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
git config --global user.email "[email protected]"
- name: Generate packages
run: |
copier copy --trust --defaults \
copier copy --trust --defaults --overwrite --vcs-ref=HEAD \
-d template=${{ matrix.template }} \
-d package_name=${{ matrix.package_name }} \
-d node_name=${{ matrix.node_name }} \
Expand Down
2 changes: 1 addition & 1 deletion ros2-pkg-create/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "ros2-pkg-create"
version = "1.0.2"
version = "1.1.0"
description = "Powerful ROS 2 Package Generator"
license = {file = "LICENSE"}
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion ros2-pkg-create/src/ros2_pkg_create/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__name__ = "ros2-pkg-create"
__version__ = "1.0.2"
__version__ = "1.1.0"
29 changes: 15 additions & 14 deletions samples/generate_samples.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/bash

script_dir=$(dirname $0)
template_dir="$script_dir/.."

copier copy --trust --defaults \
copier copy --trust --defaults --overwrite --vcs-ref=HEAD \
-d template=ros2_cpp_pkg \
-d package_name=ros2_cpp_pkg \
-d node_name=ros2_cpp_node \
Expand All @@ -16,9 +17,9 @@ copier copy --trust --defaults \
-d has_action_server=false \
-d has_timer=false \
-d has_docker_ros=true \
. $script_dir
$template_dir $script_dir

copier copy --trust --defaults \
copier copy --trust --defaults --overwrite --vcs-ref=HEAD \
-d template=ros2_cpp_pkg \
-d package_name=ros2_cpp_component_pkg \
-d node_name=ros2_cpp_node \
Expand All @@ -32,9 +33,9 @@ copier copy --trust --defaults \
-d has_action_server=false \
-d has_timer=false \
-d has_docker_ros=true \
. $script_dir
$template_dir $script_dir

copier copy --trust --defaults \
copier copy --trust --defaults --overwrite --vcs-ref=HEAD \
-d template=ros2_cpp_pkg \
-d package_name=ros2_cpp_lifecycle_pkg \
-d node_name=ros2_cpp_node \
Expand All @@ -48,9 +49,9 @@ copier copy --trust --defaults \
-d has_action_server=false \
-d has_timer=false \
-d has_docker_ros=true \
. $script_dir
$template_dir $script_dir

copier copy --trust --defaults \
copier copy --trust --defaults --overwrite --vcs-ref=HEAD \
-d template=ros2_cpp_pkg \
-d package_name=ros2_cpp_all_pkg \
-d node_name=ros2_cpp_node \
Expand All @@ -64,9 +65,9 @@ copier copy --trust --defaults \
-d has_action_server=true \
-d has_timer=true \
-d has_docker_ros=true \
. $script_dir
$template_dir $script_dir

copier copy --trust --defaults \
copier copy --trust --defaults --overwrite --vcs-ref=HEAD \
-d template=ros2_python_pkg \
-d package_name=ros2_python_pkg \
-d node_name=ros2_python_node \
Expand All @@ -78,9 +79,9 @@ copier copy --trust --defaults \
-d has_action_server=false \
-d has_timer=false \
-d has_docker_ros=true \
. $script_dir
$template_dir $script_dir

copier copy --trust --defaults \
copier copy --trust --defaults --overwrite --vcs-ref=HEAD \
-d template=ros2_python_pkg \
-d package_name=ros2_python_all_pkg \
-d node_name=ros2_python_node \
Expand All @@ -92,9 +93,9 @@ copier copy --trust --defaults \
-d has_action_server=true \
-d has_timer=true \
-d has_docker_ros=true \
. $script_dir
$template_dir $script_dir

copier copy --trust --defaults \
copier copy --trust --defaults --overwrite --vcs-ref=HEAD \
-d template=ros2_interfaces_pkg \
-d package_name=ros2_interfaces_pkg \
. $script_dir
$template_dir $script_dir
9 changes: 9 additions & 0 deletions samples/ros2_cpp_all_pkg/launch/ros2_cpp_node_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@

def generate_launch_description():

remappable_topics = [
DeclareLaunchArgument("input_topic", default_value="~/input"),
DeclareLaunchArgument("output_topic", default_value="~/output"),
]

args = [
DeclareLaunchArgument("name", default_value="ros2_cpp_node", description="node name"),
DeclareLaunchArgument("namespace", default_value="", description="node namespace"),
DeclareLaunchArgument("params", default_value=os.path.join(get_package_share_directory("ros2_cpp_all_pkg"), "config", "params.yml"), description="path to parameter file"),
DeclareLaunchArgument("log_level", default_value="info", description="ROS logging level (debug, info, warn, error, fatal)"),
DeclareLaunchArgument("startup_state", default_value="None", description="initial lifecycle state"),
DeclareLaunchArgument("use_sim_time", default_value="false", description="use simulation clock"),
*remappable_topics,
]

nodes = [
Expand All @@ -35,6 +42,7 @@ def generate_launch_description():
name=LaunchConfiguration("name"),
parameters=[LaunchConfiguration("params")],
arguments=["--ros-args", "--log-level", LaunchConfiguration("log_level")],
remappings=[(la.default_value[0].text, LaunchConfiguration(la.name)) for la in remappable_topics],
output="screen",
emulate_tty=True,
)
Expand All @@ -44,5 +52,6 @@ def generate_launch_description():

return LaunchDescription([
*args,
SetParameter("use_sim_time", LaunchConfiguration("use_sim_time")),
*nodes,
])
11 changes: 10 additions & 1 deletion samples/ros2_cpp_component_pkg/launch/ros2_cpp_node_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.actions import Node, SetParameter


def generate_launch_description():

remappable_topics = [
DeclareLaunchArgument("input_topic", default_value="~/input"),
DeclareLaunchArgument("output_topic", default_value="~/output"),
]

args = [
DeclareLaunchArgument("name", default_value="ros2_cpp_node", description="node name"),
DeclareLaunchArgument("namespace", default_value="", description="node namespace"),
DeclareLaunchArgument("params", default_value=os.path.join(get_package_share_directory("ros2_cpp_component_pkg"), "config", "params.yml"), description="path to parameter file"),
DeclareLaunchArgument("log_level", default_value="info", description="ROS logging level (debug, info, warn, error, fatal)"),
DeclareLaunchArgument("use_sim_time", default_value="false", description="use simulation clock"),
*remappable_topics,
]

nodes = [
Expand All @@ -26,12 +33,14 @@ def generate_launch_description():
name=LaunchConfiguration("name"),
parameters=[LaunchConfiguration("params")],
arguments=["--ros-args", "--log-level", LaunchConfiguration("log_level")],
remappings=[(la.default_value[0].text, LaunchConfiguration(la.name)) for la in remappable_topics],
output="screen",
emulate_tty=True,
)
]

return LaunchDescription([
*args,
SetParameter("use_sim_time", LaunchConfiguration("use_sim_time")),
*nodes,
])
9 changes: 9 additions & 0 deletions samples/ros2_cpp_lifecycle_pkg/launch/ros2_cpp_node_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@

def generate_launch_description():

remappable_topics = [
DeclareLaunchArgument("input_topic", default_value="~/input"),
DeclareLaunchArgument("output_topic", default_value="~/output"),
]

args = [
DeclareLaunchArgument("name", default_value="ros2_cpp_node", description="node name"),
DeclareLaunchArgument("namespace", default_value="", description="node namespace"),
DeclareLaunchArgument("params", default_value=os.path.join(get_package_share_directory("ros2_cpp_lifecycle_pkg"), "config", "params.yml"), description="path to parameter file"),
DeclareLaunchArgument("log_level", default_value="info", description="ROS logging level (debug, info, warn, error, fatal)"),
DeclareLaunchArgument("startup_state", default_value="None", description="initial lifecycle state"),
DeclareLaunchArgument("use_sim_time", default_value="false", description="use simulation clock"),
*remappable_topics,
]

nodes = [
Expand All @@ -35,6 +42,7 @@ def generate_launch_description():
name=LaunchConfiguration("name"),
parameters=[LaunchConfiguration("params")],
arguments=["--ros-args", "--log-level", LaunchConfiguration("log_level")],
remappings=[(la.default_value[0].text, LaunchConfiguration(la.name)) for la in remappable_topics],
output="screen",
emulate_tty=True,
)
Expand All @@ -44,5 +52,6 @@ def generate_launch_description():

return LaunchDescription([
*args,
SetParameter("use_sim_time", LaunchConfiguration("use_sim_time")),
*nodes,
])
11 changes: 10 additions & 1 deletion samples/ros2_cpp_pkg/launch/ros2_cpp_node_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.actions import Node, SetParameter


def generate_launch_description():

remappable_topics = [
DeclareLaunchArgument("input_topic", default_value="~/input"),
DeclareLaunchArgument("output_topic", default_value="~/output"),
]

args = [
DeclareLaunchArgument("name", default_value="ros2_cpp_node", description="node name"),
DeclareLaunchArgument("namespace", default_value="", description="node namespace"),
DeclareLaunchArgument("params", default_value=os.path.join(get_package_share_directory("ros2_cpp_pkg"), "config", "params.yml"), description="path to parameter file"),
DeclareLaunchArgument("log_level", default_value="info", description="ROS logging level (debug, info, warn, error, fatal)"),
DeclareLaunchArgument("use_sim_time", default_value="false", description="use simulation clock"),
*remappable_topics,
]

nodes = [
Expand All @@ -26,12 +33,14 @@ def generate_launch_description():
name=LaunchConfiguration("name"),
parameters=[LaunchConfiguration("params")],
arguments=["--ros-args", "--log-level", LaunchConfiguration("log_level")],
remappings=[(la.default_value[0].text, LaunchConfiguration(la.name)) for la in remappable_topics],
output="screen",
emulate_tty=True,
)
]

return LaunchDescription([
*args,
SetParameter("use_sim_time", LaunchConfiguration("use_sim_time")),
*nodes,
])
11 changes: 10 additions & 1 deletion samples/ros2_python_all_pkg/launch/ros2_python_node_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.actions import Node, SetParameter


def generate_launch_description():

remappable_topics = [
DeclareLaunchArgument("input_topic", default_value="~/input"),
DeclareLaunchArgument("output_topic", default_value="~/output"),
]

args = [
DeclareLaunchArgument("name", default_value="ros2_python_node", description="node name"),
DeclareLaunchArgument("namespace", default_value="", description="node namespace"),
DeclareLaunchArgument("params", default_value=os.path.join(get_package_share_directory("ros2_python_all_pkg"), "config", "params.yml"), description="path to parameter file"),
DeclareLaunchArgument("log_level", default_value="info", description="ROS logging level (debug, info, warn, error, fatal)"),
DeclareLaunchArgument("use_sim_time", default_value="false", description="use simulation clock"),
*remappable_topics,
]

nodes = [
Expand All @@ -26,12 +33,14 @@ def generate_launch_description():
name=LaunchConfiguration("name"),
parameters=[LaunchConfiguration("params")],
arguments=["--ros-args", "--log-level", LaunchConfiguration("log_level")],
remappings=[(la.default_value[0].text, LaunchConfiguration(la.name)) for la in remappable_topics],
output="screen",
emulate_tty=True,
)
]

return LaunchDescription([
*args,
SetParameter("use_sim_time", LaunchConfiguration("use_sim_time")),
*nodes,
])
11 changes: 10 additions & 1 deletion samples/ros2_python_pkg/launch/ros2_python_node_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.actions import Node, SetParameter


def generate_launch_description():

remappable_topics = [
DeclareLaunchArgument("input_topic", default_value="~/input"),
DeclareLaunchArgument("output_topic", default_value="~/output"),
]

args = [
DeclareLaunchArgument("name", default_value="ros2_python_node", description="node name"),
DeclareLaunchArgument("namespace", default_value="", description="node namespace"),
DeclareLaunchArgument("params", default_value=os.path.join(get_package_share_directory("ros2_python_pkg"), "config", "params.yml"), description="path to parameter file"),
DeclareLaunchArgument("log_level", default_value="info", description="ROS logging level (debug, info, warn, error, fatal)"),
DeclareLaunchArgument("use_sim_time", default_value="false", description="use simulation clock"),
*remappable_topics,
]

nodes = [
Expand All @@ -26,12 +33,14 @@ def generate_launch_description():
name=LaunchConfiguration("name"),
parameters=[LaunchConfiguration("params")],
arguments=["--ros-args", "--log-level", LaunchConfiguration("log_level")],
remappings=[(la.default_value[0].text, LaunchConfiguration(la.name)) for la in remappable_topics],
output="screen",
emulate_tty=True,
)
]

return LaunchDescription([
*args,
SetParameter("use_sim_time", LaunchConfiguration("use_sim_time")),
*nodes,
])
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@ from launch_ros.actions import LifecycleNode, SetParameter
{% else %}
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.actions import Node, SetParameter
{% endif %}


def generate_launch_description():

remappable_topics = [
{% if has_subscriber %}
DeclareLaunchArgument("input_topic", default_value="~/input"),
{% endif %}
{% if has_publisher %}
DeclareLaunchArgument("output_topic", default_value="~/output"),
{% endif %}
]

args = [
DeclareLaunchArgument("name", default_value="{{ node_name }}", description="node name"),
DeclareLaunchArgument("namespace", default_value="", description="node namespace"),
Expand All @@ -26,6 +35,8 @@ def generate_launch_description():
{% if is_lifecycle %}
DeclareLaunchArgument("startup_state", default_value="None", description="initial lifecycle state"),
{% endif %}
DeclareLaunchArgument("use_sim_time", default_value="false", description="use simulation clock"),
*remappable_topics,
]

{% if is_lifecycle %}
Expand All @@ -48,6 +59,7 @@ def generate_launch_description():
parameters=[],
{% endif %}
arguments=["--ros-args", "--log-level", LaunchConfiguration("log_level")],
remappings=[(la.default_value[0].text, LaunchConfiguration(la.name)) for la in remappable_topics],
output="screen",
emulate_tty=True,
)
Expand All @@ -67,6 +79,7 @@ def generate_launch_description():
parameters=[],
{% endif %}
arguments=["--ros-args", "--log-level", LaunchConfiguration("log_level")],
remappings=[(la.default_value[0].text, LaunchConfiguration(la.name)) for la in remappable_topics],
output="screen",
emulate_tty=True,
)
Expand All @@ -75,5 +88,6 @@ def generate_launch_description():

return LaunchDescription([
*args,
SetParameter("use_sim_time", LaunchConfiguration("use_sim_time")),
*nodes,
])
Loading

0 comments on commit 14c49a9

Please sign in to comment.