From 3e45f3748b86d3b7d3a2937c2b31a7a94d022410 Mon Sep 17 00:00:00 2001 From: "Takagi, Isamu" Date: Wed, 15 May 2024 18:16:50 +0900 Subject: [PATCH] feat(diagnostic_graph_aggregator): componentize node Signed-off-by: Takagi, Isamu --- .../diagnostic_graph_aggregator/CMakeLists.txt | 17 +++++++++++------ .../launch/aggregator.launch.xml | 2 +- system/diagnostic_graph_aggregator/package.xml | 1 + .../src/node/aggregator.cpp | 15 +++------------ .../src/node/aggregator.hpp | 2 +- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/system/diagnostic_graph_aggregator/CMakeLists.txt b/system/diagnostic_graph_aggregator/CMakeLists.txt index 905cc07d81da1..4f18407e2a108 100644 --- a/system/diagnostic_graph_aggregator/CMakeLists.txt +++ b/system/diagnostic_graph_aggregator/CMakeLists.txt @@ -13,12 +13,6 @@ ament_auto_add_library(${PROJECT_NAME} SHARED src/common/graph/units.cpp ) -ament_auto_add_executable(aggregator - src/node/aggregator.cpp - src/node/availability.cpp -) -target_include_directories(aggregator PRIVATE src/common) - ament_auto_add_executable(tree src/tool/tree.cpp ) @@ -29,6 +23,17 @@ ament_auto_add_executable(plantuml ) target_include_directories(plantuml PRIVATE src/common) +ament_auto_add_library(aggregator SHARED + src/node/aggregator.cpp + src/node/availability.cpp +) +target_include_directories(aggregator PRIVATE src/common) + +rclcpp_components_register_node(aggregator + PLUGIN "diagnostic_graph_aggregator::AggregatorNode" + EXECUTABLE aggregator_node +) + if(BUILD_TESTING) get_filename_component(RESOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/test/files ABSOLUTE) ament_auto_add_gtest(gtest_${PROJECT_NAME} diff --git a/system/diagnostic_graph_aggregator/launch/aggregator.launch.xml b/system/diagnostic_graph_aggregator/launch/aggregator.launch.xml index 272901a3f8045..c06c3d1d96cfa 100644 --- a/system/diagnostic_graph_aggregator/launch/aggregator.launch.xml +++ b/system/diagnostic_graph_aggregator/launch/aggregator.launch.xml @@ -1,7 +1,7 @@ - + diff --git a/system/diagnostic_graph_aggregator/package.xml b/system/diagnostic_graph_aggregator/package.xml index 2a9efad2c0d6e..a89196f25a78d 100644 --- a/system/diagnostic_graph_aggregator/package.xml +++ b/system/diagnostic_graph_aggregator/package.xml @@ -12,6 +12,7 @@ diagnostic_msgs rclcpp + rclcpp_components tier4_system_msgs yaml_cpp_vendor diff --git a/system/diagnostic_graph_aggregator/src/node/aggregator.cpp b/system/diagnostic_graph_aggregator/src/node/aggregator.cpp index 3287d30d4de18..4d2ec73bfceca 100644 --- a/system/diagnostic_graph_aggregator/src/node/aggregator.cpp +++ b/system/diagnostic_graph_aggregator/src/node/aggregator.cpp @@ -21,7 +21,7 @@ namespace diagnostic_graph_aggregator { -AggregatorNode::AggregatorNode() : Node("aggregator") +AggregatorNode::AggregatorNode(const rclcpp::NodeOptions & options) : Node("aggregator", options) { const auto stamp = now(); @@ -99,14 +99,5 @@ void AggregatorNode::on_diag(const DiagnosticArray & msg) } // namespace diagnostic_graph_aggregator -int main(int argc, char ** argv) -{ - using diagnostic_graph_aggregator::AggregatorNode; - rclcpp::init(argc, argv); - rclcpp::executors::SingleThreadedExecutor executor; - auto node = std::make_shared(); - executor.add_node(node); - executor.spin(); - executor.remove_node(node); - rclcpp::shutdown(); -} +#include +RCLCPP_COMPONENTS_REGISTER_NODE(diagnostic_graph_aggregator::AggregatorNode) diff --git a/system/diagnostic_graph_aggregator/src/node/aggregator.hpp b/system/diagnostic_graph_aggregator/src/node/aggregator.hpp index 8a0e12edb25e5..f71780f19a5c7 100644 --- a/system/diagnostic_graph_aggregator/src/node/aggregator.hpp +++ b/system/diagnostic_graph_aggregator/src/node/aggregator.hpp @@ -30,7 +30,7 @@ namespace diagnostic_graph_aggregator class AggregatorNode : public rclcpp::Node { public: - AggregatorNode(); + explicit AggregatorNode(const rclcpp::NodeOptions & options); ~AggregatorNode(); private: