Skip to content

Commit 685b8b2

Browse files
authored
feat(autoware_utils_diagnostics): split package (#45)
Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp>
1 parent 4d67adb commit 685b8b2

File tree

10 files changed

+191
-45
lines changed

10 files changed

+191
-45
lines changed

autoware_utils/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ The geometry module provides classes and functions for handling 2D and 3D points
3333

3434
The ROS module provides utilities for working with ROS messages and nodes:
3535

36-
- **`diagnostics_interface.hpp`**: An interface for publishing diagnostic messages.
3736
- **`msg_covariance.hpp`**: Indices for accessing covariance matrices in ROS messages.
3837
- **`msg_operation.hpp`**: Overloaded operators for quaternion messages.
3938
- **`self_pose_listener.hpp`**: Listens to the self-pose of the vehicle.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 Autoware Foundation
1+
// Copyright 2025 The Autoware Contributors
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -15,47 +15,14 @@
1515
#ifndef AUTOWARE_UTILS__ROS__DIAGNOSTICS_INTERFACE_HPP_
1616
#define AUTOWARE_UTILS__ROS__DIAGNOSTICS_INTERFACE_HPP_
1717

18-
#include <rclcpp/rclcpp.hpp>
18+
// NOLINTBEGIN(build/namespaces, whitespace/line_length)
19+
// clang-format off
1920

20-
#include <diagnostic_msgs/msg/diagnostic_array.hpp>
21+
#pragma message("#include <autoware_utils/ros/diagnostics_interface.hpp> is deprecated. Use #include <autoware_utils_diagnostics/diagnostics_interface.hpp> instead.")
22+
#include <autoware_utils_diagnostics/diagnostics_interface.hpp>
23+
namespace autoware_utils { using namespace autoware_utils_diagnostics; }
2124

22-
#include <string>
23-
#include <vector>
24-
25-
namespace autoware_utils
26-
{
27-
class DiagnosticsInterface
28-
{
29-
public:
30-
DiagnosticsInterface(rclcpp::Node * node, const std::string & diagnostic_name);
31-
void clear();
32-
void add_key_value(const diagnostic_msgs::msg::KeyValue & key_value_msg);
33-
template <typename T>
34-
void add_key_value(const std::string & key, const T & value);
35-
void add_key_value(const std::string & key, const std::string & value);
36-
void add_key_value(const std::string & key, bool value);
37-
void update_level_and_message(const int8_t level, const std::string & message);
38-
void publish(const rclcpp::Time & publish_time_stamp);
39-
40-
private:
41-
[[nodiscard]] diagnostic_msgs::msg::DiagnosticArray create_diagnostics_array(
42-
const rclcpp::Time & publish_time_stamp) const;
43-
44-
rclcpp::Clock::SharedPtr clock_;
45-
rclcpp::Publisher<diagnostic_msgs::msg::DiagnosticArray>::SharedPtr diagnostics_pub_;
46-
47-
diagnostic_msgs::msg::DiagnosticStatus diagnostics_status_msg_;
48-
};
49-
50-
template <typename T>
51-
void DiagnosticsInterface::add_key_value(const std::string & key, const T & value)
52-
{
53-
diagnostic_msgs::msg::KeyValue key_value;
54-
key_value.key = key;
55-
key_value.value = std::to_string(value);
56-
add_key_value(key_value);
57-
}
58-
59-
} // namespace autoware_utils
25+
// clang-format on
26+
// NOLINTEND
6027

6128
#endif // AUTOWARE_UTILS__ROS__DIAGNOSTICS_INTERFACE_HPP_

autoware_utils/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<depend>autoware_perception_msgs</depend>
2121
<depend>autoware_planning_msgs</depend>
2222
<depend>autoware_utils_debug</depend>
23+
<depend>autoware_utils_diagnostics</depend>
2324
<depend>autoware_utils_geometry</depend>
2425
<depend>autoware_utils_logging</depend>
2526
<depend>autoware_utils_math</depend>
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(autoware_utils_diagnostics)
3+
4+
find_package(autoware_cmake REQUIRED)
5+
autoware_package()
6+
7+
ament_auto_add_library(${PROJECT_NAME} SHARED
8+
"src/diagnostics_interface.cpp"
9+
)
10+
11+
if(BUILD_TESTING)
12+
ament_add_ros_isolated_gtest(test_${PROJECT_NAME}
13+
"test/main.cpp"
14+
"test/cases/diagnostics_interface.cpp"
15+
)
16+
target_link_libraries(test_${PROJECT_NAME} ${PROJECT_NAME})
17+
endif()
18+
19+
ament_auto_package()

autoware_utils_diagnostics/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# autoware_utils_diagnostics
2+
3+
## Overview
4+
5+
The **autoware_utils** library is a comprehensive toolkit designed to facilitate the development of autonomous driving applications.
6+
This package provides essential utilities for diagnostics.
7+
It is extensively used in the Autoware project to handle common tasks such as handling diagnostic tasks.
8+
9+
## Design
10+
11+
- **`diagnostics_interface.hpp`**: An interface for publishing diagnostic messages.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2023 Autoware Foundation
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+
#ifndef AUTOWARE_UTILS_DIAGNOSTICS__DIAGNOSTICS_INTERFACE_HPP_
16+
#define AUTOWARE_UTILS_DIAGNOSTICS__DIAGNOSTICS_INTERFACE_HPP_
17+
18+
#include <rclcpp/rclcpp.hpp>
19+
20+
#include <diagnostic_msgs/msg/diagnostic_array.hpp>
21+
22+
#include <string>
23+
#include <vector>
24+
25+
namespace autoware_utils_diagnostics
26+
{
27+
class DiagnosticsInterface
28+
{
29+
public:
30+
DiagnosticsInterface(rclcpp::Node * node, const std::string & diagnostic_name);
31+
void clear();
32+
void add_key_value(const diagnostic_msgs::msg::KeyValue & key_value_msg);
33+
template <typename T>
34+
void add_key_value(const std::string & key, const T & value);
35+
void add_key_value(const std::string & key, const std::string & value);
36+
void add_key_value(const std::string & key, bool value);
37+
void update_level_and_message(const int8_t level, const std::string & message);
38+
void publish(const rclcpp::Time & publish_time_stamp);
39+
40+
private:
41+
[[nodiscard]] diagnostic_msgs::msg::DiagnosticArray create_diagnostics_array(
42+
const rclcpp::Time & publish_time_stamp) const;
43+
44+
rclcpp::Clock::SharedPtr clock_;
45+
rclcpp::Publisher<diagnostic_msgs::msg::DiagnosticArray>::SharedPtr diagnostics_pub_;
46+
47+
diagnostic_msgs::msg::DiagnosticStatus diagnostics_status_msg_;
48+
};
49+
50+
template <typename T>
51+
void DiagnosticsInterface::add_key_value(const std::string & key, const T & value)
52+
{
53+
diagnostic_msgs::msg::KeyValue key_value;
54+
key_value.key = key;
55+
key_value.value = std::to_string(value);
56+
add_key_value(key_value);
57+
}
58+
59+
} // namespace autoware_utils_diagnostics
60+
61+
#endif // AUTOWARE_UTILS_DIAGNOSTICS__DIAGNOSTICS_INTERFACE_HPP_
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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>autoware_utils_diagnostics</name>
5+
<version>1.1.0</version>
6+
<description>The autoware_utils_diagnostics package</description>
7+
<maintainer email="egon.kang@autocore.ai">Jian Kang</maintainer>
8+
<maintainer email="ryohsuke.mitsudome@tier4.jp">Ryohsuke Mitsudome</maintainer>
9+
<maintainer email="esteve.fernandez@tier4.jp">Esteve Fernandez</maintainer>
10+
<maintainer email="yutaka.kondo@tier4.jp">Yutaka Kondo</maintainer>
11+
<maintainer email="isamu.takagi@tier4.jp">Takagi, Isamu</maintainer>
12+
<license>Apache License 2.0</license>
13+
14+
<buildtool_depend>ament_cmake_auto</buildtool_depend>
15+
<buildtool_depend>autoware_cmake</buildtool_depend>
16+
17+
<depend>diagnostic_msgs</depend>
18+
<depend>rclcpp</depend>
19+
20+
<test_depend>ament_cmake_ros</test_depend>
21+
<test_depend>ament_lint_auto</test_depend>
22+
<test_depend>autoware_lint_common</test_depend>
23+
24+
<export>
25+
<build_type>ament_cmake</build_type>
26+
</export>
27+
</package>

autoware_utils/src/ros/diagnostics_interface.cpp autoware_utils_diagnostics/src/diagnostics_interface.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "autoware_utils/ros/diagnostics_interface.hpp"
15+
#include "autoware_utils_diagnostics/diagnostics_interface.hpp"
1616

1717
#include <rclcpp/rclcpp.hpp>
1818

@@ -21,7 +21,7 @@
2121
#include <algorithm>
2222
#include <string>
2323

24-
namespace autoware_utils
24+
namespace autoware_utils_diagnostics
2525
{
2626
DiagnosticsInterface::DiagnosticsInterface(rclcpp::Node * node, const std::string & diagnostic_name)
2727
: clock_(node->get_clock())
@@ -103,4 +103,4 @@ diagnostic_msgs::msg::DiagnosticArray DiagnosticsInterface::create_diagnostics_a
103103

104104
return diagnostics_msg;
105105
}
106-
} // namespace autoware_utils
106+
} // namespace autoware_utils_diagnostics
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2025 The Autoware Contributors
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+
#include "autoware_utils_diagnostics/diagnostics_interface.hpp"
16+
17+
#include <gtest/gtest.h>
18+
19+
#include <memory>
20+
21+
TEST(TestDiagnosticsInterface, Instantiation)
22+
{
23+
const auto node = std::make_shared<rclcpp::Node>("test_node");
24+
autoware_utils_diagnostics::DiagnosticsInterface(node.get(), "diag_name");
25+
}
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2025 The Autoware Contributors
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+
#include <rclcpp/rclcpp.hpp>
16+
17+
#include <gtest/gtest.h>
18+
19+
class RclcppEnvironment : public testing::Environment
20+
{
21+
public:
22+
RclcppEnvironment(int argc, char ** argv) : argc(argc), argv(argv) {}
23+
void SetUp() override { rclcpp::init(argc, argv); }
24+
void TearDown() override { rclcpp::shutdown(); }
25+
26+
private:
27+
int argc;
28+
char ** argv;
29+
};
30+
31+
int main(int argc, char ** argv)
32+
{
33+
testing::InitGoogleTest(&argc, argv);
34+
testing::AddGlobalTestEnvironment(new RclcppEnvironment(argc, argv));
35+
return RUN_ALL_TESTS();
36+
}

0 commit comments

Comments
 (0)