Skip to content

Commit 0454f04

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 3739ff1 commit 0454f04

File tree

2 files changed

+411
-0
lines changed

2 files changed

+411
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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+
from launch import LaunchDescription
19+
from launch.actions import (DeclareLaunchArgument, IncludeLaunchDescription, SetEnvironmentVariable)
20+
from launch.launch_description_sources import PythonLaunchDescriptionSource
21+
from launch.substitutions import LaunchConfiguration
22+
from nav2_common.launch import ReplaceString
23+
24+
def generate_launch_description():
25+
# Get the launch directory
26+
bringup_dir = get_package_share_directory('nav2_bringup')
27+
launch_dir = os.path.join(bringup_dir, 'launch')
28+
29+
# Create the launch configuration variables
30+
namespace = LaunchConfiguration('namespace')
31+
use_namespace = LaunchConfiguration('use_namespace')
32+
slam = LaunchConfiguration('slam')
33+
map_yaml_file = LaunchConfiguration('map')
34+
use_sim_time = LaunchConfiguration('use_sim_time')
35+
params_file = LaunchConfiguration('params_file')
36+
autostart = LaunchConfiguration('autostart')
37+
use_composition = LaunchConfiguration('use_composition')
38+
use_respawn = LaunchConfiguration('use_respawn')
39+
log_level = LaunchConfiguration('log_level')
40+
41+
multirobot_params_file = ReplaceString(
42+
source_file=params_file,
43+
replacements={'<robot_namespace>': (namespace)})
44+
45+
stdout_linebuf_envvar = SetEnvironmentVariable(
46+
'RCUTILS_LOGGING_BUFFERED_STREAM', '1')
47+
48+
declare_namespace_cmd = DeclareLaunchArgument(
49+
'namespace',
50+
default_value='',
51+
description='Top-level namespace')
52+
53+
declare_use_namespace_cmd = DeclareLaunchArgument(
54+
'use_namespace',
55+
default_value='false',
56+
description='Whether to apply a namespace to the navigation stack')
57+
58+
declare_slam_cmd = DeclareLaunchArgument(
59+
'slam',
60+
default_value='False',
61+
description='Whether run a SLAM')
62+
63+
declare_map_yaml_cmd = DeclareLaunchArgument(
64+
'map',
65+
default_value='',
66+
description='Full path to map yaml file to load')
67+
68+
declare_use_sim_time_cmd = DeclareLaunchArgument(
69+
'use_sim_time',
70+
default_value='false',
71+
description='Use simulation (Gazebo) clock if true')
72+
73+
declare_params_file_cmd = DeclareLaunchArgument(
74+
'params_file',
75+
default_value=os.path.join(bringup_dir, 'params', 'nav2_multirobot_params.yaml'),
76+
description='Full path to the ROS2 parameters file to use for all launched nodes')
77+
78+
declare_autostart_cmd = DeclareLaunchArgument(
79+
'autostart', default_value='true',
80+
description='Automatically startup the nav2 stack')
81+
82+
declare_use_composition_cmd = DeclareLaunchArgument(
83+
'use_composition', default_value='True',
84+
description='Whether to use composed bringup')
85+
86+
declare_use_respawn_cmd = DeclareLaunchArgument(
87+
'use_respawn', default_value='False',
88+
description='Whether to respawn if a node crashes. Applied when composition is disabled.')
89+
90+
declare_log_level_cmd = DeclareLaunchArgument(
91+
'log_level', default_value='info',
92+
description='log level')
93+
94+
# Specify the actions
95+
bringup_cmd_with_multirobot_params = IncludeLaunchDescription(
96+
PythonLaunchDescriptionSource(os.path.join(launch_dir, 'bringup_launch.py')),
97+
launch_arguments={'namespace': namespace,
98+
'use_namespace': use_namespace,
99+
'slam': slam,
100+
'map': map_yaml_file,
101+
'use_sim_time': use_sim_time,
102+
'autostart': autostart,
103+
'use_respawn': use_respawn,
104+
'use_composition': use_composition,
105+
'log_level': log_level,
106+
'params_file': multirobot_params_file}.items())
107+
108+
# Create the launch description and populate
109+
ld = LaunchDescription()
110+
111+
# Set environment variables
112+
ld.add_action(stdout_linebuf_envvar)
113+
114+
# Declare the launch options
115+
ld.add_action(declare_namespace_cmd)
116+
ld.add_action(declare_use_namespace_cmd)
117+
ld.add_action(declare_slam_cmd)
118+
ld.add_action(declare_map_yaml_cmd)
119+
ld.add_action(declare_use_sim_time_cmd)
120+
ld.add_action(declare_params_file_cmd)
121+
ld.add_action(declare_autostart_cmd)
122+
ld.add_action(declare_use_composition_cmd)
123+
ld.add_action(declare_use_respawn_cmd)
124+
ld.add_action(declare_log_level_cmd)
125+
126+
# Add the actions to launch all of the navigation nodes
127+
ld.add_action(bringup_cmd_with_multirobot_params)
128+
129+
return ld

0 commit comments

Comments
 (0)