Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crazyflie_examples: add launch.py #440

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions crazyflie_examples/launch/launch.py
Original file line number Diff line number Diff line change
@@ -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
])
12 changes: 12 additions & 0 deletions docs2/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
----------------

Expand Down
Loading