

add example node
@5a396954d643392de0d0a3e2ec2ec7cbd4c70d7f
+++ p9n_example/.vscode/c_cpp_properties.json
... | ... | @@ -0,0 +1,22 @@ |
1 | +{ | |
2 | + "configurations": [ | |
3 | + { | |
4 | + "browse": { | |
5 | + "databaseFilename": "${workspaceFolder}/.vscode/browse.vc.db", | |
6 | + "limitSymbolsToIncludedHeaders": false | |
7 | + }, | |
8 | + "includePath": [ | |
9 | + "/opt/ros/galactic/include/**", | |
10 | + "/usr/include/**", | |
11 | + "${workspaceFolder}/include/**", | |
12 | + "${workspaceFolder}/../p9n_interface/include/**" | |
13 | + ], | |
14 | + "name": "ROS", | |
15 | + "intelliSenseMode": "clang-x64", | |
16 | + "compilerPath": "/usr/bin/gcc", | |
17 | + "cStandard": "c99", | |
18 | + "cppStandard": "c++17" | |
19 | + } | |
20 | + ], | |
21 | + "version": 4 | |
22 | +}(파일 끝에 줄바꿈 문자 없음) |
+++ p9n_example/.vscode/cspell.json
... | ... | @@ -0,0 +1,1 @@ |
1 | +../../.vscode/cspell.json(파일 끝에 줄바꿈 문자 없음) |
+++ p9n_example/.vscode/settings.json
... | ... | @@ -0,0 +1,1 @@ |
1 | +../../.vscode/settings.json(파일 끝에 줄바꿈 문자 없음) |
+++ p9n_example/.vscode/uncrustify.cfg
... | ... | @@ -0,0 +1,1 @@ |
1 | +../../.vscode/uncrustify.cfg(파일 끝에 줄바꿈 문자 없음) |
+++ p9n_example/CMakeLists.txt
... | ... | @@ -0,0 +1,30 @@ |
1 | +cmake_minimum_required(VERSION 3.8) | |
2 | +project(p9n_example) | |
3 | + | |
4 | +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | |
5 | + add_compile_options(-Wall -Wextra -Wpedantic) | |
6 | +endif() | |
7 | + | |
8 | +find_package(ament_cmake_auto REQUIRED) | |
9 | +ament_auto_find_build_dependencies() | |
10 | + | |
11 | +# Display Node ====================================================== | |
12 | +set(TARGET display_node) | |
13 | +ament_auto_add_library( | |
14 | + ${TARGET} | |
15 | + SHARED | |
16 | + src/${TARGET}.cpp) | |
17 | +rclcpp_components_register_node( | |
18 | + ${TARGET} | |
19 | + PLUGIN "p9n_example::DisplayNode" | |
20 | + EXECUTABLE ${TARGET}_exec) | |
21 | +# End Display Node ================================================== | |
22 | + | |
23 | +if(BUILD_TESTING) | |
24 | + find_package(ament_lint_auto REQUIRED) | |
25 | + set(ament_cmake_copyright_FOUND TRUE) | |
26 | + set(ament_cmake_cpplint_FOUND TRUE) | |
27 | + ament_lint_auto_find_test_dependencies() | |
28 | +endif() | |
29 | + | |
30 | +ament_auto_package(INSTALL_TO_SHARE launch) |
+++ p9n_example/include/p9n_example/display_node.hpp
... | ... | @@ -0,0 +1,42 @@ |
1 | +// Copyright 2022 HarvestX Inc. | |
2 | +// | |
3 | +// Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | +// you may not use this file except in compliance with the License. | |
5 | +// You may obtain a copy of the License at | |
6 | +// | |
7 | +// http://www.apache.org/licenses/LICENSE-2.0 | |
8 | +// | |
9 | +// Unless required by applicable law or agreed to in writing, software | |
10 | +// distributed under the License is distributed on an "AS IS" BASIS, | |
11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | +// See the License for the specific language governing permissions and | |
13 | +// limitations under the License. | |
14 | + | |
15 | +#pragma once | |
16 | + | |
17 | +#include <string> | |
18 | +#include <memory> | |
19 | +#include <sensor_msgs/msg/joy.hpp> | |
20 | +#include <rclcpp/rclcpp.hpp> | |
21 | + | |
22 | +#include <p9n_interface/p9n_interface.hpp> | |
23 | + | |
24 | + | |
25 | +namespace p9n_example | |
26 | +{ | |
27 | +class DisplayNode : public rclcpp::Node | |
28 | +{ | |
29 | +private: | |
30 | + p9n_interface::HW_TYPE hw_type_; | |
31 | + std::unique_ptr<p9n_interface::PlayStationInterface> p9n_if_; | |
32 | + | |
33 | + rclcpp::Subscription<sensor_msgs::msg::Joy>::SharedPtr joy_sub_; | |
34 | + | |
35 | +public: | |
36 | + explicit DisplayNode(const rclcpp::NodeOptions &); | |
37 | + void onJoy(sensor_msgs::msg::Joy::ConstSharedPtr); | |
38 | +}; | |
39 | +} // namespace p9n_example | |
40 | + | |
41 | +#include "rclcpp_components/register_node_macro.hpp" | |
42 | +RCLCPP_COMPONENTS_REGISTER_NODE(p9n_example::DisplayNode) |
+++ p9n_example/launch/display.launch.py
... | ... | @@ -0,0 +1,41 @@ |
1 | +# Copyright 2022 HarvestX Inc. | |
2 | +# | |
3 | +# Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | +# you may not use this file except in compliance with the License. | |
5 | +# You may obtain a copy of the License at | |
6 | +# | |
7 | +# http://www.apache.org/licenses/LICENSE-2.0 | |
8 | +# | |
9 | +# Unless required by applicable law or agreed to in writing, software | |
10 | +# distributed under the License is distributed on an "AS IS" BASIS, | |
11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | +# See the License for the specific language governing permissions and | |
13 | +# limitations under the License. | |
14 | + | |
15 | +from launch import LaunchDescription | |
16 | +from launch_ros.actions import ComposableNodeContainer, Node | |
17 | +from launch_ros.descriptions import ComposableNode | |
18 | + | |
19 | + | |
20 | +def generate_launch_description(): | |
21 | + """Generate launch description.""" | |
22 | + nodes = [ | |
23 | + ComposableNodeContainer( | |
24 | + name='joy_container', | |
25 | + namespace='p9n', | |
26 | + package='rclcpp_components', | |
27 | + executable='component_container', | |
28 | + composable_node_descriptions=[ | |
29 | + ComposableNode( | |
30 | + package='joy', | |
31 | + plugin='joy::Joy', | |
32 | + name='joy', | |
33 | + ), | |
34 | + ]), | |
35 | + Node( | |
36 | + name='display_node', | |
37 | + package='p9n_example', | |
38 | + executable='display_node_exec'), | |
39 | + ] | |
40 | + | |
41 | + return LaunchDescription(nodes) |
+++ p9n_example/package.xml
... | ... | @@ -0,0 +1,22 @@ |
1 | +<?xml version="1.0"?> | |
2 | +<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | |
3 | +<package format="3"> | |
4 | + <name>p9n_example</name> | |
5 | + <version>0.0.0</version> | |
6 | + <description>PlayStation JoyInterface example package.</description> | |
7 | + <maintainer email="m12watanabe1a@gmail.com">m12watanabe1a</maintainer> | |
8 | + <license>Apache License 2.0</license> | |
9 | + | |
10 | + <buildtool_depend>ament_cmake_auto</buildtool_depend> | |
11 | + | |
12 | + <depend>rclcpp_components</depend> | |
13 | + <depend>p9n_interface</depend> | |
14 | + <exec_depend>joy</exec_depend> | |
15 | + | |
16 | + <test_depend>ament_lint_auto</test_depend> | |
17 | + <test_depend>ament_lint_common</test_depend> | |
18 | + | |
19 | + <export> | |
20 | + <build_type>ament_cmake</build_type> | |
21 | + </export> | |
22 | +</package>(파일 끝에 줄바꿈 문자 없음) |
+++ p9n_example/src/display_node.cpp
... | ... | @@ -0,0 +1,169 @@ |
1 | +// Copyright 2022 HarvestX Inc. | |
2 | +// | |
3 | +// Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | +// you may not use this file except in compliance with the License. | |
5 | +// You may obtain a copy of the License at | |
6 | +// | |
7 | +// http://www.apache.org/licenses/LICENSE-2.0 | |
8 | +// | |
9 | +// Unless required by applicable law or agreed to in writing, software | |
10 | +// distributed under the License is distributed on an "AS IS" BASIS, | |
11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | +// See the License for the specific language governing permissions and | |
13 | +// limitations under the License. | |
14 | + | |
15 | + | |
16 | +#include "p9n_example/display_node.hpp" | |
17 | + | |
18 | + | |
19 | +namespace p9n_example | |
20 | +{ | |
21 | +DisplayNode::DisplayNode(const rclcpp::NodeOptions & options) | |
22 | +: rclcpp::Node("display_node", options) | |
23 | +{ | |
24 | + | |
25 | + const std::string hw_name = this->declare_parameter<std::string>( | |
26 | + "controller_type", p9n_interface::HW_NAME::DUALSENSE); | |
27 | + | |
28 | + try { | |
29 | + this->hw_type_ = p9n_interface::getHwType(hw_name); | |
30 | + } catch (std::runtime_error & e) { | |
31 | + RCLCPP_ERROR( | |
32 | + this->get_logger(), | |
33 | + e.what()); | |
34 | + RCLCPP_ERROR( | |
35 | + this->get_logger(), | |
36 | + "Please select hardware from %s", | |
37 | + p9n_interface::getAllHwName().c_str()); | |
38 | + rclcpp::shutdown(); | |
39 | + return; | |
40 | + } | |
41 | + | |
42 | + this->p9n_if_ = | |
43 | + std::make_unique<p9n_interface::PlayStationInterface>(this->hw_type_); | |
44 | + | |
45 | + this->joy_sub_ = this->create_subscription<sensor_msgs::msg::Joy>( | |
46 | + "joy", rclcpp::SensorDataQoS(rclcpp::KeepLast(1)), | |
47 | + std::bind(&DisplayNode::onJoy, this, std::placeholders::_1)); | |
48 | + | |
49 | + | |
50 | + if (this->joy_sub_->get_publisher_count() == 0) { | |
51 | + RCLCPP_WARN( | |
52 | + this->get_logger(), | |
53 | + "Joy node not launched"); | |
54 | + } | |
55 | +} | |
56 | + | |
57 | +void DisplayNode::onJoy(sensor_msgs::msg::Joy::ConstSharedPtr joy_msg) | |
58 | +{ | |
59 | + this->p9n_if_->setJoyMsg(joy_msg); | |
60 | + | |
61 | + if (this->p9n_if_->pressedCross()) { | |
62 | + RCLCPP_INFO(this->get_logger(), " ☓ Pressed!"); | |
63 | + } | |
64 | + | |
65 | + if (this->p9n_if_->pressedCircle()) { | |
66 | + RCLCPP_INFO(this->get_logger(), " ○ Pressed!"); | |
67 | + } | |
68 | + | |
69 | + if (this->p9n_if_->pressedTriangle()) { | |
70 | + RCLCPP_INFO(this->get_logger(), " △ Pressed!"); | |
71 | + } | |
72 | + | |
73 | + if (this->p9n_if_->pressedSquare()) { | |
74 | + RCLCPP_INFO(this->get_logger(), " □ Pressed!"); | |
75 | + } | |
76 | + | |
77 | + if (this->p9n_if_->pressedL1()) { | |
78 | + RCLCPP_INFO(this->get_logger(), " L1 Pressed!"); | |
79 | + } | |
80 | + | |
81 | + if (this->p9n_if_->pressedR1()) { | |
82 | + RCLCPP_INFO(this->get_logger(), " R1 Pressed!"); | |
83 | + } | |
84 | + | |
85 | + if (this->p9n_if_->pressedL2()) { | |
86 | + RCLCPP_INFO_STREAM( | |
87 | + this->get_logger(), | |
88 | + " L2 Pressed! : " << | |
89 | + std::right << std::setw(6) << | |
90 | + std::fixed << std::setprecision(3) << | |
91 | + this->p9n_if_->pressedL2Analog()); | |
92 | + } | |
93 | + | |
94 | + if (this->p9n_if_->pressedR2()) { | |
95 | + RCLCPP_INFO_STREAM( | |
96 | + this->get_logger(), | |
97 | + " R2 Pressed! : " << | |
98 | + std::right << std::setw(6) << | |
99 | + std::fixed << std::setprecision(3) << | |
100 | + this->p9n_if_->pressedR2Analog()); | |
101 | + } | |
102 | + | |
103 | + if (this->p9n_if_->pressedSelect()) { | |
104 | + RCLCPP_INFO( | |
105 | + this->get_logger(), " Select Pressed!"); | |
106 | + } | |
107 | + | |
108 | + if (this->p9n_if_->pressedStart()) { | |
109 | + RCLCPP_INFO( | |
110 | + this->get_logger(), " Start Pressed!"); | |
111 | + } | |
112 | + | |
113 | + if (this->p9n_if_->pressedPS()) { | |
114 | + RCLCPP_INFO( | |
115 | + this->get_logger(), " PS Pressed!"); | |
116 | + } | |
117 | + | |
118 | + if (this->p9n_if_->pressedDPadUp()) { | |
119 | + RCLCPP_INFO( | |
120 | + this->get_logger(), " ↑ Pressed!"); | |
121 | + } | |
122 | + | |
123 | + if (this->p9n_if_->pressedDPadDown()) { | |
124 | + RCLCPP_INFO( | |
125 | + this->get_logger(), " ↓ Pressed!"); | |
126 | + } | |
127 | + | |
128 | + if (this->p9n_if_->pressedDPadRight()) { | |
129 | + RCLCPP_INFO( | |
130 | + this->get_logger(), " → Pressed!"); | |
131 | + } | |
132 | + | |
133 | + if (this->p9n_if_->pressedDPadLeft()) { | |
134 | + RCLCPP_INFO( | |
135 | + this->get_logger(), " ← Pressed!"); | |
136 | + } | |
137 | + | |
138 | + if ( | |
139 | + std::abs(this->p9n_if_->tiltedStickLX()) > 1e-2 || | |
140 | + std::abs(this->p9n_if_->tiltedStickLY()) > 1e-2) | |
141 | + { | |
142 | + RCLCPP_INFO_STREAM( | |
143 | + this->get_logger(), | |
144 | + " LStick Tilted!" << | |
145 | + " x:" << std::fixed << std::setw(6) << std::setprecision(3) << | |
146 | + this->p9n_if_->tiltedStickLX() << | |
147 | + " y:" << std::fixed << std::setw(6) << std::setprecision(3) << | |
148 | + this->p9n_if_->tiltedStickLY()); | |
149 | + } | |
150 | + | |
151 | + if ( | |
152 | + std::abs(this->p9n_if_->tiltedStickRX()) > 1e-2 || | |
153 | + std::abs(this->p9n_if_->tiltedStickRY()) > 1e-2) | |
154 | + { | |
155 | + RCLCPP_INFO_STREAM( | |
156 | + this->get_logger(), | |
157 | + " RStick Tilted!" << | |
158 | + " x:" << std::fixed << std::setw(6) << std::setprecision(3) << | |
159 | + this->p9n_if_->tiltedStickRX() << | |
160 | + " y:" << std::fixed << std::setw(6) << std::setprecision(3) << | |
161 | + this->p9n_if_->tiltedStickRY()); | |
162 | + } | |
163 | + | |
164 | + if (this->p9n_if_->pressedAny()) { | |
165 | + using namespace std::chrono_literals; | |
166 | + rclcpp::sleep_for(200ms); | |
167 | + } | |
168 | +} | |
169 | +} // namespace p9n_example |
--- p9n_interface/package.xml
+++ p9n_interface/package.xml
... | ... | @@ -10,6 +10,7 @@ |
10 | 10 |
<buildtool_depend>ament_cmake_auto</buildtool_depend> |
11 | 11 |
|
12 | 12 |
<depend>rclcpp</depend> |
13 |
+ <depend>sensor_msgs</depend> |
|
13 | 14 |
|
14 | 15 |
<test_depend>ament_lint_auto</test_depend> |
15 | 16 |
<test_depend>ament_lint_common</test_depend> |
--- p9n_test/CMakeLists.txt
+++ p9n_test/CMakeLists.txt
... | ... | @@ -18,7 +18,7 @@ |
18 | 18 |
src/workflow_handler.cpp) |
19 | 19 |
rclcpp_components_register_node( |
20 | 20 |
${TARGET} |
21 |
- PLUGIN "p9n_test::PlayStationTest" |
|
21 |
+ PLUGIN "p9n_test::PlayStationTestNode" |
|
22 | 22 |
EXECUTABLE ${TARGET}_exec) |
23 | 23 |
# End Playstation Test ============================================== |
24 | 24 |
|
--- p9n_test/include/p9n_test/p9n_test_node.hpp
+++ p9n_test/include/p9n_test/p9n_test_node.hpp
... | ... | @@ -24,7 +24,7 @@ |
24 | 24 |
|
25 | 25 |
namespace p9n_test |
26 | 26 |
{ |
27 |
-class PlayStationTest : public rclcpp::Node |
|
27 |
+class PlayStationTestNode : public rclcpp::Node |
|
28 | 28 |
{ |
29 | 29 |
private: |
30 | 30 |
p9n_interface::HW_TYPE hw_type_; |
... | ... | @@ -37,11 +37,11 @@ |
37 | 37 |
rclcpp::Subscription<sensor_msgs::msg::Joy>::SharedPtr joy_sub_; |
38 | 38 |
|
39 | 39 |
public: |
40 |
- explicit PlayStationTest(const rclcpp::NodeOptions &); |
|
40 |
+ explicit PlayStationTestNode(const rclcpp::NodeOptions &); |
|
41 | 41 |
void onJoy(sensor_msgs::msg::Joy::ConstSharedPtr); |
42 | 42 |
|
43 | 43 |
}; |
44 | 44 |
} // namespace p9n_test |
45 | 45 |
|
46 | 46 |
#include "rclcpp_components/register_node_macro.hpp" |
47 |
-RCLCPP_COMPONENTS_REGISTER_NODE(p9n_test::PlayStationTest) |
|
47 |
+RCLCPP_COMPONENTS_REGISTER_NODE(p9n_test::PlayStationTestNode) |
--- p9n_test/launch/test.launch.py
+++ p9n_test/launch/test.launch.py
... | ... | @@ -33,7 +33,7 @@ |
33 | 33 |
), |
34 | 34 |
ComposableNode( |
35 | 35 |
package='p9n_test', |
36 |
- plugin='p9n_test::PlayStationTest', |
|
36 |
+ plugin='p9n_test::PlayStationTestNode', |
|
37 | 37 |
name='p9n_test' |
38 | 38 |
), |
39 | 39 |
])] |
--- p9n_test/package.xml
+++ p9n_test/package.xml
... | ... | @@ -12,7 +12,6 @@ |
12 | 12 |
<depend>rclcpp</depend> |
13 | 13 |
<depend>rclcpp_components</depend> |
14 | 14 |
<depend>p9n_interface</depend> |
15 |
- <depend>sensor_msgs</depend> |
|
16 | 15 |
<exec_depend>joy</exec_depend> |
17 | 16 |
|
18 | 17 |
<test_depend>ament_lint_auto</test_depend> |
--- p9n_test/src/p9n_test_node.cpp
+++ p9n_test/src/p9n_test_node.cpp
... | ... | @@ -16,7 +16,7 @@ |
16 | 16 |
|
17 | 17 |
namespace p9n_test |
18 | 18 |
{ |
19 |
-PlayStationTest::PlayStationTest(const rclcpp::NodeOptions & options) |
|
19 |
+PlayStationTestNode::PlayStationTestNode(const rclcpp::NodeOptions & options) |
|
20 | 20 |
: rclcpp::Node("p9n_test_node", options) |
21 | 21 |
{ |
22 | 22 |
const std::string hw_name = this->declare_parameter<std::string>( |
... | ... | @@ -48,7 +48,7 @@ |
48 | 48 |
|
49 | 49 |
this->joy_sub_ = this->create_subscription<sensor_msgs::msg::Joy>( |
50 | 50 |
"joy", rclcpp::SensorDataQoS(rclcpp::KeepLast(1)), |
51 |
- std::bind(&PlayStationTest::onJoy, this, std::placeholders::_1)); |
|
51 |
+ std::bind(&PlayStationTestNode::onJoy, this, std::placeholders::_1)); |
|
52 | 52 |
|
53 | 53 |
this->wf_handler_ = std::make_unique<WorkflowHandler>(); |
54 | 54 |
this->p9n_interface_ = |
... | ... | @@ -64,7 +64,7 @@ |
64 | 64 |
} |
65 | 65 |
} |
66 | 66 |
|
67 |
-void PlayStationTest::onJoy(sensor_msgs::msg::Joy::ConstSharedPtr joy_msg) |
|
67 |
+void PlayStationTestNode::onJoy(sensor_msgs::msg::Joy::ConstSharedPtr joy_msg) |
|
68 | 68 |
{ |
69 | 69 |
this->p9n_interface_->setJoyMsg(joy_msg); |
70 | 70 |
this->wf_handler_->explainNextTask(true); |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?