Skip to content

Commit 4d67adb

Browse files
authored
feat(autoware_utils_debug): split package (#44)
* feat(autoware_utils_system): split package Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * update for compatibility Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * feat(autoware_utils_debug): split package Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * apply testing utils Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * feat(autoware_utils_testing): create test utils Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * update test Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * add mock node Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * add test Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * update readme Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * remove testing Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * compatibility Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * fix sample code namespace Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> --------- Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp>
1 parent 009d98c commit 4d67adb

22 files changed

+915
-527
lines changed

autoware_utils/README.md

-60
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,10 @@ 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-
- **`debug_publisher.hpp`**: A helper class for publishing debug messages with timestamps.
3736
- **`diagnostics_interface.hpp`**: An interface for publishing diagnostic messages.
3837
- **`msg_covariance.hpp`**: Indices for accessing covariance matrices in ROS messages.
3938
- **`msg_operation.hpp`**: Overloaded operators for quaternion messages.
40-
- **`processing_time_publisher.hpp`**: Publishes processing times as diagnostic messages.
41-
- **`published_time_publisher.hpp`**: Tracks and publishes the time when messages are published.
4239
- **`self_pose_listener.hpp`**: Listens to the self-pose of the vehicle.
43-
- **`debug_traits.hpp`**: Traits for identifying debug message types.
44-
45-
#### System Module
46-
47-
The system module provides low-level utilities for performance monitoring and error handling:
48-
49-
- **`time_keeper.hpp`**: Tracks and reports the processing time of various functions.
5040

5141
## Usage
5242

@@ -91,33 +81,6 @@ int main() {
9181
9282
### Detailed Usage Examples
9383
94-
#### Logging Processing Times with ProcessingTimePublisher
95-
96-
```cpp
97-
#include "autoware_utils/ros/processing_time_publisher.hpp"
98-
#include <rclcpp/rclcpp.hpp>
99-
#include <map>
100-
101-
int main(int argc, char * argv[]) {
102-
rclcpp::init(argc, argv);
103-
auto node = rclcpp::Node::make_shared("processing_time_node");
104-
105-
// Initialize ProcessingTimePublisher
106-
autoware_utils::ProcessingTimePublisher processing_time_pub(node.get(), "~/debug/processing_time_ms");
107-
108-
// Simulate some processing times
109-
std::map<std::string, double> processing_times = {
110-
{"node1", 0.1}, {"node2", 0.2}, {"node3", 0.3}
111-
};
112-
113-
// Publish processing times
114-
processing_time_pub.publish(processing_times);
115-
116-
rclcpp::shutdown();
117-
return 0;
118-
}
119-
```
120-
12184
#### Manipulating Polygons with boost_polygon_utils.hpp
12285
12386
```cpp
@@ -146,26 +109,3 @@ int main(int argc, char * argv[]) {
146109
return 0;
147110
}
148111
```
149-
150-
#### Handling Debug Message Types with debug_traits.hpp
151-
152-
```cpp
153-
#include "autoware_utils/ros/debug_publisher.hpp"
154-
#include "autoware_utils/ros/debug_traits.hpp"
155-
#include <rclcpp/rclcpp.hpp>
156-
157-
int main(int argc, char * argv[]) {
158-
rclcpp::init(argc, argv);
159-
auto node = rclcpp::Node::make_shared("debug_node");
160-
161-
// Initialize DebugPublisher
162-
autoware_utils::DebugPublisher debug_pub(node, "/debug");
163-
164-
// Publish a debug message with custom type
165-
float debug_data = 42.0;
166-
debug_pub.publish<autoware_internal_debug_msgs::msg::Float32Stamped>("example", debug_data);
167-
168-
rclcpp::shutdown();
169-
return 0;
170-
}
171-
```
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 Tier IV, Inc.
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,63 +15,14 @@
1515
#ifndef AUTOWARE_UTILS__ROS__DEBUG_PUBLISHER_HPP_
1616
#define AUTOWARE_UTILS__ROS__DEBUG_PUBLISHER_HPP_
1717

18-
#include "autoware_utils/ros/debug_traits.hpp"
18+
// NOLINTBEGIN(build/namespaces, whitespace/line_length)
19+
// clang-format off
1920

20-
#include <rclcpp/publisher_base.hpp>
21-
#include <rclcpp/rclcpp.hpp>
22-
#include <rosidl_runtime_cpp/traits.hpp>
21+
#pragma message("#include <autoware_utils/ros/debug_publisher.hpp> is deprecated. Use #include <autoware_utils_debug/debug_publisher.hpp> instead.")
22+
#include <autoware_utils_debug/debug_publisher.hpp>
23+
namespace autoware_utils { using namespace autoware_utils_debug; }
2324

24-
#include <memory>
25-
#include <string>
26-
#include <unordered_map>
27-
28-
namespace autoware_utils
29-
{
30-
namespace debug_publisher
31-
{
32-
template <
33-
class T_msg, class T,
34-
std::enable_if_t<autoware_utils::debug_traits::is_debug_message<T_msg>::value, std::nullptr_t> =
35-
nullptr>
36-
T_msg to_debug_msg(const T & data, const rclcpp::Time & stamp)
37-
{
38-
T_msg msg;
39-
msg.stamp = stamp;
40-
msg.data = data;
41-
return msg;
42-
}
43-
} // namespace debug_publisher
44-
45-
class DebugPublisher
46-
{
47-
public:
48-
explicit DebugPublisher(rclcpp::Node * node, const char * ns) : node_(node), ns_(ns) {}
49-
50-
template <
51-
class T,
52-
std::enable_if_t<rosidl_generator_traits::is_message<T>::value, std::nullptr_t> = nullptr>
53-
void publish(const std::string & name, const T & data, const rclcpp::QoS & qos = rclcpp::QoS(1))
54-
{
55-
if (pub_map_.count(name) == 0) {
56-
pub_map_[name] = node_->create_publisher<T>(std::string(ns_) + "/" + name, qos);
57-
}
58-
59-
std::dynamic_pointer_cast<rclcpp::Publisher<T>>(pub_map_.at(name))->publish(data);
60-
}
61-
62-
template <
63-
class T_msg, class T,
64-
std::enable_if_t<!rosidl_generator_traits::is_message<T>::value, std::nullptr_t> = nullptr>
65-
void publish(const std::string & name, const T & data, const rclcpp::QoS & qos = rclcpp::QoS(1))
66-
{
67-
publish(name, debug_publisher::to_debug_msg<T_msg>(data, node_->now()), qos);
68-
}
69-
70-
private:
71-
rclcpp::Node * node_;
72-
const char * ns_;
73-
std::unordered_map<std::string, std::shared_ptr<rclcpp::PublisherBase>> pub_map_;
74-
};
75-
} // namespace autoware_utils
25+
// clang-format on
26+
// NOLINTEND
7627

7728
#endif // AUTOWARE_UTILS__ROS__DEBUG_PUBLISHER_HPP_
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 Tier IV, Inc.
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,77 +15,14 @@
1515
#ifndef AUTOWARE_UTILS__ROS__DEBUG_TRAITS_HPP_
1616
#define AUTOWARE_UTILS__ROS__DEBUG_TRAITS_HPP_
1717

18-
#include <autoware_internal_debug_msgs/msg/bool_stamped.hpp>
19-
#include <autoware_internal_debug_msgs/msg/float32_multi_array_stamped.hpp>
20-
#include <autoware_internal_debug_msgs/msg/float32_stamped.hpp>
21-
#include <autoware_internal_debug_msgs/msg/float64_multi_array_stamped.hpp>
22-
#include <autoware_internal_debug_msgs/msg/float64_stamped.hpp>
23-
#include <autoware_internal_debug_msgs/msg/int32_multi_array_stamped.hpp>
24-
#include <autoware_internal_debug_msgs/msg/int32_stamped.hpp>
25-
#include <autoware_internal_debug_msgs/msg/int64_multi_array_stamped.hpp>
26-
#include <autoware_internal_debug_msgs/msg/int64_stamped.hpp>
27-
#include <autoware_internal_debug_msgs/msg/string_stamped.hpp>
18+
// NOLINTBEGIN(build/namespaces, whitespace/line_length)
19+
// clang-format off
2820

29-
#include <type_traits>
21+
#pragma message("#include <autoware_utils/ros/debug_traits.hpp> is deprecated. Use #include <autoware_utils_debug/debug_traits.hpp> instead.")
22+
#include <autoware_utils_debug/debug_traits.hpp>
23+
namespace autoware_utils { using namespace autoware_utils_debug; }
3024

31-
namespace autoware_utils::debug_traits
32-
{
33-
template <typename T>
34-
struct is_debug_message : std::false_type
35-
{
36-
};
37-
38-
template <>
39-
struct is_debug_message<autoware_internal_debug_msgs::msg::BoolStamped> : std::true_type
40-
{
41-
};
42-
43-
template <>
44-
struct is_debug_message<autoware_internal_debug_msgs::msg::Float32MultiArrayStamped>
45-
: std::true_type
46-
{
47-
};
48-
49-
template <>
50-
struct is_debug_message<autoware_internal_debug_msgs::msg::Float32Stamped> : std::true_type
51-
{
52-
};
53-
54-
template <>
55-
struct is_debug_message<autoware_internal_debug_msgs::msg::Float64MultiArrayStamped>
56-
: std::true_type
57-
{
58-
};
59-
60-
template <>
61-
struct is_debug_message<autoware_internal_debug_msgs::msg::Float64Stamped> : std::true_type
62-
{
63-
};
64-
65-
template <>
66-
struct is_debug_message<autoware_internal_debug_msgs::msg::Int32MultiArrayStamped> : std::true_type
67-
{
68-
};
69-
70-
template <>
71-
struct is_debug_message<autoware_internal_debug_msgs::msg::Int32Stamped> : std::true_type
72-
{
73-
};
74-
75-
template <>
76-
struct is_debug_message<autoware_internal_debug_msgs::msg::Int64MultiArrayStamped> : std::true_type
77-
{
78-
};
79-
80-
template <>
81-
struct is_debug_message<autoware_internal_debug_msgs::msg::Int64Stamped> : std::true_type
82-
{
83-
};
84-
85-
template <>
86-
struct is_debug_message<autoware_internal_debug_msgs::msg::StringStamped> : std::true_type
87-
{
88-
};
89-
} // namespace autoware_utils::debug_traits
25+
// clang-format on
26+
// NOLINTEND
9027

9128
#endif // AUTOWARE_UTILS__ROS__DEBUG_TRAITS_HPP_
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 Tier IV, Inc.
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,53 +15,14 @@
1515
#ifndef AUTOWARE_UTILS__ROS__PROCESSING_TIME_PUBLISHER_HPP_
1616
#define AUTOWARE_UTILS__ROS__PROCESSING_TIME_PUBLISHER_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_status.hpp>
21+
#pragma message("#include <autoware_utils/ros/processing_time_publisher.hpp> is deprecated. Use #include <autoware_utils_debug/processing_time_publisher.hpp> instead.")
22+
#include <autoware_utils_debug/processing_time_publisher.hpp>
23+
namespace autoware_utils { using namespace autoware_utils_debug; }
2124

22-
#include <map>
23-
#include <sstream>
24-
#include <string>
25-
26-
namespace autoware_utils
27-
{
28-
class ProcessingTimePublisher
29-
{
30-
public:
31-
explicit ProcessingTimePublisher(
32-
rclcpp::Node * node, const std::string & name = "~/debug/processing_time_ms",
33-
const rclcpp::QoS & qos = rclcpp::QoS(1))
34-
{
35-
pub_processing_time_ =
36-
node->create_publisher<diagnostic_msgs::msg::DiagnosticStatus>(name, qos);
37-
}
38-
39-
void publish(const std::map<std::string, double> & processing_time_map)
40-
{
41-
diagnostic_msgs::msg::DiagnosticStatus status;
42-
43-
for (const auto & m : processing_time_map) {
44-
diagnostic_msgs::msg::KeyValue key_value;
45-
key_value.key = m.first;
46-
key_value.value = to_string_with_precision(m.second, 3);
47-
status.values.push_back(key_value);
48-
}
49-
50-
pub_processing_time_->publish(status);
51-
}
52-
53-
private:
54-
rclcpp::Publisher<diagnostic_msgs::msg::DiagnosticStatus>::SharedPtr pub_processing_time_;
55-
56-
template <class T>
57-
std::string to_string_with_precision(const T & value, const int precision)
58-
{
59-
std::ostringstream oss;
60-
oss.precision(precision);
61-
oss << std::fixed << value;
62-
return oss.str();
63-
}
64-
};
65-
} // namespace autoware_utils
25+
// clang-format on
26+
// NOLINTEND
6627

6728
#endif // AUTOWARE_UTILS__ROS__PROCESSING_TIME_PUBLISHER_HPP_

0 commit comments

Comments
 (0)