Skip to content

Commit df0e170

Browse files
isamu-takagishmpwk
authored andcommitted
fix(hazard_status_converter): check current operation mode (autowarefoundation#6733)
* fix: hazard status converter Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * fix: topic name and modes Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * fix check target mode Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * fix message type Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * Revert "fix check target mode" This reverts commit 8b190b7. --------- Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp>
1 parent 2b224ba commit df0e170

File tree

3 files changed

+69
-16
lines changed

3 files changed

+69
-16
lines changed

system/hazard_status_converter/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<buildtool_depend>ament_cmake_auto</buildtool_depend>
1111
<buildtool_depend>autoware_cmake</buildtool_depend>
1212

13+
<depend>autoware_adapi_v1_msgs</depend>
1314
<depend>autoware_auto_system_msgs</depend>
1415
<depend>diagnostic_msgs</depend>
1516
<depend>rclcpp</depend>

system/hazard_status_converter/src/converter.cpp

+57-16
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ enum class HazardLevel { NF, SF, LF, SPF };
3232
struct TempNode
3333
{
3434
const DiagnosticNode & node;
35-
bool is_auto_tree;
35+
bool is_root_tree;
3636
};
3737

38-
HazardLevel get_hazard_level(const TempNode & node, DiagnosticLevel auto_mode_level)
38+
HazardLevel get_hazard_level(const TempNode & node, DiagnosticLevel root_mode_level)
3939
{
4040
// Convert the level according to the table below.
4141
// The Level other than auto mode is considered OK.
@@ -49,7 +49,7 @@ HazardLevel get_hazard_level(const TempNode & node, DiagnosticLevel auto_mode_le
4949
// | STALE | SF | LF | SPF | SPF |
5050
// |-------|-------------------------------|
5151

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;
5353
const auto node_level = node.node.status.level;
5454

5555
if (node_level == DiagnosticStatus::OK) {
@@ -67,20 +67,21 @@ HazardLevel get_hazard_level(const TempNode & node, DiagnosticLevel auto_mode_le
6767
return HazardLevel::SPF;
6868
}
6969

70-
void set_auto_tree(std::vector<TempNode> & nodes, int index)
70+
void set_root_tree(std::vector<TempNode> & nodes, int index)
7171
{
7272
TempNode & node = nodes[index];
73-
if (node.is_auto_tree) {
73+
if (node.is_root_tree) {
7474
return;
7575
}
7676

77-
node.is_auto_tree = true;
77+
node.is_root_tree = true;
7878
for (const auto & link : node.node.links) {
79-
set_auto_tree(nodes, link.index);
79+
set_root_tree(nodes, link.index);
8080
}
8181
}
8282

83-
HazardStatusStamped convert_hazard_diagnostics(const DiagnosticGraph & graph)
83+
HazardStatusStamped convert_hazard_diagnostics(
84+
const DiagnosticGraph & graph, const std::string & root, bool ignore)
8485
{
8586
// Create temporary tree for conversion.
8687
std::vector<TempNode> nodes;
@@ -90,19 +91,21 @@ HazardStatusStamped convert_hazard_diagnostics(const DiagnosticGraph & graph)
9091
}
9192

9293
// 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+
}
99102
}
100103
}
101104

102105
// Calculate hazard level from node level and root level.
103106
HazardStatusStamped hazard;
104107
for (const auto & node : nodes) {
105-
switch (get_hazard_level(node, auto_mode_level)) {
108+
switch (get_hazard_level(node, root_mode_level)) {
106109
case HazardLevel::NF:
107110
hazard.status.diag_no_fault.push_back(node.node.status);
108111
break;
@@ -131,6 +134,22 @@ Converter::Converter(const rclcpp::NodeOptions & options) : Node("converter", op
131134
sub_graph_ = create_subscription<DiagnosticGraph>(
132135
"~/diagnostics_graph", rclcpp::QoS(3),
133136
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;
134153
}
135154

136155
void Converter::on_graph(const DiagnosticGraph::ConstSharedPtr msg)
@@ -148,7 +167,29 @@ void Converter::on_graph(const DiagnosticGraph::ConstSharedPtr msg)
148167
return HazardStatus::NO_FAULT;
149168
};
150169

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());
152193
hazard.stamp = msg->stamp;
153194
hazard.status.level = get_system_level(hazard.status);
154195
hazard.status.emergency = hazard.status.level == HazardStatus::SINGLE_POINT_FAULT;

system/hazard_status_converter/src/converter.hpp

+11
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#include <rclcpp/rclcpp.hpp>
1919

20+
#include <autoware_adapi_v1_msgs/msg/operation_mode_state.hpp>
21+
#include <autoware_auto_system_msgs/msg/autoware_state.hpp>
2022
#include <autoware_auto_system_msgs/msg/hazard_status_stamped.hpp>
2123
#include <tier4_system_msgs/msg/diagnostic_graph.hpp>
2224

@@ -33,11 +35,20 @@ class Converter : public rclcpp::Node
3335
explicit Converter(const rclcpp::NodeOptions & options);
3436

3537
private:
38+
using AutowareState = autoware_auto_system_msgs::msg::AutowareState;
39+
using OperationMode = autoware_adapi_v1_msgs::msg::OperationModeState;
3640
using DiagnosticGraph = tier4_system_msgs::msg::DiagnosticGraph;
3741
using HazardStatusStamped = autoware_auto_system_msgs::msg::HazardStatusStamped;
42+
rclcpp::Subscription<AutowareState>::SharedPtr sub_state_;
43+
rclcpp::Subscription<OperationMode>::SharedPtr sub_mode_;
3844
rclcpp::Subscription<DiagnosticGraph>::SharedPtr sub_graph_;
3945
rclcpp::Publisher<HazardStatusStamped>::SharedPtr pub_hazard_;
46+
void on_state(const AutowareState::ConstSharedPtr msg);
47+
void on_mode(const OperationMode::ConstSharedPtr msg);
4048
void on_graph(const DiagnosticGraph::ConstSharedPtr msg);
49+
50+
AutowareState::ConstSharedPtr state_;
51+
OperationMode::ConstSharedPtr mode_;
4152
};
4253

4354
} // namespace hazard_status_converter

0 commit comments

Comments
 (0)