Nav2 Navigation Stack - humble  humble
ROS 2 Navigation Stack
assisted_teleop_example_launch.py
1 # Copyright (c) 2021 Samsung Research America
2 # Copyright (c) 2022 Joshua Wallace
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 import os
17 
18 from ament_index_python.packages import get_package_share_directory
19 
20 from launch import LaunchDescription
21 from launch.actions import DeclareLaunchArgument, ExecuteProcess, 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 Node
26 
27 
28 def generate_launch_description():
29  warehouse_dir = get_package_share_directory('aws_robomaker_small_warehouse_world')
30  nav2_bringup_dir = get_package_share_directory('nav2_bringup')
31  python_commander_dir = get_package_share_directory('nav2_simple_commander')
32 
33  map_yaml_file = os.path.join(warehouse_dir, 'maps', '005', 'map.yaml')
34  world = os.path.join(python_commander_dir, 'warehouse.world')
35 
36  # Launch configuration variables
37  use_rviz = LaunchConfiguration('use_rviz')
38  headless = LaunchConfiguration('headless')
39 
40  # Declare the launch arguments
41  declare_use_rviz_cmd = DeclareLaunchArgument(
42  'use_rviz',
43  default_value='True',
44  description='Whether to start RVIZ')
45 
46  declare_simulator_cmd = DeclareLaunchArgument(
47  'headless',
48  default_value='False',
49  description='Whether to execute gzclient)')
50 
51  # start the simulation
52  start_gazebo_server_cmd = ExecuteProcess(
53  cmd=['gzserver', '-s', 'libgazebo_ros_factory.so', world],
54  cwd=[warehouse_dir], output='screen')
55 
56  start_gazebo_client_cmd = ExecuteProcess(
57  condition=IfCondition(PythonExpression(['not ', headless])),
58  cmd=['gzclient'],
59  cwd=[warehouse_dir], output='screen')
60 
61  urdf = os.path.join(nav2_bringup_dir, 'urdf', 'turtlebot3_waffle.urdf')
62  start_robot_state_publisher_cmd = Node(
63  package='robot_state_publisher',
64  executable='robot_state_publisher',
65  name='robot_state_publisher',
66  output='screen',
67  arguments=[urdf])
68 
69  # start the visualization
70  rviz_cmd = IncludeLaunchDescription(
71  PythonLaunchDescriptionSource(
72  os.path.join(nav2_bringup_dir, 'launch', 'rviz_launch.py')),
73  condition=IfCondition(use_rviz),
74  launch_arguments={'namespace': '',
75  'use_namespace': 'False'}.items())
76 
77  # start navigation
78  bringup_cmd = IncludeLaunchDescription(
79  PythonLaunchDescriptionSource(
80  os.path.join(nav2_bringup_dir, 'launch', 'bringup_launch.py')),
81  launch_arguments={'map': map_yaml_file}.items())
82 
83  # start the demo autonomy task
84  demo_cmd = Node(
85  package='nav2_simple_commander',
86  executable='example_assisted_teleop',
87  emulate_tty=True,
88  output='screen')
89 
90  ld = LaunchDescription()
91  ld.add_action(declare_use_rviz_cmd)
92  ld.add_action(declare_simulator_cmd)
93  ld.add_action(start_gazebo_server_cmd)
94  ld.add_action(start_gazebo_client_cmd)
95  ld.add_action(start_robot_state_publisher_cmd)
96  ld.add_action(rviz_cmd)
97  ld.add_action(bringup_cmd)
98  ld.add_action(demo_cmd)
99  return ld