SMACC2
Functions
rviz_launch Namespace Reference

Functions

def generate_launch_description ()
 

Function Documentation

◆ generate_launch_description()

def rviz_launch.generate_launch_description ( )

Definition at line 29 of file rviz_launch.py.

30 # Get the launch directory
31 bringup_dir = get_package_share_directory("nav2_bringup")
32
33 # Create the launch configuration variables
34 namespace = LaunchConfiguration("namespace")
35 use_namespace = LaunchConfiguration("use_namespace")
36 rviz_config_file = LaunchConfiguration("rviz_config")
37
38 # Declare the launch arguments
39 declare_namespace_cmd = DeclareLaunchArgument(
40 "namespace",
41 default_value="navigation",
42 description=(
43 "Top-level namespace. The value will be used to replace the "
44 "<robot_namespace> keyword on the rviz config file."
45 ),
46 )
47
48 declare_use_namespace_cmd = DeclareLaunchArgument(
49 "use_namespace",
50 default_value="false",
51 description="Whether to apply a namespace to the navigation stack",
52 )
53
54 declare_rviz_config_file_cmd = DeclareLaunchArgument(
55 "rviz_config",
56 default_value=os.path.join(bringup_dir, "rviz", "nav2_default_view.rviz"),
57 description="Full path to the RVIZ config file to use",
58 )
59
60 # Launch rviz
61 start_rviz_cmd = Node(
62 condition=UnlessCondition(use_namespace),
63 package="rviz2",
64 executable="rviz2",
65 name="rviz2",
66 arguments=["-d", rviz_config_file],
67 output="screen",
68 )
69
70 namespaced_rviz_config_file = ReplaceString(
71 source_file=rviz_config_file, replacements={"<robot_namespace>": ("/", namespace)}
72 )
73
74 start_namespaced_rviz_cmd = Node(
75 condition=IfCondition(use_namespace),
76 package="rviz2",
77 executable="rviz2",
78 name="rviz2",
79 namespace=namespace,
80 arguments=["-d", namespaced_rviz_config_file],
81 output="screen",
82 remappings=[
83 ("/tf", "tf"),
84 ("/tf_static", "tf_static"),
85 ("/goal_pose", "goal_pose"),
86 ("/clicked_point", "clicked_point"),
87 ("/initialpose", "initialpose"),
88 ],
89 )
90
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"))
95 ),
96 )
97
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")),
103 ),
104 )
105
106 # Create the launch description and populate
107 ld = LaunchDescription()
108
109 # Declare the launch options
110 ld.add_action(declare_namespace_cmd)
111 ld.add_action(declare_use_namespace_cmd)
112 ld.add_action(declare_rviz_config_file_cmd)
113
114 # Add any conditioned actions
115 ld.add_action(start_rviz_cmd)
116 ld.add_action(start_namespaced_rviz_cmd)
117
118 # Add other nodes and processes we need
119 ld.add_action(exit_event_handler)
120 ld.add_action(exit_event_handler_namespaced)
121
122 return ld
def generate_launch_description()
Definition: rviz_launch.py:29