Apollo  6.0
Open source self driving car software
control_component.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 
24 #include "cyber/time/time.h"
25 
26 #include "modules/canbus/proto/chassis.pb.h"
28 #include "modules/control/proto/control_cmd.pb.h"
29 #include "modules/control/proto/control_conf.pb.h"
30 #include "modules/control/proto/pad_msg.pb.h"
31 #include "modules/localization/proto/localization.pb.h"
32 #include "modules/planning/proto/planning.pb.h"
33 
37 #include "modules/control/proto/preprocessor.pb.h"
39 
44 namespace apollo {
45 namespace control {
46 
54  friend class ControlTestBase;
55 
56  public:
58  bool Init() override;
59 
60  bool Proc() override;
61 
62  private:
63  // Upon receiving pad message
64  void OnPad(const std::shared_ptr<PadMessage> &pad);
65 
66  void OnChassis(const std::shared_ptr<apollo::canbus::Chassis> &chassis);
67 
68  void OnPlanning(
69  const std::shared_ptr<apollo::planning::ADCTrajectory> &trajectory);
70 
71  void OnLocalization(
72  const std::shared_ptr<apollo::localization::LocalizationEstimate>
73  &localization);
74 
75  // Upon receiving monitor message
76  void OnMonitor(
77  const apollo::common::monitor::MonitorMessage &monitor_message);
78 
79  common::Status ProduceControlCommand(ControlCommand *control_command);
80  common::Status CheckInput(LocalView *local_view);
81  common::Status CheckTimestamp(const LocalView &local_view);
82  common::Status CheckPad();
83 
84  private:
85  apollo::cyber::Time init_time_;
86 
87  localization::LocalizationEstimate latest_localization_;
88  canbus::Chassis latest_chassis_;
89  planning::ADCTrajectory latest_trajectory_;
90  PadMessage pad_msg_;
91  common::Header latest_replan_trajectory_header_;
92 
93  ControllerAgent controller_agent_;
94 
95  bool estop_ = false;
96  std::string estop_reason_;
97  bool pad_received_ = false;
98 
99  unsigned int status_lost_ = 0;
100  unsigned int status_sanity_check_failed_ = 0;
101  unsigned int total_status_lost_ = 0;
102  unsigned int total_status_sanity_check_failed_ = 0;
103 
104  ControlConf control_conf_;
105 
106  std::mutex mutex_;
107 
108  std::shared_ptr<cyber::Reader<apollo::canbus::Chassis>> chassis_reader_;
109  std::shared_ptr<cyber::Reader<PadMessage>> pad_msg_reader_;
110  std::shared_ptr<cyber::Reader<apollo::localization::LocalizationEstimate>>
111  localization_reader_;
112  std::shared_ptr<cyber::Reader<apollo::planning::ADCTrajectory>>
113  trajectory_reader_;
114 
115  std::shared_ptr<cyber::Writer<ControlCommand>> control_cmd_writer_;
116  // when using control submodules
117  std::shared_ptr<cyber::Writer<LocalView>> local_view_writer_;
118 
119  common::monitor::MonitorLogBuffer monitor_logger_buffer_;
120 
121  LocalView local_view_;
122 
123  std::shared_ptr<DependencyInjector> injector_;
124 };
125 
127 } // namespace control
128 } // namespace apollo
TimerComponent is a timer component. Your component can inherit from Component, and implement Init() ...
Definition: timer_component.h:35
Defines the ControllerAgent class.
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
bool Proc() override
The Proc logic of the component, which called by the CyberRT frame.
LocalView contains all necessary data as planning input.
CYBER_REGISTER_COMPONENT(PreprocessorSubmodule)
Definition: control_component.h:53
Definition: control_test_base.h:48
manage all controllers declared in control config file.
Definition: controller_agent.h:46
The class of MonitorLogBuffer.
A general class to denote the return status of an API call. It can either be an OK status for success...
Definition: status.h:43
This class help collect MonitorMessage pb to monitor topic. The messages can be published automatical...
Definition: monitor_log_buffer.h:60
Some util functions.
Cyber has builtin time type Time.
Definition: time.h:31