Apollo 11.0
自动驾驶开放平台
lat_plus_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_plus_controller/proto/lat_based_lqr_plus_controller_conf.pb.h"
32#include "modules/control/control_task_base_extend/proto/params_pipeline.pb.h"
33#include "modules/control/control_component/proto/check_status.pb.h"
34
46
51namespace apollo {
52namespace control {
53
62public:
67
71 virtual ~LatPlusController();
72
78 common::Status Init(std::shared_ptr<DependencyInjector> injector) override;
79
90 const localization::LocalizationEstimate *localization,
91 const canbus::Chassis *chassis,
92 const planning::ADCTrajectory *trajectory,
93 ControlCommand *cmd) override;
94
99 common::Status Reset() override;
100
104 void Stop() override;
105
110 std::string Name() const override;
111
112protected:
113 bool LoadParams(ParamsPipeline *params_pipeline);
114
115 bool SetCurrentParam(
116 const std::string param_config_name,
117 LatBaseLqrPlusControllerConf &current_lat_based_lqr_plus_controller_conf);
118
120 LatBaseLqrPlusControllerConf &current_lat_based_lqr_plus_controller_conf,
121 const planning::ADCTrajectory *planning_published_trajectory);
122
123 void UpdateState(SimpleLateralDebug *debug, SimpleLateralPlusDebug *debug_info, const canbus::Chassis *chassis);
124
125 // logic for reverse driving mode
127
128 void UpdateMatrix();
129
131
132 double ComputeFeedForward(double ref_curvature);
133
135 const double x,
136 const double y,
137 const double theta,
138 const double linear_v,
139 const TrajectoryAnalyzerExtend &trajectory_analyzer,
140 const enum ChooseRefTrajectoryPoint &choose_track_point,
141 SimpleLateralPlusDebug *lat_debug);
142
144 const double x,
145 const double y,
146 const double theta,
147 const double linear_v,
148 const double angular_v,
149 const double linear_a,
150 const TrajectoryAnalyzerExtend &trajectory_analyzer,
151 const canbus::Chassis *chassis,
152 const enum ChooseRefTrajectoryPoint &choose_point,
153 SimpleLateralDebug *debug,
154 SimpleLateralPlusDebug *lat_debug);
155 bool InitControlConf(const LatBaseLqrPlusControllerConf &current_lat_based_lqr_plus_controller_conf);
156 bool UpdateControlConf(const LatBaseLqrPlusControllerConf &current_lat_based_lqr_plus_controller_conf);
157 void InitializeFilters();
158
159 void LogInitParameters();
160 void ProcessLogs(const SimpleLateralDebug *debug, const canbus::Chassis *chassis);
161
162 void CloseLogFile();
163
164 bool IsDrivingStraight(const canbus::Chassis *chassis, double ref_curvature);
165 void UpdateAHCParam(const double &heading_err, const double &speed);
166 double CalculateTempAHCValue(const double &speed);
167 double AutoCompensatedHeadingValue(const double &speed);
168 void AHCClear();
172 const double lookahead_station,
173 const double lookback_station,
174 const double pose_x,
175 const double pose_y,
176 const double theta,
177 const double linear_v,
178 const common::TrajectoryPoint &ref_point,
179 const TrajectoryAnalyzerExtend &trajectory_analyzer,
180 SimpleLateralDebug *debug,
181 SimpleLateralPlusDebug *debug_info);
182
184 const double lateral_error,
185 const double heading_error,
186 const planning::ADCTrajectory *planning_published_trajectory,
187 const SimpleLongitudinalDebug *previous_lon_debug,
188 SimpleLateralDebug *debug,
189 SimpleLateralPlusDebug *debug_info);
190
192 const uint8_t window_size,
193 const double error,
194 const double threshold,
195 std::vector<double> *arr,
196 int32_t *current_sign);
197
198 void ResetComLength();
199
201
202 const canbus::Chassis *chassis_ = nullptr;
203
204 // vehicle
205 LatBaseLqrPlusControllerConf lat_based_lqr_plus_controller_conf_;
206
207 ParamsPipeline params_pipeline_;
208 std::vector<std::pair<std::string, LatBaseLqrPlusControllerConf>> params_list_;
211
212 // vehicle parameter
214
215 // a proxy to analyze the planning trajectory
217
218 // the following parameters are vehicle physics related.
219 // control time interval
220 double ts_ = 0.0;
221 // corner stiffness; front
222 double cf_ = 0.0;
223 // corner stiffness; rear
224 double cr_ = 0.0;
225 // distance between front and rear wheel center
226 double wheelbase_ = 0.0;
227 // mass of the vehicle
228 double mass_ = 0.0;
229 // current mass of the vehicle
230 double mass_current_ = 0.0;
231 // distance from front wheel center to COM
232 double lf_ = 0.0;
233 // distance from rear wheel center to COM
234 double lr_ = 0.0;
235 // rotational inertia
236 double iz_ = 0.0;
237 // the ratio between the turn of the steering wheel and the turn of the wheels
238 double steer_ratio_ = 0.0;
239 // the maximum turn of steer
241
242 // limit steering to maximum theoretical lateral acceleration
243 double max_lat_acc_ = 0.0;
244
245 // number of control cycles look ahead (preview controller)
247
248 // longitudial length for look-ahead lateral error estimation during forward
249 // driving and look-back lateral error estimation during backward driving
250 // (look-ahead controller)
255
256 // number of states without previews, includes
257 // lateral error, lateral error rate, heading error, heading error rate
258 const int basic_state_size_ = 4;
259 // vehicle state matrix
260 Eigen::MatrixXd matrix_a_;
261 // vehicle state matrix (discrete-time)
262 Eigen::MatrixXd matrix_ad_;
263 // vehicle state matrix compound; related to preview
264 Eigen::MatrixXd matrix_adc_;
265 // control matrix
266 Eigen::MatrixXd matrix_b_;
267 // control matrix (discrete-time)
268 Eigen::MatrixXd matrix_bd_;
269 // control matrix compound
270 Eigen::MatrixXd matrix_bdc_;
271 // gain matrix
272 Eigen::MatrixXd matrix_k_;
273 // control authority weighting matrix
274 Eigen::MatrixXd matrix_r_;
275 // state weighting matrix
276 Eigen::MatrixXd matrix_q_;
277 // updated state weighting matrix
278 Eigen::MatrixXd matrix_q_updated_;
279 // vehicle state matrix coefficients
280 Eigen::MatrixXd matrix_a_coeff_;
281 // 4 by 1 matrix; state matrix
282 Eigen::MatrixXd matrix_state_;
283
284 // parameters for lqr solver; number of iterations
286 // parameters for lqr solver; threshold for computation
287 double lqr_eps_ = 0.0;
288
290
291 std::unique_ptr<Interpolation1D> lat_err_interpolation_;
292
293 std::unique_ptr<Interpolation1D> heading_err_interpolation_;
294
295 // MeanFilter heading_rate_filter_;
298
299 // Lead/Lag controller
300 bool enable_leadlag_ = false;
302
303 // Mrac controller
304 bool enable_mrac_ = false;
306
307 // Look-ahead controller
310
311 // for compute the differential valute to estimate acceleration/lon_jerk
313
316
319
322
323 // for logging purpose
324 std::ofstream steer_log_file_;
325
326 const std::string name_;
327
329
330 double pre_steer_angle_ = 0.0;
331
333
335
337
338 double init_vehicle_x_ = 0.0;
339
340 double init_vehicle_y_ = 0.0;
341
343
344 double low_speed_bound_ = 0.0;
345
346 double low_speed_window_ = 0.0;
347
349
350 std::shared_ptr<DependencyInjector> injector_;
351
352 // AHC means auto heading compensation;
354 double AHC_mean_ = 0.0;
355 double AHC_peak_ = 0.0;
356 double AHC_sum_ = 0.0;
361 std::deque<double> AHC_container_;
362
364
365 ReverseLogicStage::ReverseStageType now_reverse_stage_ = ReverseLogicStage::NO_REVERSE;
366 double efai_rate_ = 1.0;
367 double ed_date_ = 1.0;
368
370
371 // checker count
374
377
378 enum ChooseRefTrajectoryPoint choose_ref_point_ = USE_LAT_MATCH_COM;
379 int32_t current_sign_ = 0;
381 std::vector<double> lateral_lr_errors_;
382 int32_t prev_sign_ = 0;
383 int32_t prev_abs_ = 0;
384 double com_change_ = 0.0;
385 double com_change_reset_ = 0.0;
386 double com_change_add_ = 0.0;
391 bool is_lat_turbulence_ = false;
395};
396
397// 1.2 当前类声明为插件
399
400} // namespace control
401} // 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.
void LateralSafetyCheck(SimpleLateralDebug *debug, SimpleLateralPlusDebug *debug_info)
std::unique_ptr< Interpolation1D > heading_err_interpolation_
LatBaseLqrPlusControllerConf current_lat_based_lqr_plus_controller_conf_
void UpdateState(SimpleLateralDebug *debug, SimpleLateralPlusDebug *debug_info, const canbus::Chassis *chassis)
void UpdateLookForwardPointError(const double lookahead_station, const double lookback_station, const double pose_x, const double pose_y, const double theta, const double linear_v, const common::TrajectoryPoint &ref_point, const TrajectoryAnalyzerExtend &trajectory_analyzer, SimpleLateralDebug *debug, SimpleLateralPlusDebug *debug_info)
bool InitControlConf(const LatBaseLqrPlusControllerConf &current_lat_based_lqr_plus_controller_conf)
void ComputeTrackLateralErrors(const double x, const double y, const double theta, const double linear_v, const TrajectoryAnalyzerExtend &trajectory_analyzer, const enum ChooseRefTrajectoryPoint &choose_track_point, SimpleLateralPlusDebug *lat_debug)
std::vector< std::pair< std::string, LatBaseLqrPlusControllerConf > > params_list_
double CalculateTempAHCValue(const double &speed)
ReverseLogicStage::ReverseStageType now_reverse_stage_
std::unique_ptr< Interpolation1D > lat_err_interpolation_
bool LoadParams(ParamsPipeline *params_pipeline)
void EnhanceQParamsAlternate(const double lateral_error, const double heading_error, const planning::ADCTrajectory *planning_published_trajectory, const SimpleLongitudinalDebug *previous_lon_debug, SimpleLateralDebug *debug, SimpleLateralPlusDebug *debug_info)
TrajectoryAnalyzerExtend trajectory_analyzer_
void ProcessLogs(const SimpleLateralDebug *debug, const canbus::Chassis *chassis)
double ComputeFeedForward(double ref_curvature)
bool ChooseCurrentParam(LatBaseLqrPlusControllerConf &current_lat_based_lqr_plus_controller_conf, const planning::ADCTrajectory *planning_published_trajectory)
common::Status Init(std::shared_ptr< DependencyInjector > injector) override
initialize Lateral Controller
double AutoCompensatedHeadingValue(const double &speed)
bool SetCurrentParam(const std::string param_config_name, LatBaseLqrPlusControllerConf &current_lat_based_lqr_plus_controller_conf)
bool IsDrivingStraight(const canbus::Chassis *chassis, double ref_curvature)
void UpdateAHCParam(const double &heading_err, const double &speed)
std::shared_ptr< DependencyInjector > injector_
bool UpdateControlConf(const LatBaseLqrPlusControllerConf &current_lat_based_lqr_plus_controller_conf)
bool CheckContinousErrors(const uint8_t window_size, const double error, const double threshold, std::vector< double > *arr, int32_t *current_sign)
void Stop() override
stop Lateral controller
enum ChooseRefTrajectoryPoint choose_ref_point_
std::string Name() const override
Lateral controller name
void ComputeLateralErrors(const double x, const double y, const double theta, const double linear_v, const double angular_v, const double linear_a, const TrajectoryAnalyzerExtend &trajectory_analyzer, const canbus::Chassis *chassis, const enum ChooseRefTrajectoryPoint &choose_point, SimpleLateralDebug *debug, SimpleLateralPlusDebug *lat_debug)
common::Status Reset() override
reset Lateral Controller
LatBaseLqrPlusControllerConf lat_based_lqr_plus_controller_conf_
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
A mrac controller for actuation system (throttle/brake and steering)
process point query and conversion related to trajectory
Defines the ControlChecker class.
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