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
26 def generate_launch_description() -> LaunchDescription:
28 bringup_dir = get_package_share_directory(
'nav2_bringup')
31 namespace = LaunchConfiguration(
'namespace')
32 rviz_config_file = LaunchConfiguration(
'rviz_config')
33 use_sim_time = LaunchConfiguration(
'use_sim_time')
36 declare_namespace_cmd = DeclareLaunchArgument(
38 default_value=
'navigation',
40 'Top-level namespace. The value will be used to replace the '
41 '<robot_namespace> keyword on the rviz config file.'
45 declare_rviz_config_file_cmd = DeclareLaunchArgument(
47 default_value=os.path.join(bringup_dir,
'rviz',
'nav2_default_view.rviz'),
48 description=
'Full path to the RVIZ config file to use',
51 declare_use_sim_time_cmd = DeclareLaunchArgument(
53 default_value=
'false',
54 description=
'Use simulation (Gazebo) clock if true')
57 start_rviz_cmd = Node(
61 arguments=[
'-d', rviz_config_file,
'--ros-args',
'--log-level',
'warn'],
63 parameters=[{
'use_sim_time': use_sim_time}],
66 (
'/tf_static',
'tf_static'),
70 exit_event_handler = RegisterEventHandler(
71 event_handler=OnProcessExit(
72 target_action=start_rviz_cmd,
73 on_exit=EmitEvent(event=Shutdown(reason=
'rviz exited')),
78 ld = LaunchDescription()
81 ld.add_action(declare_namespace_cmd)
82 ld.add_action(declare_rviz_config_file_cmd)
83 ld.add_action(declare_use_sim_time_cmd)
86 ld.add_action(start_rviz_cmd)
89 ld.add_action(exit_event_handler)