@@ -38,49 +38,40 @@ controlEvaluatorNode::controlEvaluatorNode(const rclcpp::NodeOptions & node_opti
38
38
metrics_pub_ = create_publisher<DiagnosticArray>(" ~/metrics" , 1 );
39
39
}
40
40
41
- DiagnosticStatus controlEvaluatorNode::generateDiagnosticStatus () const
41
+ DiagnosticStatus controlEvaluatorNode::generateDiagnosticStatus (const bool is_emergency_brake ) const
42
42
{
43
43
DiagnosticStatus status;
44
44
status.level = status.OK ;
45
- status.name = " AEB " ;
45
+ status.name = " autonomous_emergency_braking " ;
46
46
diagnostic_msgs::msg::KeyValue key_value;
47
- key_value.key = " min" ;
48
- key_value.value = boost::lexical_cast<decltype (key_value.value )>(0.0 );
49
- status.values .push_back (key_value);
50
- key_value.key = " max" ;
51
- key_value.value = boost::lexical_cast<decltype (key_value.value )>(0.5 );
52
- status.values .push_back (key_value);
53
- key_value.key = " mean" ;
54
- key_value.value = boost::lexical_cast<decltype (key_value.value )>(1.0 );
47
+ key_value.key = " decision" ;
48
+ key_value.value = (is_emergency_brake) ? " stop" : " none" ;
55
49
status.values .push_back (key_value);
56
50
return status;
57
51
}
58
52
59
53
void controlEvaluatorNode::onDiagnostics (
60
54
[[maybe_unused]] const DiagnosticArray::ConstSharedPtr diag_msg)
61
-
62
55
{
63
56
const auto start = now ();
64
-
65
- const bool aeb_activated =
66
- std::any_of (diag_msg-> status . begin (), diag_msg-> status . end (), []( const auto & status) {
67
- return status. name . find ( " autonomous_emergency_braking " ) != std::string::npos ;
57
+ const auto aeb_status =
58
+ std::find_if (diag_msg-> status . begin (), diag_msg-> status . end (), []( const auto & status) {
59
+ const bool aeb_found = status. name . find ( " autonomous_emergency_braking " ) != std::string::npos;
60
+ return aeb_found ;
68
61
});
69
62
70
- if (!aeb_activated) {
71
- return ;
72
- }
63
+ if (aeb_status == diag_msg-> status . end ()) return ;
64
+
65
+ const bool is_emergency_brake = (aeb_status-> level == DiagnosticStatus::ERROR);
73
66
DiagnosticArray metrics_msg;
74
67
metrics_msg.header .stamp = now ();
75
-
76
- metrics_msg.status .push_back (generateDiagnosticStatus ());
68
+ metrics_msg.status .emplace_back (generateDiagnosticStatus (is_emergency_brake));
77
69
78
70
if (!metrics_msg.status .empty ()) {
79
71
metrics_pub_->publish (metrics_msg);
80
72
}
81
73
const auto runtime = (now () - start).seconds ();
82
74
RCLCPP_DEBUG (get_logger (), " control evaluation calculation time: %2.2f ms" , runtime * 1e3 );
83
- std::cerr << " control evaluation calculation time: " << runtime << " \n " ;
84
75
}
85
76
86
77
} // namespace control_diagnostics
0 commit comments