Skip to content

Commit

Permalink
Update launch tutorials for Foxy (#525)
Browse files Browse the repository at this point in the history
Specifically, I've made updates that reflect the change made in ros2/launch_ros#122

Signed-off-by: Jacob Perron <jacob@openrobotics.org>
  • Loading branch information
ferranm99 committed Mar 5, 2020
1 parent f17071e commit 05bd125
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 71 deletions.
181 changes: 127 additions & 54 deletions source/Tutorials/Launch-Files/Creating-Launch-Files.rst
Expand Up @@ -79,36 +79,71 @@ Let’s put together a ROS 2 launch file using the ``turtlesim`` package and its

Copy and paste the complete code into the ``turtlesim_mimic_launch.py`` file:

.. code-block:: python
from launch import LaunchDescription
from launch_ros.actions import Node
def generate_launch_description():
return LaunchDescription([
Node(
package='turtlesim',
node_namespace='turtlesim1',
node_executable='turtlesim_node',
node_name='sim'
),
Node(
package='turtlesim',
node_namespace='turtlesim2',
node_executable='turtlesim_node',
node_name='sim'
),
Node(
package='turtlesim',
node_executable='mimic',
node_name='mimic',
remappings=[
('/input/pose', '/turtlesim1/turtle1/pose'),
('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'),
]
)
])
.. tabs::

.. group-tab:: Dashing or Eloquent

.. code-block:: python
from launch import LaunchDescription
from launch_ros.actions import Node
def generate_launch_description():
return LaunchDescription([
Node(
package='turtlesim',
node_namespace='turtlesim1',
node_executable='turtlesim_node',
node_name='sim'
),
Node(
package='turtlesim',
node_namespace='turtlesim2',
node_executable='turtlesim_node',
node_name='sim'
),
Node(
package='turtlesim',
node_executable='mimic',
node_name='mimic',
remappings=[
('/input/pose', '/turtlesim1/turtle1/pose'),
('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'),
]
)
])
.. group-tab:: Foxy or newer

.. code-block:: python
from launch import LaunchDescription
from launch_ros.actions import Node
def generate_launch_description():
return LaunchDescription([
Node(
package='turtlesim',
namespace='turtlesim1',
executable='turtlesim_node',
name='sim'
),
Node(
package='turtlesim',
namespace='turtlesim2',
executable='turtlesim_node',
name='sim'
),
Node(
package='turtlesim',
executable='mimic',
name='mimic',
remappings=[
('/input/pose', '/turtlesim1/turtle1/pose'),
('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'),
]
)
])
2.1 Examine the launch file
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -134,41 +169,79 @@ The goal of the system is to launch two turtlesim windows, and have one turtle m

The first two actions in the launch description launch two turtlesim windows:

.. code-block:: python
.. tabs::

Node(
package='turtlesim',
node_namespace='turtlesim1',
node_executable='turtlesim_node',
node_name='sim'
),
Node(
package='turtlesim',
node_namespace='turtlesim2',
node_executable='turtlesim_node',
node_name='sim'
),
Note the only difference between the two nodes is their ``node_namespace`` values.
.. group-tab:: Dashing or Eloquent

.. code-block:: python
Node(
package='turtlesim',
node_namespace='turtlesim1',
node_executable='turtlesim_node',
node_name='sim'
),
Node(
package='turtlesim',
node_namespace='turtlesim2',
node_executable='turtlesim_node',
node_name='sim'
),
.. group-tab:: Foxy or newer

.. code-block:: python
Node(
package='turtlesim',
namespace='turtlesim1',
executable='turtlesim_node',
name='sim'
),
Node(
package='turtlesim',
namespace='turtlesim2',
executable='turtlesim_node',
name='sim'
),
Note the only difference between the two nodes is their namespace values.
Unique namespaces allow the system to start two simulators without node name nor topic name conflicts.

Both turtles in this system receive commands over the same topic and publish their pose over the same topic.
Without unique namespaces, there would be no way to distinguish between messages meant for one turtle or the other.

The final node is also from the ``turtlesim`` package, but a different executable: ``mimic``.

.. code-block:: python
.. tabs::

.. group-tab:: Dashing or Eloquent

.. code-block:: python
Node(
package='turtlesim',
node_executable='mimic',
node_name='mimic',
remappings=[
('/input/pose', '/turtlesim1/turtle1/pose'),
('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'),
]
)
.. group-tab:: Foxy or newer

Node(
package='turtlesim',
node_executable='mimic',
node_name='mimic',
remappings=[
('/input/pose', '/turtlesim1/turtle1/pose'),
('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'),
]
)
.. code-block:: python
Node(
package='turtlesim',
executable='mimic',
name='mimic',
remappings=[
('/input/pose', '/turtlesim1/turtle1/pose'),
('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'),
]
)
This node has added configuration details in the form of remappings.

Expand Down
60 changes: 43 additions & 17 deletions source/Tutorials/Launch-system.rst
Expand Up @@ -81,24 +81,50 @@ Inside your launch directory, create a new launch file with the ``.launch.py`` s
For example ``my_script.launch.py``.
Your launch file should define the ``generate_launch_description()`` which returns a ``launch.LaunchDescription()`` to be used by the ``ros2 launch`` verb.

.. code-block:: python
.. tabs::

.. group-tab:: Dashing or Eloquent

.. code-block:: python
import launch
import launch.actions
import launch.substitutions
import launch_ros.actions
def generate_launch_description():
return launch.LaunchDescription([
launch.actions.DeclareLaunchArgument(
'node_prefix',
default_value=[launch.substitutions.EnvironmentVariable('USER'), '_'],
description='Prefix for node names'),
launch_ros.actions.Node(
package='demo_nodes_cpp', node_executable='talker', output='screen',
node_name=[launch.substitutions.LaunchConfiguration('node_prefix'), 'talker']),
])
.. group-tab:: Foxy or newer

.. code-block:: python
import launch
import launch.actions
import launch.substitutions
import launch_ros.actions
def generate_launch_description():
return launch.LaunchDescription([
launch.actions.DeclareLaunchArgument(
'node_prefix',
default_value=[launch.substitutions.EnvironmentVariable('USER'), '_'],
description='Prefix for node names'),
launch_ros.actions.Node(
package='demo_nodes_cpp', executable='talker', output='screen',
name=[launch.substitutions.LaunchConfiguration('node_prefix'), 'talker']),
])
import launch
import launch.actions
import launch.substitutions
import launch_ros.actions
def generate_launch_description():
return launch.LaunchDescription([
launch.actions.DeclareLaunchArgument(
'node_prefix',
default_value=[launch.substitutions.EnvironmentVariable('USER'), '_'],
description='Prefix for node names'),
launch_ros.actions.Node(
package='demo_nodes_cpp', node_executable='talker', output='screen',
node_name=[launch.substitutions.LaunchConfiguration('node_prefix'), 'talker']),
])
Usage
^^^^^
Expand Down

0 comments on commit 05bd125

Please sign in to comment.