Apollo 11.0
自动驾驶开放平台
control_component.h
浏览该文件的文档.
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
22#include "modules/common_msgs/chassis_msgs/chassis.pb.h"
23#include "modules/common_msgs/control_msgs/control_cmd.pb.h"
24#include "modules/common_msgs/control_msgs/control_interactive_msg.pb.h"
25#include "modules/common_msgs/control_msgs/pad_msg.pb.h"
26#include "modules/common_msgs/external_command_msgs/command_status.pb.h"
27#include "modules/common_msgs/localization_msgs/localization.pb.h"
28#include "modules/common_msgs/planning_msgs/planning.pb.h"
29#include "modules/control/control_component/proto/preprocessor.pb.h"
30
33#include "cyber/time/time.h"
39
44namespace apollo {
45namespace 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 OnPlanningCommandStatus(
72 const std::shared_ptr<external_command::CommandStatus>
73 &planning_command_status);
74
75 void OnLocalization(
76 const std::shared_ptr<apollo::localization::LocalizationEstimate>
77 &localization);
78
79 // Upon receiving monitor message
80 void OnMonitor(
81 const apollo::common::monitor::MonitorMessage &monitor_message);
82
83 common::Status ProduceControlCommand(ControlCommand *control_command);
85 common::Status CheckTimestamp(const LocalView &local_view);
86 common::Status CheckPad();
87 void ResetAndProduceZeroControlCommand(const canbus::Chassis *chassis,
88 ControlCommand *control_command);
89 void GetVehiclePitchAngle(ControlCommand *control_command);
90 void CheckAutoMode(const canbus::Chassis *chassis);
91 void PublishControlInteractiveMsg();
92
93 private:
94 apollo::cyber::Time init_time_;
95
96 localization::LocalizationEstimate latest_localization_;
97 canbus::Chassis latest_chassis_;
98 planning::ADCTrajectory latest_trajectory_;
99 external_command::CommandStatus planning_command_status_;
100 PadMessage pad_msg_;
101 common::Header latest_replan_trajectory_header_;
102
103 ControlTaskAgent control_task_agent_;
104
105 bool estop_ = false;
106 std::string estop_reason_;
107 bool pad_received_ = false;
108
109 unsigned int status_lost_ = 0;
110 unsigned int status_sanity_check_failed_ = 0;
111 unsigned int total_status_lost_ = 0;
112 unsigned int total_status_sanity_check_failed_ = 0;
113
114 ControlPipeline control_pipeline_;
115
116 std::mutex mutex_;
117
118 std::shared_ptr<cyber::Reader<apollo::canbus::Chassis>> chassis_reader_;
119 std::shared_ptr<cyber::Reader<PadMessage>> pad_msg_reader_;
120 std::shared_ptr<cyber::Reader<apollo::localization::LocalizationEstimate>>
121 localization_reader_;
122 std::shared_ptr<cyber::Reader<apollo::planning::ADCTrajectory>>
123 trajectory_reader_;
124 std::shared_ptr<cyber::Reader<apollo::external_command::CommandStatus>>
125 planning_command_status_reader_;
126
127 std::shared_ptr<cyber::Writer<ControlCommand>> control_cmd_writer_;
128 // when using control submodules
129 std::shared_ptr<cyber::Writer<LocalView>> local_view_writer_;
130
131 std::shared_ptr<cyber::Writer<ControlInteractiveMsg>>
132 control_interactive_writer_;
133
134 common::monitor::MonitorLogBuffer monitor_logger_buffer_;
135
136 LocalView local_view_;
137
138 std::shared_ptr<DependencyInjector> injector_;
139
140 double previous_steering_command_ = 0.0;
141
142 bool is_auto_ = false;
143 bool from_else_to_auto_ = false;
144
145 uint16_t localization_timeout_count_ = 0;
146 uint16_t trajectory_timeout_count_ = 0;
147 uint16_t chassis_timeout_count_ = 0;
148};
149
151} // namespace control
152} // namespace apollo
A general class to denote the return status of an API call.
Definition status.h:43
bool Proc() override
The Proc logic of the component, which called by the CyberRT frame.
manage all controllers declared in control config file.
Cyber has builtin time type Time.
Definition time.h:31
#define CYBER_REGISTER_COMPONENT(name)
Definition component.h:657
Defines the ControlTaskAgent class.
Some util functions.
The class of MonitorLogBuffer
class register implement
Definition arena_queue.h:37
LocalView contains all necessary data as planning input