Apollo  6.0
Open source self driving car software
monitor_manager.h
Go to the documentation of this file.
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 
17 #pragma once
18 
19 #include <memory>
20 #include <string>
21 #include <unordered_map>
22 
23 #include "cyber/common/macros.h"
25 #include "modules/dreamview/proto/hmi_config.pb.h"
26 #include "modules/dreamview/proto/hmi_mode.pb.h"
27 #include "modules/dreamview/proto/hmi_status.pb.h"
28 #include "modules/monitor/proto/system_status.pb.h"
29 
34 namespace apollo {
35 namespace monitor {
36 
37 // Centralized monitor config and status manager.
39  public:
40  void Init(const std::shared_ptr<apollo::cyber::Node>& node);
41 
42  // Start and end a monitoring frame.
43  bool StartFrame(const double current_time);
44  void EndFrame();
45 
46  // Getters.
47  const apollo::dreamview::HMIMode& GetHMIMode() const { return mode_config_; }
48  bool IsInAutonomousMode() const { return in_autonomous_driving_; }
49  SystemStatus* GetStatus() { return &status_; }
51 
52  // Cyber reader / writer creator.
53  template <class T>
54  std::shared_ptr<cyber::Reader<T>> CreateReader(const std::string& channel) {
55  if (readers_.find(channel) == readers_.end()) {
56  readers_.emplace(channel, node_->CreateReader<T>(channel));
57  }
58  return std::dynamic_pointer_cast<cyber::Reader<T>>(readers_[channel]);
59  }
60 
61  template <class T>
62  std::shared_ptr<cyber::Writer<T>> CreateWriter(const std::string& channel) {
63  return node_->CreateWriter<T>(channel);
64  }
65 
66  private:
67  SystemStatus status_;
68 
69  // Input statuses.
70  std::string current_mode_;
71  const apollo::dreamview::HMIConfig hmi_config_;
72  apollo::dreamview::HMIMode mode_config_;
73  bool in_autonomous_driving_ = false;
74  bool CheckAutonomousDriving(const double current_time);
75 
77  std::shared_ptr<apollo::cyber::Node> node_;
78  std::unordered_map<std::string, std::shared_ptr<cyber::ReaderBase>> readers_;
79 
81 };
82 
83 } // namespace monitor
84 } // namespace apollo
bool IsInAutonomousMode() const
Definition: monitor_manager.h:48
apollo::common::monitor::MonitorLogBuffer & LogBuffer()
Definition: monitor_manager.h:50
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: monitor_manager.h:38
Reader subscribes a channel, it has two main functions:
Definition: reader.h:68
void Init(const std::shared_ptr< apollo::cyber::Node > &node)
const apollo::dreamview::HMIMode & GetHMIMode() const
Definition: monitor_manager.h:47
bool StartFrame(const double current_time)
#define DECLARE_SINGLETON(classname)
Definition: macros.h:52
The class of MonitorLogBuffer.
std::shared_ptr< cyber::Writer< T > > CreateWriter(const std::string &channel)
Definition: monitor_manager.h:62
std::shared_ptr< cyber::Reader< T > > CreateReader(const std::string &channel)
Definition: monitor_manager.h:54
SystemStatus * GetStatus()
Definition: monitor_manager.h:49
This class help collect MonitorMessage pb to monitor topic. The messages can be published automatical...
Definition: monitor_log_buffer.h:60