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, IncludeLaunchDescription
22 from launch.conditions
import IfCondition
23 from launch.launch_description_sources
import PythonLaunchDescriptionSource
24 from launch.substitutions
import LaunchConfiguration
25 from launch_ros.actions
import Node
29 def generate_launch_description() -> LaunchDescription:
31 bringup_dir = get_package_share_directory(
'nav2_bringup')
32 loopback_sim_dir = get_package_share_directory(
'nav2_loopback_sim')
33 launch_dir = os.path.join(bringup_dir,
'launch')
34 sim_dir = get_package_share_directory(
'nav2_minimal_tb3_sim')
37 namespace = LaunchConfiguration(
'namespace')
38 map_yaml_file = LaunchConfiguration(
'map')
39 graph_filepath = LaunchConfiguration(
'graph')
40 params_file = LaunchConfiguration(
'params_file')
41 autostart = LaunchConfigAsBool(
'autostart')
42 use_composition = LaunchConfigAsBool(
'use_composition')
43 use_intra_process_comms = LaunchConfigAsBool(
'use_intra_process_comms')
44 use_respawn = LaunchConfigAsBool(
'use_respawn')
47 rviz_config_file = LaunchConfiguration(
'rviz_config_file')
48 use_robot_state_pub = LaunchConfigAsBool(
'use_robot_state_pub')
49 use_rviz = LaunchConfigAsBool(
'use_rviz')
50 remappings = [(
'/tf',
'tf'), (
'/tf_static',
'tf_static')]
53 declare_namespace_cmd = DeclareLaunchArgument(
54 'namespace', default_value=
'', description=
'Top-level namespace'
57 declare_map_yaml_cmd = DeclareLaunchArgument(
59 default_value=os.path.join(bringup_dir,
'maps',
'tb3_sandbox.yaml'),
62 declare_graph_file_cmd = DeclareLaunchArgument(
64 default_value=os.path.join(bringup_dir,
'graphs',
'turtlebot3_graph.geojson'),
67 declare_params_file_cmd = DeclareLaunchArgument(
69 default_value=os.path.join(bringup_dir,
'params',
'nav2_params.yaml'),
70 description=
'Full path to the ROS2 parameters file to use for all launched nodes',
73 declare_autostart_cmd = DeclareLaunchArgument(
76 description=
'Automatically startup the nav2 stack',
79 declare_use_composition_cmd = DeclareLaunchArgument(
82 description=
'Whether to use composed bringup',
85 declare_use_intra_process_comms_cmd = DeclareLaunchArgument(
86 'use_intra_process_comms',
87 default_value=
'False',
88 description=
'Whether to use intra process communication',
91 declare_use_respawn_cmd = DeclareLaunchArgument(
93 default_value=
'False',
94 description=
'Whether to respawn if a node crashes. Applied when composition is disabled.',
97 declare_rviz_config_file_cmd = DeclareLaunchArgument(
99 default_value=os.path.join(bringup_dir,
'rviz',
'nav2_default_view.rviz'),
100 description=
'Full path to the RVIZ config file to use',
103 declare_use_robot_state_pub_cmd = DeclareLaunchArgument(
104 'use_robot_state_pub',
105 default_value=
'True',
106 description=
'Whether to start the robot state publisher',
109 declare_use_rviz_cmd = DeclareLaunchArgument(
110 'use_rviz', default_value=
'True', description=
'Whether to start RVIZ'
113 urdf = os.path.join(sim_dir,
'urdf',
'turtlebot3_waffle.urdf')
114 with open(urdf,
'r')
as infp:
115 robot_description = infp.read()
117 start_robot_state_publisher_cmd = Node(
118 condition=IfCondition(use_robot_state_pub),
119 package=
'robot_state_publisher',
120 executable=
'robot_state_publisher',
121 name=
'robot_state_publisher',
125 {
'use_sim_time':
True,
'robot_description': robot_description}
127 remappings=remappings,
130 rviz_cmd = IncludeLaunchDescription(
131 PythonLaunchDescriptionSource(os.path.join(launch_dir,
'rviz_launch.py')),
132 condition=IfCondition(use_rviz),
134 (
'namespace', namespace),
135 (
'use_sim_time',
'True'),
136 (
'rviz_config', rviz_config_file),
140 bringup_cmd = IncludeLaunchDescription(
141 PythonLaunchDescriptionSource(os.path.join(launch_dir,
'bringup_launch.py')),
143 'namespace': namespace,
144 'map': map_yaml_file,
145 'graph': graph_filepath,
146 'use_sim_time':
'True',
147 'params_file': params_file,
148 'autostart': autostart,
149 'use_composition': use_composition,
150 'use_intra_process_comms': use_intra_process_comms,
151 'use_respawn': use_respawn,
152 'use_localization':
'False',
153 'serve_static_map':
'True',
154 'use_keepout_zones':
'False',
155 'use_speed_zones':
'False',
156 'container_name':
'nav2_container',
160 loopback_sim_cmd = IncludeLaunchDescription(
161 PythonLaunchDescriptionSource(
162 os.path.join(loopback_sim_dir,
'loopback_simulation.launch.py')),
164 'namespace': namespace,
165 'params_file': params_file,
170 ld = LaunchDescription()
173 ld.add_action(declare_namespace_cmd)
174 ld.add_action(declare_map_yaml_cmd)
175 ld.add_action(declare_graph_file_cmd)
176 ld.add_action(declare_params_file_cmd)
177 ld.add_action(declare_autostart_cmd)
178 ld.add_action(declare_use_composition_cmd)
179 ld.add_action(declare_use_intra_process_comms_cmd)
181 ld.add_action(declare_rviz_config_file_cmd)
182 ld.add_action(declare_use_robot_state_pub_cmd)
183 ld.add_action(declare_use_rviz_cmd)
184 ld.add_action(declare_use_respawn_cmd)
187 ld.add_action(start_robot_state_publisher_cmd)
188 ld.add_action(loopback_sim_cmd)
189 ld.add_action(rviz_cmd)
190 ld.add_action(bringup_cmd)