14
14
15
15
#include " converter.hpp"
16
16
17
+ #include < string>
17
18
#include < utility>
18
19
#include < vector>
19
20
20
21
namespace hazard_status_converter
21
22
{
22
23
23
- Converter::Converter (const rclcpp::NodeOptions & options) : Node(" converter" , options)
24
+ Converter::Converter (const rclcpp::NodeOptions & options)
25
+ : Node(" converter" , options), mode_interface_(*this )
24
26
{
25
27
using std::placeholders::_1;
26
28
pub_hazard_ = create_publisher<HazardStatusStamped>(" ~/hazard_status" , rclcpp::QoS (1 ));
@@ -31,9 +33,9 @@ Converter::Converter(const rclcpp::NodeOptions & options) : Node("converter", op
31
33
32
34
void Converter::on_create (DiagGraph::ConstSharedPtr graph)
33
35
{
34
- const auto find_auto_mode_root = [](const DiagGraph & graph) {
36
+ const auto find_auto_mode_root = [](const DiagGraph & graph, const std::string & root_name ) {
35
37
for (const auto & unit : graph.units ()) {
36
- if (unit->path () == " /autoware/modes/autonomous " ) return unit;
38
+ if (unit->path () == root_name ) return unit;
37
39
}
38
40
return static_cast <DiagUnit *>(nullptr );
39
41
};
@@ -53,8 +55,17 @@ void Converter::on_create(DiagGraph::ConstSharedPtr graph)
53
55
return result;
54
56
};
55
57
56
- auto_mode_root_ = find_auto_mode_root (*graph);
57
- auto_mode_tree_ = make_auto_mode_tree (auto_mode_root_);
58
+ std::vector<std::pair<RootModeStatus::Mode, std::string>> root_modes = {
59
+ {RootModeStatus::Mode::AUTO, " /autoware/modes/autonomous" },
60
+ {RootModeStatus::Mode::REMOTE, " /autoware/modes/remote" },
61
+ {RootModeStatus::Mode::LOCAL, " /autoware/modes/local" },
62
+ };
63
+ for (const auto & [mode, root_name] : root_modes) {
64
+ ModeSubgraph subgraph;
65
+ subgraph.root = find_auto_mode_root (*graph, root_name);
66
+ subgraph.nodes = make_auto_mode_tree (subgraph.root );
67
+ mode_subgraphs_[mode] = subgraph;
68
+ }
58
69
}
59
70
60
71
void Converter::on_update (DiagGraph::ConstSharedPtr graph)
@@ -98,17 +109,24 @@ void Converter::on_update(DiagGraph::ConstSharedPtr graph)
98
109
return static_cast <std::vector<DiagnosticStatus> *>(nullptr );
99
110
};
100
111
101
- if (!auto_mode_root_) {
102
- RCLCPP_ERROR_STREAM_THROTTLE (get_logger (), *get_clock (), 10000 , " No auto mode unit." );
112
+ // Get subgraph related to the current operation mode.
113
+ const auto root = mode_interface_.get_root ();
114
+ if (root.mode == RootModeStatus::Mode::UNKNOWN) {
115
+ RCLCPP_ERROR_STREAM_THROTTLE (get_logger (), *get_clock (), 10000 , " Unknown root mode." );
116
+ return ;
117
+ }
118
+ const auto & subgraph = mode_subgraphs_.at (root.mode );
119
+ if (!subgraph.root ) {
120
+ RCLCPP_ERROR_STREAM_THROTTLE (get_logger (), *get_clock (), 10000 , " No current mode root." );
103
121
return ;
104
122
}
105
123
106
124
// Calculate hazard level from unit level and root level.
107
125
HazardStatusStamped hazard;
108
126
for (const auto & unit : graph->units ()) {
109
127
if (unit->path ().empty ()) continue ;
110
- const bool is_auto_tree = auto_mode_tree_ .count (unit);
111
- const auto root_level = is_auto_tree ? auto_mode_root_ ->level () : DiagnosticStatus::OK ;
128
+ const bool is_ignored = root. ignore || !subgraph. nodes .count (unit);
129
+ const auto root_level = is_ignored ? DiagnosticStatus::OK : subgraph. root ->level ();
112
130
const auto unit_level = unit->level ();
113
131
if (auto diags = get_hazards_vector (hazard.status , get_hazard_level (unit_level, root_level))) {
114
132
diags->push_back (unit->create_diagnostic_status ());
0 commit comments