Apollo 10.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(ControlCommand *control_command);
88 void GetVehiclePitchAngle(ControlCommand *control_command);
89 void CheckAutoMode(const canbus::Chassis *chassis);
90 void PublishControlInteractiveMsg();
91
92 private:
93 apollo::cyber::Time init_time_;
94
95 localization::LocalizationEstimate latest_localization_;
96 canbus::Chassis latest_chassis_;
97 planning::ADCTrajectory latest_trajectory_;
98 external_command::CommandStatus planning_command_status_;
99 PadMessage pad_msg_;
100 common::Header latest_replan_trajectory_header_;
101
102 ControlTaskAgent control_task_agent_;
103
104 bool estop_ = false;
105 std::string estop_reason_;
106 bool pad_received_ = false;
107
108 unsigned int status_lost_ = 0;
109 unsigned int status_sanity_check_failed_ = 0;
110 unsigned int total_status_lost_ = 0;
111 unsigned int total_status_sanity_check_failed_ = 0;
112
113 ControlPipeline control_pipeline_;
114
115 std::mutex mutex_;
116
117 std::shared_ptr<cyber::Reader<apollo::canbus::Chassis>> chassis_reader_;
118 std::shared_ptr<cyber::Reader<PadMessage>> pad_msg_reader_;
119 std::shared_ptr<cyber::Reader<apollo::localization::LocalizationEstimate>>
120 localization_reader_;
121 std::shared_ptr<cyber::Reader<apollo::planning::ADCTrajectory>>
122 trajectory_reader_;
123 std::shared_ptr<cyber::Reader<apollo::external_command::CommandStatus>>
124 planning_command_status_reader_;
125
126 std::shared_ptr<cyber::Writer<ControlCommand>> control_cmd_writer_;
127 // when using control submodules
128 std::shared_ptr<cyber::Writer<LocalView>> local_view_writer_;
129
130 std::shared_ptr<cyber::Writer<ControlInteractiveMsg>>
131 control_interactive_writer_;
132
133 common::monitor::MonitorLogBuffer monitor_logger_buffer_;
134
135 LocalView local_view_;
136
137 std::shared_ptr<DependencyInjector> injector_;
138
139 double previous_steering_command_ = 0.0;
140
141 bool is_auto_ = false;
142 bool from_else_to_auto_ = false;
143};
144
146} // namespace control
147} // 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:656
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