17 from ament_index_python.packages
import get_package_share_directory
19 from launch
import LaunchDescription
20 from launch.actions
import DeclareLaunchArgument, EmitEvent, RegisterEventHandler
21 from launch.conditions
import IfCondition, UnlessCondition
22 from launch.event_handlers
import OnProcessExit
23 from launch.events
import Shutdown
24 from launch.substitutions
import LaunchConfiguration
25 from launch_ros.actions
import Node
29 def generate_launch_description():
31 bringup_dir = get_package_share_directory(
'nav2_bringup')
34 namespace = LaunchConfiguration(
'namespace')
35 use_namespace = LaunchConfiguration(
'use_namespace')
36 rviz_config_file = LaunchConfiguration(
'rviz_config')
37 use_sim_time = LaunchConfiguration(
'use_sim_time')
40 declare_namespace_cmd = DeclareLaunchArgument(
42 default_value=
'navigation',
44 'Top-level namespace. The value will be used to replace the '
45 '<robot_namespace> keyword on the rviz config file.'
49 declare_use_namespace_cmd = DeclareLaunchArgument(
51 default_value=
'false',
52 description=
'Whether to apply a namespace to the navigation stack',
55 declare_rviz_config_file_cmd = DeclareLaunchArgument(
57 default_value=os.path.join(bringup_dir,
'rviz',
'nav2_default_view.rviz'),
58 description=
'Full path to the RVIZ config file to use',
61 declare_use_sim_time_cmd = DeclareLaunchArgument(
63 default_value=
'false',
64 description=
'Use simulation (Gazebo) clock if true')
67 start_rviz_cmd = Node(
68 condition=UnlessCondition(use_namespace),
71 arguments=[
'-d', rviz_config_file],
73 parameters=[{
'use_sim_time': use_sim_time}],
76 namespaced_rviz_config_file = ReplaceString(
77 source_file=rviz_config_file,
78 replacements={
'<robot_namespace>': (
'/', namespace)},
81 start_namespaced_rviz_cmd = Node(
82 condition=IfCondition(use_namespace),
86 arguments=[
'-d', namespaced_rviz_config_file],
87 parameters=[{
'use_sim_time': use_sim_time}],
92 (
'/tf_static',
'tf_static'),
93 (
'/goal_pose',
'goal_pose'),
94 (
'/clicked_point',
'clicked_point'),
95 (
'/initialpose',
'initialpose'),
99 exit_event_handler = RegisterEventHandler(
100 condition=UnlessCondition(use_namespace),
101 event_handler=OnProcessExit(
102 target_action=start_rviz_cmd,
103 on_exit=EmitEvent(event=Shutdown(reason=
'rviz exited')),
107 exit_event_handler_namespaced = RegisterEventHandler(
108 condition=IfCondition(use_namespace),
109 event_handler=OnProcessExit(
110 target_action=start_namespaced_rviz_cmd,
111 on_exit=EmitEvent(event=Shutdown(reason=
'rviz exited')),
116 ld = LaunchDescription()
119 ld.add_action(declare_namespace_cmd)
120 ld.add_action(declare_use_namespace_cmd)
121 ld.add_action(declare_rviz_config_file_cmd)
122 ld.add_action(declare_use_sim_time_cmd)
125 ld.add_action(start_rviz_cmd)
126 ld.add_action(start_namespaced_rviz_cmd)
129 ld.add_action(exit_event_handler)
130 ld.add_action(exit_event_handler_namespaced)