17 from ament_index_python.packages
import get_package_share_directory
18 from launch
import LaunchDescription
19 from launch.actions
import DeclareLaunchArgument, EmitEvent, RegisterEventHandler
20 from launch.event_handlers
import OnProcessExit
21 from launch.events
import Shutdown
22 from launch.substitutions
import LaunchConfiguration
23 from launch_ros.actions
import Node
27 def generate_launch_description() -> LaunchDescription:
29 bringup_dir = get_package_share_directory(
'nav2_bringup')
32 namespace = LaunchConfiguration(
'namespace')
33 rviz_config_file = LaunchConfiguration(
'rviz_config')
34 use_sim_time = LaunchConfigAsBool(
'use_sim_time')
37 declare_namespace_cmd = DeclareLaunchArgument(
39 default_value=
'navigation',
41 'Top-level namespace. The value will be used to replace the '
42 '<robot_namespace> keyword on the rviz config file.'
46 declare_rviz_config_file_cmd = DeclareLaunchArgument(
48 default_value=os.path.join(bringup_dir,
'rviz',
'nav2_default_view.rviz'),
49 description=
'Full path to the RVIZ config file to use',
52 declare_use_sim_time_cmd = DeclareLaunchArgument(
54 default_value=
'false',
55 description=
'Use simulation (Gazebo) clock if true')
58 start_rviz_cmd = Node(
62 arguments=[
'-d', rviz_config_file,
'--ros-args',
'--log-level',
'warn'],
64 parameters=[{
'use_sim_time': use_sim_time}],
67 (
'/tf_static',
'tf_static'),
71 exit_event_handler = RegisterEventHandler(
72 event_handler=OnProcessExit(
73 target_action=start_rviz_cmd,
74 on_exit=EmitEvent(event=Shutdown(reason=
'rviz exited')),
79 ld = LaunchDescription()
82 ld.add_action(declare_namespace_cmd)
83 ld.add_action(declare_rviz_config_file_cmd)
84 ld.add_action(declare_use_sim_time_cmd)
87 ld.add_action(start_rviz_cmd)
90 ld.add_action(exit_event_handler)