Skip to content

Commit

Permalink
Merge pull request #440 from IMRCLab/issue433
Browse files Browse the repository at this point in the history
crazyflie_examples: add launch.py
  • Loading branch information
knmcguire authored Feb 27, 2024
2 parents 261f3e8 + dc7491e commit e818576
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
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

0 comments on commit e818576

Please sign in to comment.