Skip to content

Commit bbbe990

Browse files
committed
Make it possible to launch multi-robot which rewrites <robot_namespace> to namespace.
Automatically apply namespace on specific target topic path in costmap plugins. re-utilize navigation_launch file. add new params file for multi-robot -> nav2_multirobot_params.yaml
1 parent 9b56556 commit bbbe990

File tree

3 files changed

+413
-0
lines changed

3 files changed

+413
-0
lines changed

nav2_bringup/launch/bringup_launch.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def generate_launch_description():
4242
autostart = LaunchConfiguration('autostart')
4343
use_composition = LaunchConfiguration('use_composition')
4444
use_respawn = LaunchConfiguration('use_respawn')
45+
use_multirobot = LaunchConfiguration('use_multirobot')
4546
log_level = LaunchConfiguration('log_level')
4647

4748
# Map fully qualified names to relative ones so the node's namespace can be prepended.
@@ -104,6 +105,10 @@ def generate_launch_description():
104105
'use_respawn', default_value='False',
105106
description='Whether to respawn if a node crashes. Applied when composition is disabled.')
106107

108+
declare_use_multirobot_cmd = DeclareLaunchArgument(
109+
'use_multirobot', default_value='False',
110+
description='Whether to launch multi-robot. Applied a namespace in parameters file.')
111+
107112
declare_log_level_cmd = DeclareLaunchArgument(
108113
'log_level', default_value='info',
109114
description='log level')
@@ -148,6 +153,18 @@ def generate_launch_description():
148153

149154
IncludeLaunchDescription(
150155
PythonLaunchDescriptionSource(os.path.join(launch_dir, 'navigation_launch.py')),
156+
condition=IfCondition(PythonExpression(['not ', use_multirobot])),
157+
launch_arguments={'namespace': namespace,
158+
'use_sim_time': use_sim_time,
159+
'autostart': autostart,
160+
'params_file': params_file,
161+
'use_composition': use_composition,
162+
'use_respawn': use_respawn,
163+
'container_name': 'nav2_container'}.items()),
164+
165+
IncludeLaunchDescription(
166+
PythonLaunchDescriptionSource(os.path.join(launch_dir, 'multirobot_navigation_launch.py')),
167+
condition=IfCondition(PythonExpression(use_multirobot)),
151168
launch_arguments={'namespace': namespace,
152169
'use_sim_time': use_sim_time,
153170
'autostart': autostart,
@@ -173,6 +190,7 @@ def generate_launch_description():
173190
ld.add_action(declare_autostart_cmd)
174191
ld.add_action(declare_use_composition_cmd)
175192
ld.add_action(declare_use_respawn_cmd)
193+
ld.add_action(declare_use_multirobot_cmd)
176194
ld.add_action(declare_log_level_cmd)
177195

178196
# Add the actions to launch all of the navigation nodes
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Copyright (c) 2018 Intel Corporation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
17+
from ament_index_python.packages import get_package_share_directory
18+
19+
from launch import LaunchDescription
20+
from launch.actions import DeclareLaunchArgument, GroupAction, IncludeLaunchDescription, SetEnvironmentVariable
21+
from launch.launch_description_sources import PythonLaunchDescriptionSource
22+
from launch.substitutions import LaunchConfiguration
23+
from nav2_common.launch import ReplaceString
24+
25+
26+
def generate_launch_description():
27+
# Get the launch directory
28+
bringup_dir = get_package_share_directory('nav2_bringup')
29+
launch_dir = os.path.join(bringup_dir, 'launch')
30+
31+
namespace = LaunchConfiguration('namespace')
32+
use_sim_time = LaunchConfiguration('use_sim_time')
33+
autostart = LaunchConfiguration('autostart')
34+
params_file = LaunchConfiguration('params_file')
35+
use_composition = LaunchConfiguration('use_composition')
36+
container_name = LaunchConfiguration('container_name')
37+
use_respawn = LaunchConfiguration('use_respawn')
38+
log_level = LaunchConfiguration('log_level')
39+
40+
configured_multi_robot_params = ReplaceString(
41+
source_file=params_file,
42+
replacements={'<robot_namespace>': (namespace)})
43+
44+
stdout_linebuf_envvar = SetEnvironmentVariable(
45+
'RCUTILS_LOGGING_BUFFERED_STREAM', '1')
46+
47+
declare_namespace_cmd = DeclareLaunchArgument(
48+
'namespace',
49+
default_value='',
50+
description='Top-level namespace')
51+
52+
declare_use_sim_time_cmd = DeclareLaunchArgument(
53+
'use_sim_time',
54+
default_value='false',
55+
description='Use simulation (Gazebo) clock if true')
56+
57+
declare_params_file_cmd = DeclareLaunchArgument(
58+
'params_file',
59+
default_value=os.path.join(bringup_dir, 'params', 'nav2_params.yaml'),
60+
description='Full path to the ROS2 parameters file to use for all launched nodes')
61+
62+
declare_autostart_cmd = DeclareLaunchArgument(
63+
'autostart', default_value='true',
64+
description='Automatically startup the nav2 stack')
65+
66+
declare_use_composition_cmd = DeclareLaunchArgument(
67+
'use_composition', default_value='False',
68+
description='Use composed bringup if True')
69+
70+
declare_container_name_cmd = DeclareLaunchArgument(
71+
'container_name', default_value='nav2_container',
72+
description='the name of conatiner that nodes will load in if use composition')
73+
74+
declare_use_respawn_cmd = DeclareLaunchArgument(
75+
'use_respawn', default_value='False',
76+
description='Whether to respawn if a node crashes. Applied when composition is disabled.')
77+
78+
declare_log_level_cmd = DeclareLaunchArgument(
79+
'log_level', default_value='info',
80+
description='log level')
81+
82+
bringup_cmd_group = GroupAction([
83+
IncludeLaunchDescription(
84+
PythonLaunchDescriptionSource(os.path.join(launch_dir, 'navigation_launch.py')),
85+
launch_arguments={'namespace': namespace,
86+
'use_sim_time': use_sim_time,
87+
'autostart': autostart,
88+
'params_file': configured_multi_robot_params,
89+
'use_composition': use_composition,
90+
'use_respawn': use_respawn,
91+
'container_name': container_name,
92+
'log_level': log_level}.items())
93+
])
94+
95+
# Create the launch description and populate
96+
ld = LaunchDescription()
97+
98+
# Set environment variables
99+
ld.add_action(stdout_linebuf_envvar)
100+
101+
# Declare the launch options
102+
ld.add_action(declare_namespace_cmd)
103+
ld.add_action(declare_use_sim_time_cmd)
104+
ld.add_action(declare_params_file_cmd)
105+
ld.add_action(declare_autostart_cmd)
106+
ld.add_action(declare_use_composition_cmd)
107+
ld.add_action(declare_container_name_cmd)
108+
ld.add_action(declare_use_respawn_cmd)
109+
ld.add_action(declare_log_level_cmd)
110+
111+
ld.add_action(bringup_cmd_group)
112+
113+
return ld

0 commit comments

Comments
 (0)