From dc7491e6bb85b34a74329e1966318aad9b3e6bd0 Mon Sep 17 00:00:00 2001 From: Wolfgang Hoenig Date: Sun, 25 Feb 2024 22:00:43 +0100 Subject: [PATCH] crazyflie_examples: add launch.py --- crazyflie_examples/launch/launch.py | 50 +++++++++++++++++++++++++++++ docs2/usage.rst | 12 +++++++ 2 files changed, 62 insertions(+) create mode 100644 crazyflie_examples/launch/launch.py diff --git a/crazyflie_examples/launch/launch.py b/crazyflie_examples/launch/launch.py new file mode 100644 index 000000000..2b2e82e82 --- /dev/null +++ b/crazyflie_examples/launch/launch.py @@ -0,0 +1,50 @@ +import os + +from ament_index_python.packages import get_package_share_directory + + +from launch import LaunchDescription +from launch.actions import DeclareLaunchArgument +from launch.actions import IncludeLaunchDescription +from launch.launch_description_sources import PythonLaunchDescriptionSource +from launch.substitutions import LaunchConfiguration, PythonExpression +from launch_ros.actions import Node + + +def generate_launch_description(): + script = LaunchConfiguration('script') + backend = LaunchConfiguration('backend') + + script_launch_arg = DeclareLaunchArgument( + 'script' + ) + + backend_launch_arg = DeclareLaunchArgument( + 'backend', + default_value='cpp' + ) + + crazyflie = IncludeLaunchDescription( + PythonLaunchDescriptionSource([os.path.join( + get_package_share_directory('crazyflie'), 'launch'), + '/launch.py']), + launch_arguments={ + 'backend': backend, + }.items() + ) + + example_node = Node( + package='crazyflie_examples', + executable=script, + name=script, + parameters=[{ + 'use_sim_time': PythonExpression(["'", backend, "' == 'sim'"]), + }] + ) + + return LaunchDescription([ + script_launch_arg, + backend_launch_arg, + crazyflie, + example_node + ]) diff --git a/docs2/usage.rst b/docs2/usage.rst index 52117f0ae..74caf33d9 100644 --- a/docs2/usage.rst +++ b/docs2/usage.rst @@ -127,6 +127,12 @@ The configuration of the simulation (physics simulator, controller, etc.) can be Example: +.. code-block:: bash + + [terminal]$ ros2 launch crazyflie_examples launch.py script:=hello_world backend:=sim + +which is a short-hand for the following two commands: + .. code-block:: bash [terminal1]$ ros2 launch crazyflie launch.py backend:=sim @@ -156,6 +162,12 @@ You may run the script multiple times or different scripts while leaving the ser [terminal1]$ ros2 launch crazyflie launch.py [terminal2]$ ros2 run crazyflie_examples hello_world +If you only want to run a single script once, you can also use: + +.. code-block:: bash + + [terminal]$ ros2 launch crazyflie_examples launch.py script:=hello_world + Swarm Management ----------------