Skip to content

Commit c11a2c6

Browse files
committed
change to timer callback to check the error
Signed-off-by: a-maumau <maumaumaumaumaumaumaumaumaumau@gmail.com>
1 parent cbedc0f commit c11a2c6

File tree

3 files changed

+65
-21
lines changed

3 files changed

+65
-21
lines changed

perception/autoware_lidar_centerpoint/config/centerpoint_diagnostics.param.yaml

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# When the processing time exceeds the max_allowed_processing_time,
44
# a warning will be triggered.
55
max_allowed_processing_time: 200.0 # in milliseconds
6-
# If the warning is triggered more than max_consecutive_warn_count times in a row,
7-
# an error diagnostic message will be sent.
8-
max_consecutive_warn_count: 10
6+
# If the warning is triggered and if a timestamp of last normal processing is more than
7+
# max_acceptable_consecutive_delay_ms, an error diagnostic message will be sent.
8+
max_acceptable_consecutive_delay_ms: 1000.0
9+
# interval of diagnostic callback in milliseconds
10+
validation_callback_interval_ms: 100 # in milliseconds, in integer

perception/autoware_lidar_centerpoint/include/autoware/lidar_centerpoint/node.hpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <autoware_perception_msgs/msg/object_classification.hpp>
3131
#include <autoware_perception_msgs/msg/shape.hpp>
3232
#include <sensor_msgs/msg/point_cloud2.hpp>
33+
#include <std_msgs/msg/header.hpp>
3334

3435
#include <memory>
3536
#include <string>
@@ -45,6 +46,7 @@ class LidarCenterPointNode : public rclcpp::Node
4546

4647
private:
4748
void pointCloudCallback(const sensor_msgs::msg::PointCloud2::ConstSharedPtr input_pointcloud_msg);
49+
void diagnosticsTimerCallback();
4850

4951
tf2_ros::Buffer tf_buffer_;
5052
tf2_ros::TransformListener tf_listener_{tf_buffer_};
@@ -55,15 +57,20 @@ class LidarCenterPointNode : public rclcpp::Node
5557
std::vector<std::string> class_names_;
5658
bool has_variance_{false};
5759
bool has_twist_{false};
58-
float max_allowed_processing_time_;
59-
int max_consecutive_warn_count_;
60-
int consecutive_delay_count_ = 0;
60+
61+
bool is_processing_delayed_{false};
62+
double max_allowed_processing_time_;
63+
double max_acceptable_consecutive_delay_ms_;
64+
// set optional to avoid sending the error diagnostics before node start processing
65+
std::optional<rclcpp::Time> last_normal_processing_timestamp_;
6166

6267
NonMaximumSuppression iou_bev_nms_;
6368
DetectionClassRemapper detection_class_remapper_;
6469

6570
std::unique_ptr<CenterPointTRT> detector_ptr_{nullptr};
6671
std::unique_ptr<autoware_utils::DiagnosticsInterface> diagnostics_interface_ptr_;
72+
std::unique_ptr<autoware_utils::DiagnosticsInterface> diagnostics_processing_delay_;
73+
rclcpp::TimerBase::SharedPtr diagnostics_processing_time_timer_;
6774

6875
// debugger
6976
std::unique_ptr<autoware_utils::StopWatch<std::chrono::milliseconds>> stop_watch_ptr_{nullptr};

perception/autoware_lidar_centerpoint/src/node.cpp

+50-15
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,15 @@ LidarCenterPointNode::LidarCenterPointNode(const rclcpp::NodeOptions & node_opti
109109
std::make_unique<CenterPointTRT>(encoder_param, head_param, densification_param, config);
110110
diagnostics_interface_ptr_ =
111111
std::make_unique<autoware_utils::DiagnosticsInterface>(this, "centerpoint_trt");
112+
diagnostics_processing_delay_ =
113+
std::make_unique<autoware_utils::DiagnosticsInterface>(this, "node_processing_time_status");
112114

113115
// diagnostics parameters
114-
max_allowed_processing_time_ = declare_parameter<float>("max_allowed_processing_time");
115-
max_consecutive_warn_count_ = declare_parameter<int>("max_consecutive_warn_count");
116+
max_allowed_processing_time_ = declare_parameter<double>("max_allowed_processing_time");
117+
max_acceptable_consecutive_delay_ms_ =
118+
declare_parameter<double>("max_acceptable_consecutive_delay_ms");
119+
const long validation_callback_interval_ms =
120+
declare_parameter<long>("validation_callback_interval_ms");
116121

117122
pointcloud_sub_ = this->create_subscription<sensor_msgs::msg::PointCloud2>(
118123
"~/input/pointcloud", rclcpp::SensorDataQoS{}.keep_last(1),
@@ -130,6 +135,12 @@ LidarCenterPointNode::LidarCenterPointNode(const rclcpp::NodeOptions & node_opti
130135
stop_watch_ptr_->tic("processing_time");
131136
}
132137

138+
if (stop_watch_ptr_) {
139+
diagnostics_processing_time_timer_ = this->create_wall_timer(
140+
std::chrono::milliseconds(validation_callback_interval_ms),
141+
std::bind(&LidarCenterPointNode::diagnosticsTimerCallback, this));
142+
}
143+
133144
if (this->declare_parameter("build_only", false)) {
134145
RCLCPP_INFO(this->get_logger(), "TensorRT engine is built and shutdown node.");
135146
rclcpp::shutdown();
@@ -194,24 +205,21 @@ void LidarCenterPointNode::pointCloudCallback(
194205
if (processing_time_ms > max_allowed_processing_time_) {
195206
diagnostics_interface_ptr_->add_key_value("is_processing_time_ms_in_expected_range", false);
196207

197-
consecutive_delay_count_++;
208+
std::stringstream message;
209+
message << "CenterPoint processing time exceeds the acceptable limit of "
210+
<< max_allowed_processing_time_ << " ms by "
211+
<< (processing_time_ms - max_allowed_processing_time_) << " ms.";
198212

199-
if (consecutive_delay_count_ <= max_consecutive_warn_count_) {
200-
std::stringstream message;
201-
message << "CenterPoint processing time exceeds the acceptable limit of "
202-
<< max_allowed_processing_time_ << " ms by "
203-
<< (processing_time_ms - max_allowed_processing_time_) << " ms.";
213+
diagnostics_interface_ptr_->update_level_and_message(
214+
diagnostic_msgs::msg::DiagnosticStatus::WARN, message.str());
204215

205-
diagnostics_interface_ptr_->update_level_and_message(
206-
diagnostic_msgs::msg::DiagnosticStatus::WARN, message.str());
207-
} else {
208-
diagnostics_interface_ptr_->update_level_and_message(
209-
diagnostic_msgs::msg::DiagnosticStatus::ERROR,
210-
"CenterPoint processing delay has exceeded the acceptable limit continuously.");
216+
// just in case the processing starts with a delayed inference
217+
if (!last_normal_processing_timestamp_) {
218+
last_normal_processing_timestamp_ = this->get_clock()->now();
211219
}
212220
} else {
213221
diagnostics_interface_ptr_->add_key_value("is_processing_time_ms_in_expected_range", true);
214-
consecutive_delay_count_ = 0;
222+
last_normal_processing_timestamp_ = this->get_clock()->now();
215223
}
216224

217225
// add processing time for debug
@@ -234,6 +242,33 @@ void LidarCenterPointNode::pointCloudCallback(
234242
diagnostics_interface_ptr_->publish(input_pointcloud_msg->header.stamp);
235243
}
236244

245+
// Check the timestamp of consecutively delayed processing
246+
// If the node is consistently delayed, publish an error diagnostic message
247+
void LidarCenterPointNode::diagnosticsTimerCallback() {
248+
// skip if the node has not performed inference yet
249+
if (last_normal_processing_timestamp_) {
250+
diagnostics_processing_delay_->clear();
251+
252+
const rclcpp::Time timestamp_now = this->get_clock()->now();
253+
const double delayed_state_duration =
254+
std::chrono::duration<double, std::milli>(
255+
std::chrono::nanoseconds(
256+
(timestamp_now - last_normal_processing_timestamp_.value()).nanoseconds()))
257+
.count();
258+
259+
if (delayed_state_duration > max_acceptable_consecutive_delay_ms_) {
260+
diagnostics_processing_delay_->add_key_value("is_processing_time_ms_in_expected_range", false);
261+
diagnostics_processing_delay_->update_level_and_message(
262+
diagnostic_msgs::msg::DiagnosticStatus::ERROR,
263+
"CenterPoint processing delay has exceeded the acceptable limit continuously.");
264+
} else {
265+
diagnostics_processing_delay_->add_key_value("is_processing_time_ms_in_expected_range", true);
266+
}
267+
268+
diagnostics_processing_delay_->publish(timestamp_now);
269+
}
270+
}
271+
237272
} // namespace autoware::lidar_centerpoint
238273

239274
#include <rclcpp_components/register_node_macro.hpp>

0 commit comments

Comments
 (0)