Apollo 11.0
自动驾驶开放平台
lat_controller.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
22#pragma once
23
24#include <fstream>
25#include <memory>
26#include <string>
27
28#include "Eigen/Core"
29
30#include "modules/common_msgs/config_msgs/vehicle_config.pb.h"
31#include "modules/control/controllers/lat_based_lqr_controller/proto/lat_based_lqr_controller_conf.pb.h"
32
42
47namespace apollo {
48namespace control {
49
57class LatController : public ControlTask {
58 public:
63
67 virtual ~LatController();
68
74 common::Status Init(std::shared_ptr<DependencyInjector> injector) override;
75
86 const localization::LocalizationEstimate *localization,
87 const canbus::Chassis *chassis, const planning::ADCTrajectory *trajectory,
88 ControlCommand *cmd) override;
89
94 common::Status Reset() override;
95
99 void Stop() override;
100
105 std::string Name() const override;
106
107 protected:
108 void UpdateState(SimpleLateralDebug *debug, const canbus::Chassis *chassis);
109
110 // logic for reverse driving mode
112
113 void UpdateMatrix();
114
116
117 double ComputeFeedForward(double ref_curvature) const;
118
119 void ComputeLateralErrors(const double x, const double y, const double theta,
120 const double linear_v, const double angular_v,
121 const double linear_a,
122 const TrajectoryAnalyzer &trajectory_analyzer,
123 SimpleLateralDebug *debug,
124 const canbus::Chassis *chassis);
125 bool LoadControlConf();
126 void InitializeFilters();
128 void LogInitParameters();
129 void ProcessLogs(const SimpleLateralDebug *debug,
130 const canbus::Chassis *chassis);
131
132 void CloseLogFile();
133
134 // vehicle
135 LatBaseLqrControllerConf lat_based_lqr_controller_conf_;
136
137 // vehicle parameter
139
140 // a proxy to analyze the planning trajectory
142
143 // the following parameters are vehicle physics related.
144 // control time interval
145 double ts_ = 0.0;
146 // corner stiffness; front
147 double cf_ = 0.0;
148 // corner stiffness; rear
149 double cr_ = 0.0;
150 // distance between front and rear wheel center
151 double wheelbase_ = 0.0;
152 // mass of the vehicle
153 double mass_ = 0.0;
154 // distance from front wheel center to COM
155 double lf_ = 0.0;
156 // distance from rear wheel center to COM
157 double lr_ = 0.0;
158 // rotational inertia
159 double iz_ = 0.0;
160 // the ratio between the turn of the steering wheel and the turn of the wheels
161 double steer_ratio_ = 0.0;
162 // the maximum turn of steer
164
165 // limit steering to maximum theoretical lateral acceleration
166 double max_lat_acc_ = 0.0;
167
168 // number of control cycles look ahead (preview controller)
170
171 // longitudial length for look-ahead lateral error estimation during forward
172 // driving and look-back lateral error estimation during backward driving
173 // (look-ahead controller)
178
179 // number of states without previews, includes
180 // lateral error, lateral error rate, heading error, heading error rate
181 const int basic_state_size_ = 4;
182 // vehicle state matrix
183 Eigen::MatrixXd matrix_a_;
184 // vehicle state matrix (discrete-time)
185 Eigen::MatrixXd matrix_ad_;
186 // vehicle state matrix compound; related to preview
187 Eigen::MatrixXd matrix_adc_;
188 // control matrix
189 Eigen::MatrixXd matrix_b_;
190 // control matrix (discrete-time)
191 Eigen::MatrixXd matrix_bd_;
192 // control matrix compound
193 Eigen::MatrixXd matrix_bdc_;
194 // gain matrix
195 Eigen::MatrixXd matrix_k_;
196 // control authority weighting matrix
197 Eigen::MatrixXd matrix_r_;
198 // state weighting matrix
199 Eigen::MatrixXd matrix_q_;
200 // updated state weighting matrix
201 Eigen::MatrixXd matrix_q_updated_;
202 // vehicle state matrix coefficients
203 Eigen::MatrixXd matrix_a_coeff_;
204 // 4 by 1 matrix; state matrix
205 Eigen::MatrixXd matrix_state_;
206
207 // parameters for lqr solver; number of iterations
209 // parameters for lqr solver; threshold for computation
210 double lqr_eps_ = 0.0;
211
213
214 std::unique_ptr<Interpolation1D> lat_err_interpolation_;
215
216 std::unique_ptr<Interpolation1D> heading_err_interpolation_;
217
218 // MeanFilter heading_rate_filter_;
221
222 // Lead/Lag controller
223 bool enable_leadlag_ = false;
225
226 // Mrac controller
227 bool enable_mrac_ = false;
229
230 // Look-ahead controller
232
233 // for compute the differential valute to estimate acceleration/lon_jerk
235
238
241
242 // for logging purpose
243 std::ofstream steer_log_file_;
244
245 const std::string name_;
246
248
249 double pre_steer_angle_ = 0.0;
250
252
254
256
257 double init_vehicle_x_ = 0.0;
258
259 double init_vehicle_y_ = 0.0;
260
262
263 double low_speed_bound_ = 0.0;
264
265 double low_speed_window_ = 0.0;
266
268
269 std::shared_ptr<DependencyInjector> injector_;
270};
271
272// 1.2 当前类声明为插件
275
276} // namespace control
277} // namespace apollo
The DigitalFilter class is used to pass signals with a frequency lower than a certain cutoff frequenc...
The MeanFilter class is used to smoothen a series of noisy numbers, such as sensor data or the output...
Definition mean_filter.h:45
A general class to denote the return status of an API call.
Definition status.h:43
LQR-Based lateral controller, to compute steering target.
double ComputeFeedForward(double ref_curvature) const
TrajectoryAnalyzer trajectory_analyzer_
common::MeanFilter lateral_error_filter_
void Stop() override
stop Lateral controller
void UpdateState(SimpleLateralDebug *debug, const canbus::Chassis *chassis)
virtual ~LatController()
destructor
void ProcessLogs(const SimpleLateralDebug *debug, const canbus::Chassis *chassis)
common::MeanFilter heading_error_filter_
void ComputeLateralErrors(const double x, const double y, const double theta, const double linear_v, const double angular_v, const double linear_a, const TrajectoryAnalyzer &trajectory_analyzer, SimpleLateralDebug *debug, const canbus::Chassis *chassis)
common::Status Init(std::shared_ptr< DependencyInjector > injector) override
initialize Lateral Controller
common::Status Reset() override
reset Lateral Controller
common::DigitalFilter digital_filter_
LatBaseLqrControllerConf lat_based_lqr_controller_conf_
std::string Name() const override
Lateral controller name
std::unique_ptr< Interpolation1D > heading_err_interpolation_
std::shared_ptr< DependencyInjector > injector_
LeadlagController leadlag_controller_
common::Status ComputeControlCommand(const localization::LocalizationEstimate *localization, const canbus::Chassis *chassis, const planning::ADCTrajectory *trajectory, ControlCommand *cmd) override
compute steering target based on current vehicle status and target trajectory
std::unique_ptr< Interpolation1D > lat_err_interpolation_
common::VehicleParam vehicle_param_
A lead/lag controller for speed and steering using defualt integral hold
A mrac controller for actuation system (throttle/brake and steering)
process point query and conversion related to trajectory
Defines the Controller base class.
#define CYBER_PLUGIN_MANAGER_REGISTER_PLUGIN(name, base)
Defines the DigitalFilter class.
Functions to generate coefficients for digital filter.
Defines the MeanFilter class.
class register implement
Definition arena_queue.h:37
Defines the TrajectoryAnalyzer class.