17from ament_index_python.packages
import get_package_share_directory
19from launch
import LaunchDescription
20from launch.actions
import DeclareLaunchArgument, EmitEvent, RegisterEventHandler
21from launch.conditions
import IfCondition, UnlessCondition
22from launch.event_handlers
import OnProcessExit
23from launch.events
import Shutdown
24from launch.substitutions
import LaunchConfiguration
25from launch_ros.actions
import Node
26from nav2_common.launch
import ReplaceString
31 bringup_dir = get_package_share_directory(
"sm_husky_barrel_search_1")
34 namespace = LaunchConfiguration(
"namespace")
35 use_namespace = LaunchConfiguration(
"use_namespace")
36 rviz_config_file = LaunchConfiguration(
"rviz_config")
39 declare_namespace_cmd = DeclareLaunchArgument(
41 default_value=
"navigation",
43 "Top-level namespace. The value will be used to replace the "
44 "<robot_namespace> keyword on the rviz config file."
48 declare_use_namespace_cmd = DeclareLaunchArgument(
50 default_value=
"false",
51 description=
"Whether to apply a namespace to the navigation stack",
54 declare_rviz_config_file_cmd = DeclareLaunchArgument(
56 default_value=os.path.join(bringup_dir,
"rviz",
"nav2_default_view.rviz"),
57 description=
"Full path to the RVIZ config file to use",
61 start_rviz_cmd = Node(
62 condition=UnlessCondition(use_namespace),
66 arguments=[
"-d", rviz_config_file],
70 namespaced_rviz_config_file = ReplaceString(
71 source_file=rviz_config_file, replacements={
"<robot_namespace>": (
"/", namespace)}
74 start_namespaced_rviz_cmd = Node(
75 condition=IfCondition(use_namespace),
80 arguments=[
"-d", namespaced_rviz_config_file],
84 (
"/tf_static",
"tf_static"),
85 (
"/goal_pose",
"goal_pose"),
86 (
"/clicked_point",
"clicked_point"),
87 (
"/initialpose",
"initialpose"),
91 exit_event_handler = RegisterEventHandler(
92 condition=UnlessCondition(use_namespace),
93 event_handler=OnProcessExit(
94 target_action=start_rviz_cmd, on_exit=EmitEvent(event=Shutdown(reason=
"rviz exited"))
98 exit_event_handler_namespaced = RegisterEventHandler(
99 condition=IfCondition(use_namespace),
100 event_handler=OnProcessExit(
101 target_action=start_namespaced_rviz_cmd,
102 on_exit=EmitEvent(event=Shutdown(reason=
"rviz exited")),
107 ld = LaunchDescription()
110 ld.add_action(declare_namespace_cmd)
111 ld.add_action(declare_use_namespace_cmd)
112 ld.add_action(declare_rviz_config_file_cmd)
115 ld.add_action(start_rviz_cmd)
116 ld.add_action(start_namespaced_rviz_cmd)
119 ld.add_action(exit_event_handler)
120 ld.add_action(exit_event_handler_namespaced)
def generate_launch_description()