Skip to content

Commit afe7581

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 593c4ca commit afe7581

File tree

2 files changed

+416
-0
lines changed

2 files changed

+416
-0
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
slam = LaunchConfiguration('slam')
32+
map_yaml_file = LaunchConfiguration('map')
33+
use_sim_time = LaunchConfiguration('use_sim_time')
34+
params_file = LaunchConfiguration('params_file')
35+
autostart = LaunchConfiguration('autostart')
36+
use_composition = LaunchConfiguration('use_composition')
37+
use_respawn = LaunchConfiguration('use_respawn')
38+
log_level = LaunchConfiguration('log_level')
39+
40+
# '<robot_namespace>' keyword shall be replaced by 'namespace' launch argument
41+
# in config file 'nav2_namespaced_params.yaml' as a default.
42+
# User defined config file should containe '<robot_namespace>' keyword
43+
# for the proper parameter wherever you want to get parameters thet namespace applied.
44+
namespaced_replaced_params_file = ReplaceString(
45+
source_file=params_file,
46+
replacements={'<robot_namespace>': (namespace)})
47+
48+
stdout_linebuf_envvar = SetEnvironmentVariable(
49+
'RCUTILS_LOGGING_BUFFERED_STREAM', '1')
50+
51+
declare_namespace_cmd = DeclareLaunchArgument(
52+
'namespace',
53+
default_value='robot0',
54+
description='Top-level namespace')
55+
56+
declare_slam_cmd = DeclareLaunchArgument(
57+
'slam',
58+
default_value='False',
59+
description='Whether run a SLAM')
60+
61+
declare_map_yaml_cmd = DeclareLaunchArgument(
62+
'map',
63+
default_value='',
64+
description='Full path to map yaml file to load')
65+
66+
declare_use_sim_time_cmd = DeclareLaunchArgument(
67+
'use_sim_time',
68+
default_value='false',
69+
description='Use simulation (Gazebo) clock if true')
70+
71+
declare_params_file_cmd = DeclareLaunchArgument(
72+
'params_file',
73+
default_value=os.path.join(bringup_dir, 'params', 'nav2_multirobot_params.yaml'),
74+
description='Full path to the ROS2 parameters file to use for all launched nodes')
75+
76+
declare_autostart_cmd = DeclareLaunchArgument(
77+
'autostart', default_value='true',
78+
description='Automatically startup the nav2 stack')
79+
80+
declare_use_composition_cmd = DeclareLaunchArgument(
81+
'use_composition', default_value='True',
82+
description='Whether to use composed bringup')
83+
84+
declare_use_respawn_cmd = DeclareLaunchArgument(
85+
'use_respawn', default_value='False',
86+
description='Whether to respawn if a node crashes. Applied when composition is disabled.')
87+
88+
declare_log_level_cmd = DeclareLaunchArgument(
89+
'log_level', default_value='info',
90+
description='log level')
91+
92+
# Specify the actions
93+
bringup_with_namespace_cmd_params = IncludeLaunchDescription(
94+
PythonLaunchDescriptionSource(os.path.join(launch_dir, 'bringup_launch.py')),
95+
launch_arguments={'namespace': namespace,
96+
'use_namespace': True,
97+
'slam': slam,
98+
'map': map_yaml_file,
99+
'use_sim_time': use_sim_time,
100+
'autostart': autostart,
101+
'use_respawn': use_respawn,
102+
'use_composition': use_composition,
103+
'log_level': log_level,
104+
'params_file': namespaced_replaced_params_file}.items())
105+
106+
# Create the launch description and populate
107+
ld = LaunchDescription()
108+
109+
# Set environment variables
110+
ld.add_action(stdout_linebuf_envvar)
111+
112+
# Declare the launch options
113+
ld.add_action(declare_namespace_cmd)
114+
ld.add_action(declare_slam_cmd)
115+
ld.add_action(declare_map_yaml_cmd)
116+
ld.add_action(declare_use_sim_time_cmd)
117+
ld.add_action(declare_params_file_cmd)
118+
ld.add_action(declare_autostart_cmd)
119+
ld.add_action(declare_use_composition_cmd)
120+
ld.add_action(declare_use_respawn_cmd)
121+
ld.add_action(declare_log_level_cmd)
122+
123+
# Add the actions to launch all of the navigation nodes
124+
ld.add_action(bringup_with_namespace_cmd_params)
125+
126+
return ld

0 commit comments

Comments
 (0)