From b318bc0c33fa73cd04a17f085eaa9f64497b6f0c Mon Sep 17 00:00:00 2001 From: "Takagi, Isamu" Date: Fri, 7 Mar 2025 12:00:22 +0900 Subject: [PATCH] feat(autoware_utils_diagnostics): split package Signed-off-by: Takagi, Isamu --- autoware_utils/README.md | 1 - .../ros/diagnostics_interface.hpp | 49 +++------------ autoware_utils/package.xml | 1 + autoware_utils_diagnostics/CMakeLists.txt | 19 ++++++ autoware_utils_diagnostics/README.md | 11 ++++ .../diagnostics_interface.hpp | 61 +++++++++++++++++++ autoware_utils_diagnostics/package.xml | 27 ++++++++ .../src}/diagnostics_interface.cpp | 6 +- .../test/cases/diagnostics_interface.cpp | 25 ++++++++ autoware_utils_diagnostics/test/main.cpp | 36 +++++++++++ 10 files changed, 191 insertions(+), 45 deletions(-) create mode 100644 autoware_utils_diagnostics/CMakeLists.txt create mode 100644 autoware_utils_diagnostics/README.md create mode 100644 autoware_utils_diagnostics/include/autoware_utils_diagnostics/diagnostics_interface.hpp create mode 100644 autoware_utils_diagnostics/package.xml rename {autoware_utils/src/ros => autoware_utils_diagnostics/src}/diagnostics_interface.cpp (95%) create mode 100644 autoware_utils_diagnostics/test/cases/diagnostics_interface.cpp create mode 100644 autoware_utils_diagnostics/test/main.cpp diff --git a/autoware_utils/README.md b/autoware_utils/README.md index bb4236a..481e8df 100644 --- a/autoware_utils/README.md +++ b/autoware_utils/README.md @@ -34,7 +34,6 @@ The geometry module provides classes and functions for handling 2D and 3D points The ROS module provides utilities for working with ROS messages and nodes: - **`debug_publisher.hpp`**: A helper class for publishing debug messages with timestamps. -- **`diagnostics_interface.hpp`**: An interface for publishing diagnostic messages. - **`msg_covariance.hpp`**: Indices for accessing covariance matrices in ROS messages. - **`msg_operation.hpp`**: Overloaded operators for quaternion messages. - **`processing_time_publisher.hpp`**: Publishes processing times as diagnostic messages. diff --git a/autoware_utils/include/autoware_utils/ros/diagnostics_interface.hpp b/autoware_utils/include/autoware_utils/ros/diagnostics_interface.hpp index 96be191..cb71fe1 100644 --- a/autoware_utils/include/autoware_utils/ros/diagnostics_interface.hpp +++ b/autoware_utils/include/autoware_utils/ros/diagnostics_interface.hpp @@ -1,4 +1,4 @@ -// Copyright 2023 Autoware Foundation +// Copyright 2025 The Autoware Contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,47 +15,14 @@ #ifndef AUTOWARE_UTILS__ROS__DIAGNOSTICS_INTERFACE_HPP_ #define AUTOWARE_UTILS__ROS__DIAGNOSTICS_INTERFACE_HPP_ -#include +// NOLINTBEGIN(build/namespaces, whitespace/line_length) +// clang-format off -#include +#pragma message("#include is deprecated. Use #include instead.") +#include +namespace autoware_utils { using namespace autoware_utils_diagnostics; } -#include -#include - -namespace autoware_utils -{ -class DiagnosticsInterface -{ -public: - DiagnosticsInterface(rclcpp::Node * node, const std::string & diagnostic_name); - void clear(); - void add_key_value(const diagnostic_msgs::msg::KeyValue & key_value_msg); - template - void add_key_value(const std::string & key, const T & value); - void add_key_value(const std::string & key, const std::string & value); - void add_key_value(const std::string & key, bool value); - void update_level_and_message(const int8_t level, const std::string & message); - void publish(const rclcpp::Time & publish_time_stamp); - -private: - [[nodiscard]] diagnostic_msgs::msg::DiagnosticArray create_diagnostics_array( - const rclcpp::Time & publish_time_stamp) const; - - rclcpp::Clock::SharedPtr clock_; - rclcpp::Publisher::SharedPtr diagnostics_pub_; - - diagnostic_msgs::msg::DiagnosticStatus diagnostics_status_msg_; -}; - -template -void DiagnosticsInterface::add_key_value(const std::string & key, const T & value) -{ - diagnostic_msgs::msg::KeyValue key_value; - key_value.key = key; - key_value.value = std::to_string(value); - add_key_value(key_value); -} - -} // namespace autoware_utils +// clang-format on +// NOLINTEND #endif // AUTOWARE_UTILS__ROS__DIAGNOSTICS_INTERFACE_HPP_ diff --git a/autoware_utils/package.xml b/autoware_utils/package.xml index ca76554..4211c19 100644 --- a/autoware_utils/package.xml +++ b/autoware_utils/package.xml @@ -19,6 +19,7 @@ autoware_internal_planning_msgs autoware_perception_msgs autoware_planning_msgs + autoware_utils_diagnostics autoware_utils_geometry autoware_utils_logging autoware_utils_math diff --git a/autoware_utils_diagnostics/CMakeLists.txt b/autoware_utils_diagnostics/CMakeLists.txt new file mode 100644 index 0000000..cf7939b --- /dev/null +++ b/autoware_utils_diagnostics/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.14) +project(autoware_utils_diagnostics) + +find_package(autoware_cmake REQUIRED) +autoware_package() + +ament_auto_add_library(${PROJECT_NAME} SHARED + "src/diagnostics_interface.cpp" +) + +if(BUILD_TESTING) + ament_add_ros_isolated_gtest(test_${PROJECT_NAME} + "test/main.cpp" + "test/cases/diagnostics_interface.cpp" + ) + target_link_libraries(test_${PROJECT_NAME} ${PROJECT_NAME}) +endif() + +ament_auto_package() diff --git a/autoware_utils_diagnostics/README.md b/autoware_utils_diagnostics/README.md new file mode 100644 index 0000000..e90eb84 --- /dev/null +++ b/autoware_utils_diagnostics/README.md @@ -0,0 +1,11 @@ +# autoware_utils_diagnostics + +## Overview + +The **autoware_utils** library is a comprehensive toolkit designed to facilitate the development of autonomous driving applications. +This package provides essential utilities for diagnostics. +It is extensively used in the Autoware project to handle common tasks such as handling diagnostic tasks. + +## Design + +- **`diagnostics_interface.hpp`**: An interface for publishing diagnostic messages. diff --git a/autoware_utils_diagnostics/include/autoware_utils_diagnostics/diagnostics_interface.hpp b/autoware_utils_diagnostics/include/autoware_utils_diagnostics/diagnostics_interface.hpp new file mode 100644 index 0000000..2518e64 --- /dev/null +++ b/autoware_utils_diagnostics/include/autoware_utils_diagnostics/diagnostics_interface.hpp @@ -0,0 +1,61 @@ +// Copyright 2023 Autoware Foundation +// +// 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. + +#ifndef AUTOWARE_UTILS_DIAGNOSTICS__DIAGNOSTICS_INTERFACE_HPP_ +#define AUTOWARE_UTILS_DIAGNOSTICS__DIAGNOSTICS_INTERFACE_HPP_ + +#include + +#include + +#include +#include + +namespace autoware_utils_diagnostics +{ +class DiagnosticsInterface +{ +public: + DiagnosticsInterface(rclcpp::Node * node, const std::string & diagnostic_name); + void clear(); + void add_key_value(const diagnostic_msgs::msg::KeyValue & key_value_msg); + template + void add_key_value(const std::string & key, const T & value); + void add_key_value(const std::string & key, const std::string & value); + void add_key_value(const std::string & key, bool value); + void update_level_and_message(const int8_t level, const std::string & message); + void publish(const rclcpp::Time & publish_time_stamp); + +private: + [[nodiscard]] diagnostic_msgs::msg::DiagnosticArray create_diagnostics_array( + const rclcpp::Time & publish_time_stamp) const; + + rclcpp::Clock::SharedPtr clock_; + rclcpp::Publisher::SharedPtr diagnostics_pub_; + + diagnostic_msgs::msg::DiagnosticStatus diagnostics_status_msg_; +}; + +template +void DiagnosticsInterface::add_key_value(const std::string & key, const T & value) +{ + diagnostic_msgs::msg::KeyValue key_value; + key_value.key = key; + key_value.value = std::to_string(value); + add_key_value(key_value); +} + +} // namespace autoware_utils_diagnostics + +#endif // AUTOWARE_UTILS_DIAGNOSTICS__DIAGNOSTICS_INTERFACE_HPP_ diff --git a/autoware_utils_diagnostics/package.xml b/autoware_utils_diagnostics/package.xml new file mode 100644 index 0000000..117b286 --- /dev/null +++ b/autoware_utils_diagnostics/package.xml @@ -0,0 +1,27 @@ + + + + autoware_utils_diagnostics + 1.1.0 + The autoware_utils_diagnostics package + Jian Kang + Ryohsuke Mitsudome + Esteve Fernandez + Yutaka Kondo + Takagi, Isamu + Apache License 2.0 + + ament_cmake_auto + autoware_cmake + + diagnostic_msgs + rclcpp + + ament_cmake_ros + ament_lint_auto + autoware_lint_common + + + ament_cmake + + diff --git a/autoware_utils/src/ros/diagnostics_interface.cpp b/autoware_utils_diagnostics/src/diagnostics_interface.cpp similarity index 95% rename from autoware_utils/src/ros/diagnostics_interface.cpp rename to autoware_utils_diagnostics/src/diagnostics_interface.cpp index 060482f..9a305c3 100644 --- a/autoware_utils/src/ros/diagnostics_interface.cpp +++ b/autoware_utils_diagnostics/src/diagnostics_interface.cpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "autoware_utils/ros/diagnostics_interface.hpp" +#include "autoware_utils_diagnostics/diagnostics_interface.hpp" #include @@ -21,7 +21,7 @@ #include #include -namespace autoware_utils +namespace autoware_utils_diagnostics { DiagnosticsInterface::DiagnosticsInterface(rclcpp::Node * node, const std::string & diagnostic_name) : clock_(node->get_clock()) @@ -103,4 +103,4 @@ diagnostic_msgs::msg::DiagnosticArray DiagnosticsInterface::create_diagnostics_a return diagnostics_msg; } -} // namespace autoware_utils +} // namespace autoware_utils_diagnostics diff --git a/autoware_utils_diagnostics/test/cases/diagnostics_interface.cpp b/autoware_utils_diagnostics/test/cases/diagnostics_interface.cpp new file mode 100644 index 0000000..d454d4a --- /dev/null +++ b/autoware_utils_diagnostics/test/cases/diagnostics_interface.cpp @@ -0,0 +1,25 @@ +// Copyright 2025 The Autoware Contributors +// +// 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 "autoware_utils_diagnostics/diagnostics_interface.hpp" + +#include + +#include + +TEST(TestDiagnosticsInterface, Instantiation) +{ + const auto node = std::make_shared("test_node"); + autoware_utils_diagnostics::DiagnosticsInterface(node.get(), "diag_name"); +} diff --git a/autoware_utils_diagnostics/test/main.cpp b/autoware_utils_diagnostics/test/main.cpp new file mode 100644 index 0000000..42f409f --- /dev/null +++ b/autoware_utils_diagnostics/test/main.cpp @@ -0,0 +1,36 @@ +// Copyright 2025 The Autoware Contributors +// +// 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 + +#include + +class RclcppEnvironment : public testing::Environment +{ +public: + RclcppEnvironment(int argc, char ** argv) : argc(argc), argv(argv) {} + void SetUp() override { rclcpp::init(argc, argv); } + void TearDown() override { rclcpp::shutdown(); } + +private: + int argc; + char ** argv; +}; + +int main(int argc, char ** argv) +{ + testing::InitGoogleTest(&argc, argv); + testing::AddGlobalTestEnvironment(new RclcppEnvironment(argc, argv)); + return RUN_ALL_TESTS(); +}