From cd239d604876bb0e8df4fdfc7c4936c97a7afd42 Mon Sep 17 00:00:00 2001
From: "Carlos A. Orduno" <39749557+orduno@users.noreply.github.com>
Date: Mon, 28 Oct 2019 11:00:46 -0700
Subject: [PATCH] Launch RVIZ using launch_ros::Actions::Node (#1286)

---
 .../launch/nav2_tb3_simulation_launch.py      | 44 ++++++-------------
 1 file changed, 13 insertions(+), 31 deletions(-)

diff --git a/nav2_bringup/bringup/launch/nav2_tb3_simulation_launch.py b/nav2_bringup/bringup/launch/nav2_tb3_simulation_launch.py
index 08fbe1a2..b562d3bc 100644
--- a/nav2_bringup/bringup/launch/nav2_tb3_simulation_launch.py
+++ b/nav2_bringup/bringup/launch/nav2_tb3_simulation_launch.py
@@ -16,7 +16,7 @@
 
 import os
 
-from ament_index_python.packages import get_package_prefix, get_package_share_directory
+from ament_index_python.packages import get_package_share_directory
 
 from launch import LaunchDescription
 from launch.actions import (DeclareLaunchArgument, EmitEvent, ExecuteProcess,
@@ -152,37 +152,19 @@ def generate_launch_description():
         remappings=remappings,
         arguments=[urdf])
 
-    # TODO(orduno) RVIZ crashing if launched as a node: https://github.com/ros2/rviz/issues/442
-    #              Launching as node works after applying the change described on the github issue.
-    #              Once fixed, launch by providing the remappings:
-    # rviz_remappings = [('/tf', 'tf'),
-    #                    ('/tf_static', 'tf_static'),
-    #                    ('goal_pose', 'goal_pose'),
-    #                    ('/clicked_point', 'clicked_point'),
-    #                    ('/initialpose', 'initialpose'),
-    #                    ('/parameter_events', 'parameter_events'),
-    #                    ('/rosout', 'rosout')]
-
-    # start_rviz_cmd = Node(
-    #     package='rviz2',
-    #     node_executable='rviz2',
-    #     node_name='rviz2',
-    #     arguments=['-d', rviz_config_file],
-    #     output='screen',
-    #     use_remappings=IfCondition(use_remappings),
-    #     remappings=rviz_remappings)
-
-    start_rviz_cmd = ExecuteProcess(
+    start_rviz_cmd = Node(
         condition=IfCondition(use_rviz),
-        cmd=[os.path.join(get_package_prefix('rviz2'), 'lib/rviz2/rviz2'),
-             ['-d', rviz_config_file],
-             ['__ns:=/', namespace],
-             '/tf:=tf',
-             '/tf_static:=tf_static',
-             '/goal_pose:=goal_pose',
-             '/clicked_point:=clicked_point',
-             '/initialpose:=initialpose'],
-        cwd=[launch_dir], output='screen')
+        package='rviz2',
+        node_executable='rviz2',
+        node_name='rviz2',
+        arguments=['-d', rviz_config_file],
+        output='screen',
+        use_remappings=IfCondition(use_remappings),
+        remappings=[('/tf', 'tf'),
+                    ('/tf_static', 'tf_static'),
+                    ('goal_pose', 'goal_pose'),
+                    ('/clicked_point', 'clicked_point'),
+                    ('/initialpose', 'initialpose')])
 
     exit_event_handler = RegisterEventHandler(
         event_handler=OnProcessExit(
-- 
GitLab