Apollo 10.0
自动驾驶开放平台
monitor_manager.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 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 "gflags/gflags.h"
20
21#include "modules/common_msgs/chassis_msgs/chassis.pb.h"
22
23#include "cyber/common/file.h"
29
30namespace apollo {
31namespace monitor {
32
34
35MonitorManager::MonitorManager()
38
39void MonitorManager::Init(const std::shared_ptr<apollo::cyber::Node>& node) {
40 node_ = node;
41 if (FLAGS_use_sim_time) {
42 status_.set_is_realtime_in_simulation(true);
43 }
44}
45
46bool MonitorManager::StartFrame(const double current_time) {
47 status_.set_detect_immediately(false);
48 // Get latest HMIStatus.
49 static auto hmi_status_reader =
50 CreateReader<apollo::dreamview::HMIStatus>(FLAGS_hmi_status_topic);
51 hmi_status_reader->Observe();
52 const auto hmi_status = hmi_status_reader->GetLatestObserved();
53 if (hmi_status == nullptr) {
54 AERROR << "No HMIStatus was received.";
55 return false;
56 } else if (hmi_status->expected_modules() > 0) {
57 status_.set_detect_immediately(true);
58 }
59
60 if (current_mode_ != hmi_status->current_mode()) {
61 // Mode changed, update configs and monitored.
62 current_mode_ = hmi_status->current_mode();
64 hmi_config_.modes().at(current_mode_));
65 status_.clear_hmi_modules();
66 for (const auto& iter : mode_config_.modules()) {
67 status_.mutable_hmi_modules()->insert({iter.first, {}});
68 }
69 status_.clear_components();
70 for (const auto& iter : mode_config_.monitored_components()) {
71 status_.mutable_components()->insert({iter.first, {}});
72 }
73 status_.clear_other_components();
74 for (const auto& iter : mode_config_.other_components()) {
75 status_.mutable_other_components()->insert({iter.first, {}});
76 }
77 status_.clear_global_components();
78 for (const auto& iter : mode_config_.global_components()) {
79 status_.mutable_global_components()->insert({iter.first, {}});
80 }
81 } else {
82 // Mode not changed, clear component summary from the last frame.
83 for (auto& iter : *status_.mutable_components()) {
84 iter.second.clear_summary();
85 }
86 // clear global component summary from the last frame.
87 for (auto& iter : *status_.mutable_global_components()) {
88 iter.second.clear_summary();
89 }
90 }
91
92 in_autonomous_driving_ = CheckAutonomousDriving(current_time);
93 return true;
94}
95
97 // Print and publish all monitor logs.
98 log_buffer_.Publish();
99}
100
101bool MonitorManager::CheckAutonomousDriving(const double current_time) {
102 // It's in offline mode if use_sim_time is set.
103 if (FLAGS_use_sim_time) {
104 return false;
105 }
106
107 // Get current DrivingMode, which will affect how we monitor modules.
108 static auto chassis_reader = CreateReader<Chassis>(FLAGS_chassis_topic);
109 chassis_reader->Observe();
110 const auto chassis = chassis_reader->GetLatestObserved();
111 if (chassis == nullptr) {
112 return false;
113 }
114
115 // If SimControl is used, return false to ignore safety check.
116 if (chassis->header().module_name() == "SimControl") {
117 return false;
118 }
119
120 // Ignore old messages which are likely from playback.
121 const double msg_time = chassis->header().timestamp_sec();
122 if (msg_time + FLAGS_system_status_lifetime_seconds < current_time) {
123 return false;
124 }
125
126 return chassis->driving_mode() == Chassis::COMPLETE_AUTO_DRIVE;
127}
128
129} // namespace monitor
130} // namespace apollo
void Publish()
publish the monitor messages
static apollo::dreamview::HMIMode LoadMode(const std::string &mode_config_path)
Load HMIMode.
Definition hmi_util.cc:100
static apollo::dreamview::HMIConfig LoadConfig(const std::string config_path="")
Load HMIConfig.
Definition hmi_util.cc:75
bool StartFrame(const double current_time)
void Init(const std::shared_ptr< apollo::cyber::Node > &node)
#define AERROR
Definition log.h:44
Some map util functions.
class register implement
Definition arena_queue.h:37
map< string, string > modes
map< string, ProcessMonitorConfig > other_components
map< string, MonitoredComponent > monitored_components
map< string, Module > modules
map< string, MonitoredComponent > global_components