@@ -32,10 +32,10 @@ enum class HazardLevel { NF, SF, LF, SPF };
32
32
struct TempNode
33
33
{
34
34
const DiagnosticNode & node;
35
- bool is_auto_tree ;
35
+ bool is_root_tree ;
36
36
};
37
37
38
- HazardLevel get_hazard_level (const TempNode & node, DiagnosticLevel auto_mode_level )
38
+ HazardLevel get_hazard_level (const TempNode & node, DiagnosticLevel root_mode_level )
39
39
{
40
40
// Convert the level according to the table below.
41
41
// The Level other than auto mode is considered OK.
@@ -49,7 +49,7 @@ HazardLevel get_hazard_level(const TempNode & node, DiagnosticLevel auto_mode_le
49
49
// | STALE | SF | LF | SPF | SPF |
50
50
// |-------|-------------------------------|
51
51
52
- const auto root_level = node.is_auto_tree ? auto_mode_level : DiagnosticStatus::OK;
52
+ const auto root_level = node.is_root_tree ? root_mode_level : DiagnosticStatus::OK;
53
53
const auto node_level = node.node .status .level ;
54
54
55
55
if (node_level == DiagnosticStatus::OK) {
@@ -67,20 +67,21 @@ HazardLevel get_hazard_level(const TempNode & node, DiagnosticLevel auto_mode_le
67
67
return HazardLevel::SPF;
68
68
}
69
69
70
- void set_auto_tree (std::vector<TempNode> & nodes, int index)
70
+ void set_root_tree (std::vector<TempNode> & nodes, int index)
71
71
{
72
72
TempNode & node = nodes[index ];
73
- if (node.is_auto_tree ) {
73
+ if (node.is_root_tree ) {
74
74
return ;
75
75
}
76
76
77
- node.is_auto_tree = true ;
77
+ node.is_root_tree = true ;
78
78
for (const auto & link : node.node .links ) {
79
- set_auto_tree (nodes, link .index );
79
+ set_root_tree (nodes, link .index );
80
80
}
81
81
}
82
82
83
- HazardStatusStamped convert_hazard_diagnostics (const DiagnosticGraph & graph)
83
+ HazardStatusStamped convert_hazard_diagnostics (
84
+ const DiagnosticGraph & graph, const std::string & root, bool ignore)
84
85
{
85
86
// Create temporary tree for conversion.
86
87
std::vector<TempNode> nodes;
@@ -90,19 +91,21 @@ HazardStatusStamped convert_hazard_diagnostics(const DiagnosticGraph & graph)
90
91
}
91
92
92
93
// Mark nodes included in the auto mode tree.
93
- DiagnosticLevel auto_mode_level = DiagnosticStatus::STALE;
94
- for (size_t index = 0 ; index < nodes.size (); ++index ) {
95
- const auto & status = nodes[index ].node .status ;
96
- if (status.name == " /autoware/modes/autonomous" ) {
97
- set_auto_tree (nodes, index );
98
- auto_mode_level = status.level ;
94
+ DiagnosticLevel root_mode_level = DiagnosticStatus::STALE;
95
+ if (!root.empty () && !ignore) {
96
+ for (size_t index = 0 ; index < nodes.size (); ++index ) {
97
+ const auto & status = nodes[index ].node .status ;
98
+ if (status.name == root) {
99
+ set_root_tree (nodes, index );
100
+ root_mode_level = status.level ;
101
+ }
99
102
}
100
103
}
101
104
102
105
// Calculate hazard level from node level and root level.
103
106
HazardStatusStamped hazard;
104
107
for (const auto & node : nodes) {
105
- switch (get_hazard_level (node, auto_mode_level )) {
108
+ switch (get_hazard_level (node, root_mode_level )) {
106
109
case HazardLevel::NF:
107
110
hazard.status .diag_no_fault .push_back (node.node .status );
108
111
break ;
@@ -131,6 +134,22 @@ Converter::Converter(const rclcpp::NodeOptions & options) : Node("converter", op
131
134
sub_graph_ = create_subscription<DiagnosticGraph>(
132
135
" ~/diagnostics_graph" , rclcpp::QoS (3 ),
133
136
std::bind (&Converter::on_graph, this , std::placeholders::_1));
137
+ sub_state_ = create_subscription<AutowareState>(
138
+ " /autoware/state" , rclcpp::QoS (1 ),
139
+ std::bind (&Converter::on_state, this , std::placeholders::_1));
140
+ sub_mode_ = create_subscription<OperationMode>(
141
+ " /system/operation_mode/state" , rclcpp::QoS (1 ).transient_local (),
142
+ std::bind (&Converter::on_mode, this , std::placeholders::_1));
143
+ }
144
+
145
+ void Converter::on_state (const AutowareState::ConstSharedPtr msg)
146
+ {
147
+ state_ = msg;
148
+ }
149
+
150
+ void Converter::on_mode (const OperationMode::ConstSharedPtr msg)
151
+ {
152
+ mode_ = msg;
134
153
}
135
154
136
155
void Converter::on_graph (const DiagnosticGraph::ConstSharedPtr msg)
@@ -148,7 +167,29 @@ void Converter::on_graph(const DiagnosticGraph::ConstSharedPtr msg)
148
167
return HazardStatus::NO_FAULT;
149
168
};
150
169
151
- HazardStatusStamped hazard = convert_hazard_diagnostics (*msg);
170
+ const auto is_ignore = [this ]() {
171
+ if (mode_ && state_) {
172
+ if (mode_->mode == OperationMode::AUTONOMOUS || mode_->mode == OperationMode::STOP) {
173
+ if (state_->state == AutowareState::WAITING_FOR_ROUTE) return true ;
174
+ if (state_->state == AutowareState::PLANNING) return true ;
175
+ }
176
+ if (state_->state == AutowareState::INITIALIZING) return true ;
177
+ if (state_->state == AutowareState::FINALIZING) return true ;
178
+ }
179
+ return false ;
180
+ };
181
+
182
+ const auto get_root = [this ]() {
183
+ if (mode_) {
184
+ if (mode_->mode == OperationMode::STOP) return " /autoware/modes/stop" ;
185
+ if (mode_->mode == OperationMode::AUTONOMOUS) return " /autoware/modes/autonomous" ;
186
+ if (mode_->mode == OperationMode::LOCAL) return " /autoware/modes/local" ;
187
+ if (mode_->mode == OperationMode::REMOTE) return " /autoware/modes/remote" ;
188
+ }
189
+ return " " ;
190
+ };
191
+
192
+ HazardStatusStamped hazard = convert_hazard_diagnostics (*msg, get_root (), is_ignore ());
152
193
hazard.stamp = msg->stamp ;
153
194
hazard.status .level = get_system_level (hazard.status );
154
195
hazard.status .emergency = hazard.status .level == HazardStatus::SINGLE_POINT_FAULT;
0 commit comments