From 4a7a2a342d726de2eae29c157106b3b0c94bdd3c Mon Sep 17 00:00:00 2001 From: Kento Yabuuchi Date: Wed, 19 Jun 2024 09:29:45 +0900 Subject: [PATCH] feat(yabloc_monitor): componentize yabloc_monitor node (#7509) * change node to component Signed-off-by: Kento Yabuuchi * fix launch file & cmake Signed-off-by: Kento Yabuuchi --------- Signed-off-by: Kento Yabuuchi Signed-off-by: Simon Eisenmann --- .../yabloc/yabloc_monitor/CMakeLists.txt | 10 +++++-- .../launch/yabloc_monitor.launch.xml | 2 +- .../yabloc/yabloc_monitor/package.xml | 1 + .../src/yabloc_monitor_core.cpp | 6 +++- .../src/yabloc_monitor_core.hpp | 2 +- .../src/yabloc_monitor_node.cpp | 28 ------------------- 6 files changed, 15 insertions(+), 34 deletions(-) delete mode 100644 localization/yabloc/yabloc_monitor/src/yabloc_monitor_node.cpp diff --git a/localization/yabloc/yabloc_monitor/CMakeLists.txt b/localization/yabloc/yabloc_monitor/CMakeLists.txt index aa1515661b2f6..7267cda53714f 100644 --- a/localization/yabloc/yabloc_monitor/CMakeLists.txt +++ b/localization/yabloc/yabloc_monitor/CMakeLists.txt @@ -4,12 +4,16 @@ project(yabloc_monitor) find_package(autoware_cmake REQUIRED) autoware_package() -ament_auto_add_executable(yabloc_monitor - src/yabloc_monitor_node.cpp +ament_auto_add_library(${PROJECT_NAME} src/yabloc_monitor_core.cpp src/availability_module.cpp ) -ament_target_dependencies(yabloc_monitor) + +rclcpp_components_register_node(${PROJECT_NAME} + PLUGIN "YabLocMonitor" + EXECUTABLE ${PROJECT_NAME}_node + EXECUTOR SingleThreadedExecutor +) ament_auto_package( INSTALL_TO_SHARE diff --git a/localization/yabloc/yabloc_monitor/launch/yabloc_monitor.launch.xml b/localization/yabloc/yabloc_monitor/launch/yabloc_monitor.launch.xml index cf9f73977d35d..3073208e2e1a2 100644 --- a/localization/yabloc/yabloc_monitor/launch/yabloc_monitor.launch.xml +++ b/localization/yabloc/yabloc_monitor/launch/yabloc_monitor.launch.xml @@ -1,7 +1,7 @@ - + diff --git a/localization/yabloc/yabloc_monitor/package.xml b/localization/yabloc/yabloc_monitor/package.xml index 22a5d0eded6b6..a42a734dbab31 100644 --- a/localization/yabloc/yabloc_monitor/package.xml +++ b/localization/yabloc/yabloc_monitor/package.xml @@ -20,6 +20,7 @@ diagnostic_updater geometry_msgs rclcpp + rclcpp_components ament_cmake_gtest ament_lint_auto diff --git a/localization/yabloc/yabloc_monitor/src/yabloc_monitor_core.cpp b/localization/yabloc/yabloc_monitor/src/yabloc_monitor_core.cpp index 876b86fd2bc9e..31e6ec9c51e7a 100644 --- a/localization/yabloc/yabloc_monitor/src/yabloc_monitor_core.cpp +++ b/localization/yabloc/yabloc_monitor/src/yabloc_monitor_core.cpp @@ -18,7 +18,8 @@ #include -YabLocMonitor::YabLocMonitor() : Node("yabloc_monitor"), updater_(this) +YabLocMonitor::YabLocMonitor(const rclcpp::NodeOptions & options) +: Node("yabloc_monitor", options), updater_(this) { updater_.setHardwareID(get_name()); updater_.add("yabloc_status", this, &YabLocMonitor::update_diagnostics); @@ -46,3 +47,6 @@ void YabLocMonitor::update_diagnostics(diagnostic_updater::DiagnosticStatusWrapp stat.summary(diagnostic_msgs::msg::DiagnosticStatus::ERROR, "NG"); } } + +#include +RCLCPP_COMPONENTS_REGISTER_NODE(YabLocMonitor) diff --git a/localization/yabloc/yabloc_monitor/src/yabloc_monitor_core.hpp b/localization/yabloc/yabloc_monitor/src/yabloc_monitor_core.hpp index 8b8b937da205b..5dd46d63de6f2 100644 --- a/localization/yabloc/yabloc_monitor/src/yabloc_monitor_core.hpp +++ b/localization/yabloc/yabloc_monitor/src/yabloc_monitor_core.hpp @@ -25,7 +25,7 @@ class YabLocMonitor : public rclcpp::Node { public: - YabLocMonitor(); + explicit YabLocMonitor(const rclcpp::NodeOptions & options = rclcpp::NodeOptions()); private: void update_diagnostics(diagnostic_updater::DiagnosticStatusWrapper & stat); diff --git a/localization/yabloc/yabloc_monitor/src/yabloc_monitor_node.cpp b/localization/yabloc/yabloc_monitor/src/yabloc_monitor_node.cpp deleted file mode 100644 index 9b58325c852ea..0000000000000 --- a/localization/yabloc/yabloc_monitor/src/yabloc_monitor_node.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2023 TIER IV -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "yabloc_monitor_core.hpp" - -#include - -int main(int argc, char ** argv) -{ - rclcpp::init(argc, argv); - rclcpp::NodeOptions node_options; - auto node = std::make_shared(); - - rclcpp::spin(node); - - return 0; -}