m12watanabe1a 2022-05-31
fix launch file
@c625b81aa5205d54241a6994ad60a49a57742e38
p9n_example/launch/display.launch.py
--- p9n_example/launch/display.launch.py
+++ p9n_example/launch/display.launch.py
@@ -13,12 +13,24 @@
 # limitations under the License.
 
 from launch import LaunchDescription
-from launch_ros.actions import ComposableNodeContainer, Node
+from launch.actions import DeclareLaunchArgument
+from launch.substitutions import (
+    TextSubstitution,
+    LaunchConfiguration,
+)
+
+from launch_ros.actions import ComposableNodeContainer
 from launch_ros.descriptions import ComposableNode
 
 
 def generate_launch_description():
     """Generate launch description."""
+    launch_args = [
+        DeclareLaunchArgument(
+            'hw_type',
+            default_value=TextSubstitution(text='Dualsense')
+        )
+    ]
     nodes = [
         ComposableNodeContainer(
             name='joy_container',
@@ -31,11 +43,15 @@
                     plugin='joy::Joy',
                     name='joy',
                 ),
+                ComposableNode(
+                    package='p9n_example',
+                    plugin='p9n_example::DisplayNode',
+                    name='display_node',
+                    parameters=[{
+                        'hw_type': LaunchConfiguration('hw_type')
+                    }]
+                )
             ]),
-        Node(
-            name='display_node',
-            package='p9n_example',
-            executable='display_node_exec'),
     ]
 
-    return LaunchDescription(nodes)
+    return LaunchDescription(launch_args + nodes)
p9n_example/src/display_node.cpp
--- p9n_example/src/display_node.cpp
+++ p9n_example/src/display_node.cpp
@@ -23,7 +23,7 @@
 {
 
   const std::string hw_name = this->declare_parameter<std::string>(
-    "controller_type", p9n_interface::HW_NAME::DUALSENSE);
+    "hw_type", p9n_interface::HW_NAME::DUALSENSE);
 
   try {
     this->hw_type_ = p9n_interface::getHwType(hw_name);
p9n_interface/src/p9n_interface.cpp
--- p9n_interface/src/p9n_interface.cpp
+++ p9n_interface/src/p9n_interface.cpp
@@ -69,9 +69,9 @@
 
   switch (this->HW_TYPE_) {
     case HW_TYPE::DUALSHOCK3:
-      throw std::runtime_error("Not supported yet.");
+      throw std::runtime_error("DualShock3 not supported yet.");
     case HW_TYPE::DUALSHOCK4:
-      throw std::runtime_error("Not supported yet.");
+      throw std::runtime_error("DualShock4 not supported yet.");
     case HW_TYPE::DUALSENSE:
       {
         using BTN_IDX = BUTTONS_DUALSENSE;
p9n_test/launch/test.launch.py
--- p9n_test/launch/test.launch.py
+++ p9n_test/launch/test.launch.py
@@ -13,12 +13,24 @@
 # limitations under the License.
 
 from launch import LaunchDescription
+from launch.actions import DeclareLaunchArgument
+from launch.substitutions import (
+    TextSubstitution,
+    LaunchConfiguration,
+)
+
 from launch_ros.actions import ComposableNodeContainer
 from launch_ros.descriptions import ComposableNode
 
 
 def generate_launch_description():
     """Generate launch description."""
+    launch_args = [
+        DeclareLaunchArgument(
+            'hw_type',
+            default_value=TextSubstitution(text='Dualsense')
+        )
+    ]
     nodes = [
         ComposableNodeContainer(
             name='joy_container',
@@ -34,8 +46,11 @@
                 ComposableNode(
                     package='p9n_test',
                     plugin='p9n_test::PlayStationTestNode',
-                    name='p9n_test'
+                    name='p9n_test',
+                    parameters=[{
+                        'hw_type': LaunchConfiguration('hw_type')
+                    }]
                 ),
             ])]
 
-    return LaunchDescription(nodes)
+    return LaunchDescription(launch_args + nodes)
p9n_test/src/p9n_test_node.cpp
--- p9n_test/src/p9n_test_node.cpp
+++ p9n_test/src/p9n_test_node.cpp
@@ -20,7 +20,7 @@
 : rclcpp::Node("p9n_test_node", options)
 {
   const std::string hw_name = this->declare_parameter<std::string>(
-    "controller_type", p9n_interface::HW_NAME::DUALSENSE);
+    "hw_type", p9n_interface::HW_NAME::DUALSENSE);
 
   try {
     this->hw_type_ = p9n_interface::getHwType(hw_name);
Add a comment
List