From ee947fcaa8be49d8e9e2f42d4d1e1f0a301536e2 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Mon, 5 May 2025 09:12:41 -0700 Subject: [PATCH] Add 'repetition' example using ForLoop action Signed-off-by: Christophe Bedard --- donatello/launch/12-repetition.launch.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 donatello/launch/12-repetition.launch.py diff --git a/donatello/launch/12-repetition.launch.py b/donatello/launch/12-repetition.launch.py new file mode 100644 index 0000000..3acdb27 --- /dev/null +++ b/donatello/launch/12-repetition.launch.py @@ -0,0 +1,19 @@ +import launch +from launch.actions import DeclareLaunchArgument, ForLoop +from launch.substitutions import LaunchConfiguration +import launch_ros.actions + + +def for_i(i: int): + return [ + # i will be [0, N), so use i+1 to get [1, N] + launch_ros.actions.Node(name=['donatello_node', str(i + 1)], + package='donatello', executable='donatello_node'), + ] + + +def generate_launch_description(): + return launch.LaunchDescription([ + DeclareLaunchArgument('N', default_value='10'), + ForLoop(LaunchConfiguration('N'), function=for_i), + ])