@@ -112,7 +112,11 @@ LidarCenterPointNode::LidarCenterPointNode(const rclcpp::NodeOptions & node_opti
112
112
113
113
// diagnostics parameters
114
114
max_allowed_processing_time_ = declare_parameter<float >(" max_allowed_processing_time" );
115
- max_consecutive_warn_count_ = declare_parameter<int >(" max_consecutive_warn_count" );
115
+ max_acceptable_consecutive_delay_ms_ = declare_parameter<int >(" max_acceptable_consecutive_delay_ms" );
116
+
117
+ diagnostics_timer_ = this ->create_wall_timer (
118
+ std::chrono::milliseconds (100 ),
119
+ std::bind (&LidarCenterPointNode::diagnosticTimerCallback, this ));
116
120
117
121
pointcloud_sub_ = this ->create_subscription <sensor_msgs::msg::PointCloud2>(
118
122
" ~/input/pointcloud" , rclcpp::SensorDataQoS{}.keep_last (1 ),
@@ -194,24 +198,21 @@ void LidarCenterPointNode::pointCloudCallback(
194
198
if (processing_time_ms > max_allowed_processing_time_) {
195
199
diagnostics_interface_ptr_->add_key_value (" is_processing_time_ms_in_expected_range" , false );
196
200
197
- consecutive_delay_count_++;
201
+ if (!is_processing_delayed_) {
202
+ started_delayed_timestamp_ = this ->get_clock ()->now ();
203
+ is_processing_delayed_ = true ;
204
+ }
198
205
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." ;
206
+ std::stringstream message;
207
+ message << " CenterPoint processing time exceeds the acceptable limit of "
208
+ << max_allowed_processing_time_ << " ms by "
209
+ << (processing_time_ms - max_allowed_processing_time_) << " ms." ;
204
210
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." );
211
- }
211
+ diagnostics_interface_ptr_->update_level_and_message (
212
+ diagnostic_msgs::msg::DiagnosticStatus::WARN, message.str ());
212
213
} else {
213
214
diagnostics_interface_ptr_->add_key_value (" is_processing_time_ms_in_expected_range" , true );
214
- consecutive_delay_count_ = 0 ;
215
+ is_processing_delayed_ = false ;
215
216
}
216
217
217
218
// add processing time for debug
@@ -234,6 +235,25 @@ void LidarCenterPointNode::pointCloudCallback(
234
235
diagnostics_interface_ptr_->publish (input_pointcloud_msg->header .stamp );
235
236
}
236
237
238
+ // Check the timestamp of the processing that has started consecutively delaying,
239
+ // and if the node is delayed constantly, publish the error diagnostic message
240
+ void LidarCenterPointNode::diagnosticTimerCallback () {
241
+ const double delayed_state_duration =
242
+ std::chrono::duration<double , std::milli>(
243
+ std::chrono::nanoseconds (
244
+ (this ->get_clock ()->now () - started_delayed_timestamp_).nanoseconds ()))
245
+ .count ();
246
+
247
+ if (delayed_state_duration > max_acceptable_consecutive_delay_ms_) {
248
+ diagnostics_interface_ptr_->add_key_value (" is_processing_time_ms_in_expected_range" , false );
249
+ diagnostics_interface_ptr_->update_level_and_message (
250
+ diagnostic_msgs::msg::DiagnosticStatus::ERROR,
251
+ " CenterPoint processing delay has exceeded the acceptable limit continuously." );
252
+
253
+ diagnostics_interface_ptr_->publish (input_pointcloud_msg->header .stamp );
254
+ }
255
+ }
256
+
237
257
} // namespace autoware::lidar_centerpoint
238
258
239
259
#include < rclcpp_components/register_node_macro.hpp>
0 commit comments