Nav2 Navigation Stack - humble  humble
ROS 2 Navigation Stack
waypoint_follower_example_launch.py
1 # Copyright (c) 2021 Samsung Research America
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, ExecuteProcess, IncludeLaunchDescription
21 from launch.conditions import IfCondition
22 from launch.launch_description_sources import PythonLaunchDescriptionSource
23 from launch.substitutions import LaunchConfiguration, PythonExpression
24 from launch_ros.actions import Node
25 
26 
27 def generate_launch_description():
28  warehouse_dir = get_package_share_directory('aws_robomaker_small_warehouse_world')
29  nav2_bringup_dir = get_package_share_directory('nav2_bringup')
30  python_commander_dir = get_package_share_directory('nav2_simple_commander')
31 
32  map_yaml_file = os.path.join(warehouse_dir, 'maps', '005', 'map.yaml')
33  world = os.path.join(python_commander_dir, 'warehouse.world')
34 
35  # Launch configuration variables
36  use_rviz = LaunchConfiguration('use_rviz')
37  headless = LaunchConfiguration('headless')
38 
39  # Declare the launch arguments
40  declare_use_rviz_cmd = DeclareLaunchArgument(
41  'use_rviz',
42  default_value='True',
43  description='Whether to start RVIZ')
44 
45  declare_simulator_cmd = DeclareLaunchArgument(
46  'headless',
47  default_value='False',
48  description='Whether to execute gzclient)')
49 
50  # start the simulation
51  start_gazebo_server_cmd = ExecuteProcess(
52  cmd=['gzserver', '-s', 'libgazebo_ros_factory.so', world],
53  cwd=[warehouse_dir], output='screen')
54 
55  start_gazebo_client_cmd = ExecuteProcess(
56  condition=IfCondition(PythonExpression(['not ', headless])),
57  cmd=['gzclient'],
58  cwd=[warehouse_dir], output='screen')
59 
60  urdf = os.path.join(nav2_bringup_dir, 'urdf', 'turtlebot3_waffle.urdf')
61  start_robot_state_publisher_cmd = Node(
62  package='robot_state_publisher',
63  executable='robot_state_publisher',
64  name='robot_state_publisher',
65  output='screen',
66  arguments=[urdf])
67 
68  # start the visualization
69  rviz_cmd = IncludeLaunchDescription(
70  PythonLaunchDescriptionSource(
71  os.path.join(nav2_bringup_dir, 'launch', 'rviz_launch.py')),
72  condition=IfCondition(use_rviz),
73  launch_arguments={'namespace': '',
74  'use_namespace': 'False'}.items())
75 
76  # start navigation
77  bringup_cmd = IncludeLaunchDescription(
78  PythonLaunchDescriptionSource(
79  os.path.join(nav2_bringup_dir, 'launch', 'bringup_launch.py')),
80  launch_arguments={'map': map_yaml_file}.items())
81 
82  # start the demo autonomy task
83  demo_cmd = Node(
84  package='nav2_simple_commander',
85  executable='example_waypoint_follower',
86  emulate_tty=True,
87  output='screen')
88 
89  ld = LaunchDescription()
90  ld.add_action(declare_use_rviz_cmd)
91  ld.add_action(declare_simulator_cmd)
92  ld.add_action(start_gazebo_server_cmd)
93  ld.add_action(start_gazebo_client_cmd)
94  ld.add_action(start_robot_state_publisher_cmd)
95  ld.add_action(rviz_cmd)
96  ld.add_action(bringup_cmd)
97  ld.add_action(demo_cmd)
98  return ld