15 """This is all-in-one launch script intended for use by nav2 developers."""
19 from ament_index_python.packages
import get_package_share_directory
20 from launch
import LaunchDescription
21 from launch.actions
import DeclareLaunchArgument, GroupAction, IncludeLaunchDescription
22 from launch.conditions
import IfCondition
23 from launch.launch_description_sources
import PythonLaunchDescriptionSource
24 from launch.substitutions
import LaunchConfiguration, PythonExpression
25 from launch_ros.actions
import LoadComposableNodes, Node, SetParameter
26 from launch_ros.descriptions
import ComposableNode, ParameterFile
30 def generate_launch_description() -> LaunchDescription:
32 bringup_dir = get_package_share_directory(
'nav2_bringup')
33 loopback_sim_dir = get_package_share_directory(
'nav2_loopback_sim')
34 launch_dir = os.path.join(bringup_dir,
'launch')
35 sim_dir = get_package_share_directory(
'nav2_minimal_tb3_sim')
38 namespace = LaunchConfiguration(
'namespace')
39 map_yaml_file = LaunchConfiguration(
'map')
40 graph_filepath = LaunchConfiguration(
'graph')
41 params_file = LaunchConfiguration(
'params_file')
42 autostart = LaunchConfigAsBool(
'autostart')
43 use_composition = LaunchConfigAsBool(
'use_composition')
44 use_intra_process_comms = LaunchConfigAsBool(
'use_intra_process_comms')
45 use_respawn = LaunchConfigAsBool(
'use_respawn')
48 rviz_config_file = LaunchConfiguration(
'rviz_config_file')
49 use_robot_state_pub = LaunchConfigAsBool(
'use_robot_state_pub')
50 use_rviz = LaunchConfigAsBool(
'use_rviz')
51 container_name_full = (namespace,
'/',
'nav2_container')
53 remappings = [(
'/tf',
'tf'), (
'/tf_static',
'tf_static')]
56 declare_namespace_cmd = DeclareLaunchArgument(
57 'namespace', default_value=
'', description=
'Top-level namespace'
60 declare_map_yaml_cmd = DeclareLaunchArgument(
62 default_value=os.path.join(bringup_dir,
'maps',
'tb3_sandbox.yaml'),
65 declare_graph_file_cmd = DeclareLaunchArgument(
67 default_value=os.path.join(bringup_dir,
'graphs',
'turtlebot3_graph.geojson'),
70 declare_params_file_cmd = DeclareLaunchArgument(
72 default_value=os.path.join(bringup_dir,
'params',
'nav2_params.yaml'),
73 description=
'Full path to the ROS2 parameters file to use for all launched nodes',
76 declare_autostart_cmd = DeclareLaunchArgument(
79 description=
'Automatically startup the nav2 stack',
82 declare_use_composition_cmd = DeclareLaunchArgument(
85 description=
'Whether to use composed bringup',
88 declare_use_intra_process_comms_cmd = DeclareLaunchArgument(
89 'use_intra_process_comms',
90 default_value=
'False',
91 description=
'Whether to use intra process communication',
94 declare_use_respawn_cmd = DeclareLaunchArgument(
96 default_value=
'False',
97 description=
'Whether to respawn if a node crashes. Applied when composition is disabled.',
100 declare_rviz_config_file_cmd = DeclareLaunchArgument(
102 default_value=os.path.join(bringup_dir,
'rviz',
'nav2_default_view.rviz'),
103 description=
'Full path to the RVIZ config file to use',
106 declare_use_robot_state_pub_cmd = DeclareLaunchArgument(
107 'use_robot_state_pub',
108 default_value=
'True',
109 description=
'Whether to start the robot state publisher',
112 declare_use_rviz_cmd = DeclareLaunchArgument(
113 'use_rviz', default_value=
'True', description=
'Whether to start RVIZ'
116 urdf = os.path.join(sim_dir,
'urdf',
'turtlebot3_waffle.urdf')
117 with open(urdf,
'r')
as infp:
118 robot_description = infp.read()
120 start_robot_state_publisher_cmd = Node(
121 condition=IfCondition(use_robot_state_pub),
122 package=
'robot_state_publisher',
123 executable=
'robot_state_publisher',
124 name=
'robot_state_publisher',
128 {
'use_sim_time':
True,
'robot_description': robot_description}
130 remappings=remappings,
133 rviz_cmd = IncludeLaunchDescription(
134 PythonLaunchDescriptionSource(os.path.join(launch_dir,
'rviz_launch.py')),
135 condition=IfCondition(use_rviz),
137 (
'namespace', namespace),
138 (
'use_sim_time',
'True'),
139 (
'rviz_config', rviz_config_file),
143 bringup_cmd = IncludeLaunchDescription(
144 PythonLaunchDescriptionSource(os.path.join(launch_dir,
'bringup_launch.py')),
146 'namespace': namespace,
147 'map': map_yaml_file,
148 'graph': graph_filepath,
149 'use_sim_time':
'True',
150 'params_file': params_file,
151 'autostart': autostart,
152 'use_composition': use_composition,
153 'use_intra_process_comms': use_intra_process_comms,
154 'use_respawn': use_respawn,
155 'use_localization':
'False',
156 'use_keepout_zones':
'False',
157 'use_speed_zones':
'False',
158 'container_name':
'nav2_container',
162 loopback_sim_cmd = IncludeLaunchDescription(
163 PythonLaunchDescriptionSource(
164 os.path.join(loopback_sim_dir,
'loopback_simulation.launch.py')),
166 'params_file': params_file,
170 configured_params = ParameterFile(
172 source_file=params_file,
180 start_map_server = GroupAction(
181 condition=IfCondition(PythonExpression([
'not ', use_composition])),
183 SetParameter(
'use_sim_time',
True),
185 package=
'nav2_map_server',
186 executable=
'map_server',
191 parameters=[configured_params, {
'yaml_filename': map_yaml_file}],
192 remappings=remappings,
195 package=
'nav2_lifecycle_manager',
196 executable=
'lifecycle_manager',
197 name=
'lifecycle_manager_map_server',
201 {
'autostart': autostart}, {
'node_names': [
'map_server']}],
206 start_composable_map_server = GroupAction(
207 condition=IfCondition(use_composition),
209 SetParameter(
'use_sim_time',
True),
211 target_container=container_name_full,
212 composable_node_descriptions=[
214 package=
'nav2_map_server',
215 plugin=
'nav2_map_server::MapServer',
217 parameters=[configured_params, {
'yaml_filename': map_yaml_file}],
218 remappings=remappings,
219 extra_arguments=[{
'use_intra_process_comms': use_intra_process_comms}],
222 package=
'nav2_lifecycle_manager',
223 plugin=
'nav2_lifecycle_manager::LifecycleManager',
224 name=
'lifecycle_manager_map_server',
227 {
'autostart': autostart}, {
'node_names': [
'map_server']}
229 extra_arguments=[{
'use_intra_process_comms': use_intra_process_comms}],
237 ld = LaunchDescription()
240 ld.add_action(declare_namespace_cmd)
241 ld.add_action(declare_map_yaml_cmd)
242 ld.add_action(declare_graph_file_cmd)
243 ld.add_action(declare_params_file_cmd)
244 ld.add_action(declare_autostart_cmd)
245 ld.add_action(declare_use_composition_cmd)
246 ld.add_action(declare_use_intra_process_comms_cmd)
248 ld.add_action(declare_rviz_config_file_cmd)
249 ld.add_action(declare_use_robot_state_pub_cmd)
250 ld.add_action(declare_use_rviz_cmd)
251 ld.add_action(declare_use_respawn_cmd)
254 ld.add_action(start_robot_state_publisher_cmd)
255 ld.add_action(start_map_server)
256 ld.add_action(start_composable_map_server)
257 ld.add_action(loopback_sim_cmd)
258 ld.add_action(rviz_cmd)
259 ld.add_action(bringup_cmd)