Apollo 11.0
自动驾驶开放平台
localization_monitor.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
18
19#include "cyber/common/log.h"
22#include "modules/common_msgs/localization_msgs/localization.pb.h"
25
26DEFINE_string(localization_monitor_name, "LocalizationMonitor",
27 "Name of the localization monitor.");
28
29DEFINE_double(localization_monitor_interval, 5,
30 "Localization status checking interval (s).");
31
32DEFINE_string(localization_component_name, "Localization",
33 "Localization component name.");
34
35namespace apollo {
36namespace monitor {
39
41 : RecurrentRunner(FLAGS_localization_monitor_name,
42 FLAGS_localization_monitor_interval) {}
43
44void LocalizationMonitor::RunOnce(const double current_time) {
45 auto manager = MonitorManager::Instance();
46 auto* component = apollo::common::util::FindOrNull(
47 *manager->GetStatus()->mutable_components(),
48 FLAGS_localization_component_name);
49 if (component == nullptr) {
50 // localization is not monitored in current mode, skip.
51 return;
52 }
53
54 static auto reader =
55 manager->CreateReader<LocalizationStatus>(FLAGS_localization_msf_status);
56 reader->Observe();
57 const auto status = reader->GetLatestObserved();
58
59 ComponentStatus* component_status = component->mutable_other_status();
60 component_status->clear_status();
61 if (status == nullptr) {
62 SummaryMonitor::EscalateStatus(ComponentStatus::ERROR,
63 "No LocalizationStatus received",
64 component_status);
65 return;
66 }
67
68 // Translate LocalizationStatus to ComponentStatus. Note that ERROR and FATAL
69 // will trigger safety mode in current settings.
70 switch (status->fusion_status()) {
71 case MeasureState::OK:
72 SummaryMonitor::EscalateStatus(ComponentStatus::OK, "", component_status);
73 break;
74 case MeasureState::WARNNING:
76 ComponentStatus::WARN,
77 absl::StrCat("WARNNING: ", status->state_message()),
78 component_status);
79 break;
80 case MeasureState::ERROR:
82 ComponentStatus::WARN,
83 absl::StrCat("ERROR: ", status->state_message()), component_status);
84 break;
85 case MeasureState::CRITICAL_ERROR:
87 ComponentStatus::ERROR,
88 absl::StrCat("CRITICAL_ERROR: ", status->state_message()),
89 component_status);
90 break;
91 case MeasureState::FATAL_ERROR:
93 ComponentStatus::FATAL,
94 absl::StrCat("FATAL_ERROR: ", status->state_message()),
95 component_status);
96 break;
97 default:
98 AFATAL << "Unknown fusion_status: " << status->fusion_status();
99 break;
100 }
101}
102
103} // namespace monitor
104} // namespace apollo
void RunOnce(const double current_time) override
static void EscalateStatus(const ComponentStatus::Status new_status, const std::string &message, ComponentStatus *current_status)
DEFINE_string(localization_monitor_name, "LocalizationMonitor", "Name of the localization monitor.")
DEFINE_double(localization_monitor_interval, 5, "Localization status checking interval (s).")
#define AFATAL
Definition log.h:45
Some map util functions.
class register implement
Definition arena_queue.h:37