1818
1919from launch import LaunchDescription
2020from launch .actions import DeclareLaunchArgument , EmitEvent , RegisterEventHandler
21- from launch .conditions import IfCondition , UnlessCondition
2221from launch .event_handlers import OnProcessExit
2322from launch .events import Shutdown
2423from launch .substitutions import LaunchConfiguration
2524from launch_ros .actions import Node
26- from nav2_common .launch import ReplaceString
2725
2826
2927def generate_launch_description ():
@@ -32,7 +30,6 @@ def generate_launch_description():
3230
3331 # Create the launch configuration variables
3432 namespace = LaunchConfiguration ('namespace' )
35- use_namespace = LaunchConfiguration ('use_namespace' )
3633 rviz_config_file = LaunchConfiguration ('rviz_config' )
3734 use_sim_time = LaunchConfiguration ('use_sim_time' )
3835
@@ -46,12 +43,6 @@ def generate_launch_description():
4643 ),
4744 )
4845
49- declare_use_namespace_cmd = DeclareLaunchArgument (
50- 'use_namespace' ,
51- default_value = 'false' ,
52- description = 'Whether to apply a namespace to the navigation stack' ,
53- )
54-
5546 declare_rviz_config_file_cmd = DeclareLaunchArgument (
5647 'rviz_config' ,
5748 default_value = os .path .join (bringup_dir , 'rviz' , 'nav2_default_view.rviz' ),
@@ -65,68 +56,37 @@ def generate_launch_description():
6556
6657 # Launch rviz
6758 start_rviz_cmd = Node (
68- condition = UnlessCondition (use_namespace ),
6959 package = 'rviz2' ,
7060 executable = 'rviz2' ,
61+ namespace = namespace ,
7162 arguments = ['-d' , rviz_config_file ],
7263 output = 'screen' ,
7364 parameters = [{'use_sim_time' : use_sim_time }],
74- )
75-
76- namespaced_rviz_config_file = ReplaceString (
77- source_file = rviz_config_file ,
78- replacements = {'<robot_namespace>' : ('/' , namespace )},
79- )
80-
81- start_namespaced_rviz_cmd = Node (
82- condition = IfCondition (use_namespace ),
83- package = 'rviz2' ,
84- executable = 'rviz2' ,
85- namespace = namespace ,
86- arguments = ['-d' , namespaced_rviz_config_file ],
87- parameters = [{'use_sim_time' : use_sim_time }],
88- output = 'screen' ,
8965 remappings = [
90- ('/map' , 'map' ),
9166 ('/tf' , 'tf' ),
9267 ('/tf_static' , 'tf_static' ),
93- ('/goal_pose' , 'goal_pose' ),
94- ('/clicked_point' , 'clicked_point' ),
95- ('/initialpose' , 'initialpose' ),
9668 ],
9769 )
9870
9971 exit_event_handler = RegisterEventHandler (
100- condition = UnlessCondition (use_namespace ),
10172 event_handler = OnProcessExit (
10273 target_action = start_rviz_cmd ,
10374 on_exit = EmitEvent (event = Shutdown (reason = 'rviz exited' )),
10475 ),
10576 )
10677
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' )),
112- ),
113- )
114-
11578 # Create the launch description and populate
11679 ld = LaunchDescription ()
11780
11881 # Declare the launch options
11982 ld .add_action (declare_namespace_cmd )
120- ld .add_action (declare_use_namespace_cmd )
12183 ld .add_action (declare_rviz_config_file_cmd )
12284 ld .add_action (declare_use_sim_time_cmd )
12385
12486 # Add any conditioned actions
12587 ld .add_action (start_rviz_cmd )
126- ld .add_action (start_namespaced_rviz_cmd )
12788
12889 # Add other nodes and processes we need
12990 ld .add_action (exit_event_handler )
130- ld .add_action (exit_event_handler_namespaced )
13191
13292 return ld
0 commit comments