Apollo 11.0
自动驾驶开放平台
anti_slip_control_task.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 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
18
19#include "cyber/common/log.h"
22#include "absl/strings/str_cat.h"
23
24namespace apollo {
25namespace control {
26
32
33constexpr double GRA_ACC = 9.8;
34
35AntiSlipControlTask::AntiSlipControlTask() : name_("Slope Anti-Slip Control Task") {
36 AINFO << "Using " << name_;
37}
38
39Status AntiSlipControlTask::Init(std::shared_ptr<DependencyInjector> injector) {
40 // hook: Apollo License Verification: v_apollo_park
41 if (!ControlTask::LoadConfig<AntiSlipControlTaskConf>(&antislip_control_task_conf_)) {
42 AERROR << "Failed to load control task conf";
43 return Status(ErrorCode::CONTROL_INIT_ERROR, "Failed to load slop anti-slip control task conf");
44 }
45 if (!ControlTaskExtend::LoadParamsPipelineConfig<ParamsPipeline>(&params_pipeline_)) {
46 AERROR << "failed to load anti params pipeline config";
47 return Status(ErrorCode::CONTROL_INIT_ERROR, "failed to load anti params pipeline config");
48 }
49 if (!LoadParams(&params_pipeline_)) {
50 AERROR << "failed to load anti controller params.";
51 return Status(ErrorCode::CONTROL_INIT_ERROR, "failed to load anti anti controller params.");
52 }
53 if (!ControlTask::LoadCalibrationTable(&calibration_table_)) {
54 AERROR << "failed to load calibration table";
55 return Status(ErrorCode::CONTROL_INIT_ERROR, "lon failed to load calibration table");
56 }
57 injector_ = injector;
58 SetDigitalFilterPitchAngle();
59 InitControlCalibrationTable();
60 enable_acc_gain_ = antislip_control_task_conf_.enable_slope_offset();
61 vehicle_param_.CopyFrom(common::VehicleConfigHelper::Instance()->GetConfig().vehicle_param());
62 hill_start_window_ = antislip_control_task_conf_.hill_start_preview_window();
63 return Status::OK();
64}
65
66bool AntiSlipControlTask::LoadParams(ParamsPipeline *params_pipeline) {
67 for (int i = 0; i < params_pipeline->params_declare_size(); i++) {
68 AntiSlipControlTaskConf param_config;
69 auto param_config_path = params_pipeline->params_declare(i).config_path();
70 std::string param_config_path_relative = absl::StrCat("conf", "/", param_config_path);
71 AINFO << "Param config_path_relative is " << param_config_path_relative;
72 std::string param_config_path_absolute
74 "apollo::control::AntiSlipControlTask", param_config_path_relative);
75 AINFO << "Param config_path_absolute is " << param_config_path_absolute;
76 if (!apollo::cyber::common::GetProtoFromFile(param_config_path_absolute, &param_config)) {
77 AERROR << "Load config: " << params_pipeline->params_declare(i).config_name() << " param failed!";
78 return false;
79 }
80 AINFO << "Load the config file successfully, param file name: " << param_config_path;
81 params_list_.push_back(std::make_pair(params_pipeline->params_declare(i).config_name(), param_config));
82 }
83 return true;
84}
85
86bool AntiSlipControlTask::SetCurrentParam(
87 const std::string param_config_name,
88 AntiSlipControlTaskConf &antislip_control_task_conf_) {
89 bool set_success = false;
90 for (const auto &param : params_list_) {
91 if (param.first == param_config_name) {
92 antislip_control_task_conf_.CopyFrom(param.second);
93 set_success = true;
94 ADEBUG << "find the right params, set the currernt param_config_name is " << param_config_name;
95 break;
96 }
97 }
98 if (!set_success) {
99 AERROR << "Fail to find lon current param[" << param_config_name << "]";
100 }
101 return set_success;
102}
103
104bool AntiSlipControlTask::ChooseCurrentParam(
105 const planning::ADCTrajectory *trajectory_msg,
106 AntiSlipControlTaskConf &antislip_control_task_conf_) {
107 std::string param_config_name = "";
108
109 if (trajectory_msg->trajectory_type() == ADCTrajectory::EDGE_FOLLOW) {
110 param_config_name = "edge_follow_param";
111 } else {
112 param_config_name = "public_road_param";
113 }
114
115 if (!SetCurrentParam(param_config_name, antislip_control_task_conf_)) {
116 AERROR << "Failed to set current anti param config: " << param_config_name;
117 return false;
118 } else {
119 if (param_config_name != current_param_config_name_) {
120 AINFO << "Update the current anti param config name is " << param_config_name;
121 current_param_config_name_ = param_config_name;
122 }
123 return true;
124 }
125}
126
128 const localization::LocalizationEstimate *localization,
129 const canbus::Chassis *chassis,
130 const planning::ADCTrajectory *planning_published_trajectory,
131 ControlCommand *cmd) {
132 trajectory_message_ = planning_published_trajectory;
133 if (planning_published_trajectory->trajectory_type() == ADCTrajectory::OPEN_SPACE) {
134 // if reverse,dont use this task
135 return Status::OK();
136 }
137
138 if (!ChooseCurrentParam(trajectory_message_, antislip_control_task_conf_)) {
139 AERROR << "Fail to load current anti control param!";
140 return Status(ErrorCode::CONTROL_COMPUTE_ERROR, "Fail to load current anti control param!");
141 }
142
143 uphill_too_fast_ = false;
144 only_use_brk_downhill_ = false;
145 erase_brk_in_go_ = false;
146 erase_brk_in_end_ = false;
147
148 // speed filter
149 double current_speed = GetVehicleSpeed(injector_, FLAGS_use_speed_filter, FLAGS_speed_smoothing_factor);
150
151 auto anti_slip_debug_info = injector_->mutable_control_debug_info()->mutable_simple_anti_slope_debug();
152 anti_slip_debug_info->Clear();
153 if (!previous_is_auto_ && chassis->driving_mode() == apollo::canbus::Chassis::COMPLETE_AUTO_DRIVE) {
154 from_else_to_auto_ = true;
155 ADEBUG << "From else to auto!!!";
156 } else {
157 from_else_to_auto_ = false;
158 }
160 && gear_drive_count_ > antislip_control_task_conf_.gear_drive_count_num()) {
161 previous_is_auto_ = true;
162 } else {
163 previous_is_auto_ = false;
164 }
165
166 if (chassis->gear_location() != canbus::Chassis::GEAR_DRIVE) {
167 gear_drive_count_ = 0;
168 previous_is_auto_ = false;
169 } else {
170 gear_drive_count_++;
171 }
172
173 auto lon_debug = cmd->mutable_debug()->mutable_simple_lon_debug();
174 auto lon_debug_previous = injector_->Get_previous_lon_debug_info();
175 double throttle_cmd = cmd->throttle();
176 double throttle_lowerbound = vehicle_param_.throttle_deadzone();
177 double brake_cmd = cmd->brake();
178 double brake_lowerbound = vehicle_param_.brake_deadzone();
179 if (brake_lowerbound <= antislip_control_task_conf_.brake_minimum_action()) {
180 brake_lowerbound = antislip_control_task_conf_.brake_minimum_action();
181 }
182 double calibration_value = 0.0;
183
184 double max_path_remain_when_stopped
185 = FLAGS_max_path_remain_when_stopped + antislip_control_task_conf_.path_remain_threshold();
186
187 double vehicle_pitch_rad = injector_->vehicle_state()->pitch();
188 double vehicle_pitch = vehicle_pitch_rad * 180 / M_PI + FLAGS_pitch_offset_deg;
189 lon_debug->set_vehicle_pitch(vehicle_pitch);
190 FindMaxSpeedInPreviewWindow(planning_published_trajectory);
191 FindMinSpeedInPreviewWindow(planning_published_trajectory);
192 if (CheckSlope(vehicle_pitch)) {
193 int reverse_flag = 1;
195 reverse_flag = -1;
196 }
197 ADEBUG << "Into anti-slip stop process.";
198 if (((CheckAccGainPoint(max_path_remain_when_stopped, lon_debug, lon_debug_previous)
199 != AntiSlipControlTaskConf::MOVING_DEFAULT_DESTNATION)
200 && !lon_debug->is_full_stop() && !lon_debug->is_full_stop_soft())
201 || enable_acc_gain_) {
202 ADEBUG << "is_full_stop is " << lon_debug->is_full_stop();
203 ADEBUG << "Into acc gain process.";
204 // TODO(ALL): confirm the slope_offset_compensation whether is positive or
205 // not when vehicle move uphill Resume: uphill: + , downhill: -
206 double slope_offset_compensation = antislip_control_task_conf_.use_opposite_slope_compensation() * GRA_ACC
207 * std::sin(vehicle_pitch_rad + FLAGS_pitch_offset_deg * M_PI / 180);
208 if (reverse_flag == 1 && lon_debug->speed_error() < antislip_control_task_conf_.cut_hill_up_throttle_speed()
209 && vehicle_pitch > 0) {
210 slope_offset_compensation
211 = slope_offset_compensation * antislip_control_task_conf_.cut_hill_up_throttle_rate();
212 // uphill forward too fast
213 uphill_too_fast_ = true;
214 } else if (
215 reverse_flag == -1
216 && lon_debug->speed_error() > -1 * antislip_control_task_conf_.cut_hill_up_throttle_speed()
217 && vehicle_pitch < 0) {
218 slope_offset_compensation
219 = slope_offset_compensation * antislip_control_task_conf_.cut_hill_up_throttle_rate();
220 // uphill backward too fast
221 uphill_too_fast_ = true;
222 }
223 if (std::isnan(slope_offset_compensation)) {
224 slope_offset_compensation = 0;
225 }
226 lon_debug->set_slope_offset_compensation(slope_offset_compensation);
227 anti_slip_debug_info->set_slope_offset_compensation(slope_offset_compensation);
228 double acceleration_cmd = lon_debug->acceleration_cmd_closeloop()
229 + lon_debug->preview_acceleration_reference()
230 + antislip_control_task_conf_.enable_slope_offset() * slope_offset_compensation;
231 ADEBUG << "[acc gain process] acceleration_cmd gain to: " << acceleration_cmd;
232 ADEBUG << "[acc gain process] close loop: " << lon_debug->acceleration_cmd_closeloop();
233 ADEBUG << "[acc gain process] acceleration_preview_acceleration_reference "
234 "to: "
235 << lon_debug->preview_acceleration_reference();
236 ADEBUG << "[acc gain process] acceleration_compensation_ to: "
237 << antislip_control_task_conf_.enable_slope_offset() * slope_offset_compensation;
238 ADEBUG << "[acc gain process] compensation_ to: " << slope_offset_compensation;
239 ADEBUG << "[acc gain process] pitch = " << vehicle_pitch;
240
241 double acceleration_lookup = (chassis->gear_location() == canbus::Chassis::GEAR_REVERSE) ? -acceleration_cmd
242 : acceleration_cmd;
243 anti_slip_debug_info->set_anti_acc_lookup(acceleration_lookup);
244 // acceleration_lookup > 0: THROTTLE
245 // acceleration_lookup < 0: BRAKE
246 calibration_value
247 = control_interpolation_->Interpolate(std::make_pair(chassis->speed_mps(), acceleration_lookup));
248 anti_slip_debug_info->set_calibration_value_anti(calibration_value);
249 if (acceleration_lookup >= 0) {
250 if (calibration_value >= 0) {
251 throttle_cmd = std::max(calibration_value, throttle_lowerbound);
252 anti_stage_ = "acc lookup and cali > 0, stage1";
253 } else {
254 throttle_cmd = throttle_lowerbound;
255 anti_stage_ = "acc lookup > 0 ,cali < 0, stage2";
256 }
257 brake_cmd = 0.0;
258 previous_downhill_go_brk_ = 0.0;
259 pre_cali_down_hill_ = 0.0;
260 } else {
261 // the car is going downhill,acceleration_lookup < 0DetectObstacle
262 throttle_cmd = 0.0;
263 if (calibration_value >= 0) {
264 brake_cmd = brake_lowerbound;
265 throttle_cmd = 0.0;
266 previous_downhill_go_brk_ = 0.0;
267 pre_cali_down_hill_ = 0.0;
268 anti_stage_ = "acc lookup < 0 and cali > 0, stage3";
269 } else {
270 // use only brake to go downhill
271 only_use_brk_downhill_ = true;
272 if ((std::fabs(lon_debug->acceleration_cmd_closeloop()) < std::fabs(slope_offset_compensation))
273 && (vehicle_pitch * reverse_flag < 0)) {
274 brake_cmd = std::max(-calibration_value, brake_lowerbound);
275
276 if (reverse_flag == 1 && (vehicle_pitch < 0)) {
277 // TODO:
278 // it is a method to avoid the being too fast or too slow,but it can be cancled ,cause it
279 // may stop the car suddendly
280
281 // if (lon_debug->speed_error() > antislip_control_task_conf_.downhill_cut_brake_v_err()) {
282 // // should kill brake ,too slow
283 // previous_downhill_go_brk_ = previous_downhill_go_brk_
284 // - antislip_control_task_conf_.downhill_brake_change();
285 // }
286 // if (lon_debug->speed_error()
287 // < (-1) * antislip_control_task_conf_.downhill_cut_brake_v_err()) {
288 // // should add brake,car is too fast
289 // previous_downhill_go_brk_ = previous_downhill_go_brk_
290 // + antislip_control_task_conf_.downhill_brake_change();
291 // }
292 // if ((lon_debug->speed_error() <= antislip_control_task_conf_.downhill_cut_brake_v_err())
293 // && (lon_debug->speed_error()
294 // >= (-1) * antislip_control_task_conf_.downhill_cut_brake_v_err())) {
295 // previous_downhill_go_brk_ = previous_downhill_go_brk_;
296 // }
297
298 // else {
299 // brake_cmd = brake_cmd + previous_downhill_go_brk_;
300 // }
301 if (std::fabs(current_speed) < antislip_control_task_conf_.maintain_min_speed()) {
302 brake_cmd = 0.0;
303 anti_stage_ = "acc lookup < 0 and cali < 0, stage4";
304 }
305 if (lon_debug->speed_error()
306 < -1 * antislip_control_task_conf_.downhill_cut_brake_v_err()) {
307 if (brake_cmd - pre_cali_down_hill_
308 > antislip_control_task_conf_.downhill_brake_change_max()) {
309 brake_cmd = pre_cali_down_hill_
310 + 2 * antislip_control_task_conf_.downhill_brake_change_max();
311 }
312 } else {
313 if (brake_cmd - pre_cali_down_hill_
314 > antislip_control_task_conf_.downhill_brake_change_max()) {
315 brake_cmd = pre_cali_down_hill_
316 + antislip_control_task_conf_.downhill_brake_change_max();
317 }
318 }
319 if (brake_cmd == 0.0) {
320 pre_cali_down_hill_
321 = pre_cali_down_hill_ * antislip_control_task_conf_.downhill_brake_rate();
322 } else {
323 pre_cali_down_hill_ = brake_cmd;
324 }
325 }
326
327 // TODO: the method when car go reversely
328 // if (reverse_flag == -1 && (vehicle_pitch > 0)) {
329 // if (lon_debug->speed_error()
330 // < (-1) * antislip_control_task_conf_.downhill_cut_brake_v_err()) {
331 // brake_cmd = previous_downhill_go_brk_
332 // - antislip_control_task_conf_.downhill_brake_change();
333 // }
334 // if (lon_debug->speed_error() > antislip_control_task_conf_.downhill_cut_brake_v_err()) {
335 // brake_cmd = previous_downhill_go_brk_
336 // + antislip_control_task_conf_.downhill_brake_change();
337 // }
338 // if ((lon_debug->speed_error() <= antislip_control_task_conf_.downhill_cut_brake_v_err())
339 // && (lon_debug->speed_error()
340 // >= (-1) * antislip_control_task_conf_.downhill_cut_brake_v_err())) {
341 // brake_cmd = previous_downhill_go_brk_;
342 // }
343 // }
344 }
345
346 if (brake_cmd <= 0) {
347 anti_stage_ = "brk < 0, set brk 0 stage5";
348 brake_cmd = 0.0;
349 }
350 ADEBUG << "usr brk to go,cmd = " << brake_cmd << "calibration_value = " << calibration_value;
351 ADEBUG << "acceleration_lookup = " << acceleration_lookup;
352 // previous_downhill_go_brk_ = brake_cmd;
353 }
354 }
355
356 if ((std::fabs(current_speed) < antislip_control_task_conf_.maintain_min_speed())
357 && (lon_debug->speed_error() > antislip_control_task_conf_.cut_unusual_brk_speed_error())) {
358 if ((!in_hill_start_condition_) && (!in_normal_start_condition_) && (!on_obstacle_)
359 && (planning_published_trajectory->trajectory_type() != ADCTrajectory::OPEN_SPACE)) {
360 brake_cmd = 0.0;
361 erase_brk_in_go_ = true;
362 }
363 }
364
365 if ((vehicle_pitch <= antislip_control_task_conf_.uphill_start_pitch())
366 && (vehicle_pitch >= antislip_control_task_conf_.normal_start_pitch())
367 && (planning_published_trajectory->trajectory_type() != ADCTrajectory::OPEN_SPACE)) {
368 if (lon_debug->path_remain() > antislip_control_task_conf_.cncl_brake_min_path()
369 && lon_debug->path_remain() <= antislip_control_task_conf_.cncl_brake_max_path()) {
370 if ((!in_hill_start_condition_) && (!in_normal_start_condition_) && (!on_obstacle_)
371 && (min_speed_preview_ < antislip_control_task_conf_.preview_min_speed_threshold())
372 && (lon_debug->preview_acceleration_reference()
373 > antislip_control_task_conf_.emergency_acc())) {
374 if (lon_debug->speed_error() < antislip_control_task_conf_.cut_hill_up_throttle_speed()) {
375 if (cmd->brake() > antislip_control_task_conf_.cncl_max_brake()) {
376 brake_cmd = antislip_control_task_conf_.cncl_max_brake();
377 }
378 } else {
379 brake_cmd = 0.0;
380 erase_brk_in_end_ = true;
381 }
382 }
383 }
384 }
385
386 if ((!in_hill_start_condition_) && (!in_normal_start_condition_)
387 && DetectHillStartCondition(cmd, planning_published_trajectory, current_speed)) {
388 ADEBUG << "in hill start condition,pitch = " << vehicle_pitch;
389 if (vehicle_pitch >= antislip_control_task_conf_.uphill_start_pitch()
390 && antislip_control_task_conf_.enable_hill_start()) {
391 ADEBUG << "uphill!!!!!! start condition";
392 in_hill_start_condition_ = true;
393 CalculateHillStartACCAndBrakeRate(cmd, planning_published_trajectory);
394 previous_hill_start_acc_ = hill_start_first_acc_;
395 previous_hill_start_brake_ = antislip_control_task_conf_.epb_brake_cmd();
396 }
397 if ((vehicle_pitch >= antislip_control_task_conf_.normal_start_pitch())
398 && (vehicle_pitch < antislip_control_task_conf_.uphill_start_pitch())
399 && antislip_control_task_conf_.enable_normal_start()) {
400 in_normal_start_condition_ = true;
401 previous_hill_start_acc_ = hill_start_first_acc_;
402 ADEBUG << "in normal start condition,normal start !!!!!!!!";
403 CalculateNormalStartACC(cmd);
404 }
405 } else {
406 if (FLAGS_use_vehicle_epb) {
407 UseVehicleEpb(chassis, cmd);
408 ADEBUG << "[anti-slip stop in condition]: Into vehicle epb, parking "
409 "brake true.";
410 } else if (lon_debug->is_full_stop_soft() || lon_debug->is_full_stop()) {
411 brake_cmd = std::max(brake_cmd, antislip_control_task_conf_.epb_brake_cmd());
412 ADEBUG << "[anti-slip stop in condition]: Into non vehicle epb, "
413 "throttle cmd is 0, brake cmd is "
414 << brake_cmd;
415 lon_debug->set_is_epb_brake(true);
416 ADEBUG << "anti slip brake triggered in slope: " << lon_debug->is_epb_brake();
417 } else {
418 lon_debug->set_is_epb_brake(false);
419 ADEBUG << "[anti-slip stop out condition]: anti slip brake is not "
420 "triggered in slope.";
421 }
422 }
423
424 if (in_hill_start_condition_) {
425 if (chassis->gear_location() == canbus::Chassis::GEAR_DRIVE && !chassis->parking_brake()) {
426 // hill start control begin:
427 if (hill_start_acc_count_ > antislip_control_task_conf_.hill_start_acc_window()) {
428 hill_start_acc_gain_rate_ = 0;
429 ADEBUG << "flag over set acc gain to 0";
430 }
431 slope_start_acc_ = hill_start_acc_gain_rate_ + previous_hill_start_acc_;
432 previous_hill_start_acc_ = slope_start_acc_;
433 double hill_start_throttle = control_interpolation_->Interpolate(
434 std::make_pair(chassis->speed_mps(), slope_start_acc_));
435 throttle_cmd = std::max(hill_start_throttle, throttle_lowerbound);
436
437 if (hill_start_brake_count_ >= antislip_control_task_conf_.hill_start_brake_window()) {
438 brake_cmd = 0.0;
439 } else if (
440 hill_start_brake_count_ >= antislip_control_task_conf_.hill_start_brake_standby_window()) {
441 brake_cmd = previous_hill_start_brake_ - hill_start_brake_dec_rate_;
442 previous_hill_start_brake_ = brake_cmd;
443 } else {
444 brake_cmd = antislip_control_task_conf_.epb_brake_cmd();
445 }
446 hill_start_acc_count_++;
447 hill_start_brake_count_++;
448 }
449 if (chassis->gear_location() == canbus::Chassis::GEAR_NEUTRAL || chassis->parking_brake()) {
450 brake_cmd = antislip_control_task_conf_.epb_brake_cmd();
451 }
452 }
453
454 if (in_normal_start_condition_) {
455 if (chassis->gear_location() == canbus::Chassis::GEAR_DRIVE && !chassis->parking_brake()) {
456 brake_cmd = 0.0;
457 if (normal_start_gain_count_ >= antislip_control_task_conf_.normal_start_gain_window()) {
458 normal_start_acc_gain_rate_ = 0.0;
459 }
460 slope_start_acc_ = normal_start_acc_gain_rate_ + previous_hill_start_acc_;
461 if (slope_start_acc_ < 0) {
462 slope_start_acc_ = 0.0;
463 }
464 if (slope_start_acc_ >= normal_start_tartget_acc_) {
465 slope_start_acc_ = normal_start_tartget_acc_;
466 }
467 previous_hill_start_acc_ = slope_start_acc_;
468 double hill_start_throttle = control_interpolation_->Interpolate(
469 std::make_pair(chassis->speed_mps(), slope_start_acc_));
470 throttle_cmd = std::max(hill_start_throttle, throttle_lowerbound)
471 * antislip_control_task_conf_.normal_acc_rate();
472 ADEBUG << "set normal throttle_cmd" << throttle_cmd;
473 ADEBUG << "now acc = " << slope_start_acc_;
474 normal_start_gain_count_++;
475 normal_start_maintain_count_++;
476 }
477 }
478
479 if (DetectQuitHillStart(cmd, current_speed)) {
480 ADEBUG << "quit hill start,clear flags";
481 in_hill_start_condition_ = false;
482 in_normal_start_condition_ = false;
483 hill_start_acc_count_ = 0;
484 hill_start_brake_count_ = 0;
485 previous_hill_start_acc_ = 0.0;
486 previous_hill_start_brake_ = 0.0;
487 hill_start_acc_gain_rate_ = 0.0;
488 hill_start_brake_dec_rate_ = 0.0;
489 quit_hill_start_speed_ = 0.0;
490 hill_start_first_acc_ = 0.0;
491 normal_start_tartget_acc_ = 0.0;
492 normal_start_gain_count_ = 0;
493 normal_start_maintain_count_ = 0;
494 normal_start_acc_gain_rate_ = 0.0;
495 preview_length_ = 0;
496 slope_start_acc_ = 0.0;
497 }
498
499 ADEBUG << "out put acc = " << acceleration_cmd;
500 lon_debug->set_acceleration_cmd(acceleration_cmd);
501 lon_debug->set_acceleration_lookup(acceleration_lookup);
502 if (!lon_debug->is_full_stop() && !lon_debug->is_full_stop_soft()) {
503 throttle_cmd
504 = ThrottleCmdFilter(FLAGS_use_throttle_filter, FLAGS_throttle_smoothing_factor, throttle_cmd);
505 cmd->set_throttle(throttle_cmd);
506 cmd->set_brake(brake_cmd);
507 } else {
508 previous_is_auto_ = false;
509 }
510 }
511 } else {
512 ResetHillStart();
513 ADEBUG << "Not into anti-slip stop process because out of enable threshold: "
514 << antislip_control_task_conf_.slope_offset_threhold();
515 }
516 DetectObstacle(cmd, chassis, current_speed);
517 if (on_obstacle_) {
518 quit_obstacle_count_++;
519 ADEBUG << "[obstacle] overcome obstacle,throttle = " << previous_obs_throttle_;
520 previous_obs_throttle_ = previous_obs_throttle_ + antislip_control_task_conf_.obs_throttle_add_rate();
521 if (!lon_debug->is_full_stop() && !lon_debug->is_full_stop_soft()) {
522 // previous_obs_throttle_ = ThrottleCmdFilter(FLAGS_use_throttle_filter, FLAGS_throttle_smoothing_factor,
523 // previous_obs_throttle_);
524 if (previous_obs_throttle_ > 99.0) {
525 previous_obs_throttle_ = 99.0;
526 }
527 cmd->set_throttle(previous_obs_throttle_);
528 }
529 }
530 previous_park_brake_ = cmd->parking_brake();
531
533 || (chassis->gear_location() != trajectory_message_->gear())) {
534 brake_cmd = antislip_control_task_conf_.epb_brake_cmd();
535 throttle_cmd = 0.0;
536 cmd->set_throttle(throttle_cmd);
537 cmd->set_brake(brake_cmd);
538 }
539
540 auto control_interactive_info = injector_->mutable_control_interactive_info();
541 if (antislip_control_task_conf_.judge_safety_check()) {
542 if (lon_debug->is_full_stop() || lon_debug->is_full_stop_soft()
543 || (lon_debug->acceleration_reference() > antislip_control_task_conf_.cancle_safety_check_acc()
544 && current_speed < antislip_control_task_conf_.cancle_safety_check_speed())
545 || (std::fabs(vehicle_pitch) > antislip_control_task_conf_.cancle_safety_check_pitch())) {
546 // situations dont use safety check
547 // 0 use cancle fullstop
548 // 1 fullstop(soft)
549 // 2 accpreviwe > thres && v < thres(car is starting)
550 // 3 vehicle pitch toobig toosmall
551 control_interactive_info->set_is_need_safety_check(false);
552 } else {
553 control_interactive_info->set_is_need_safety_check(true);
554 }
555 } else {
556 control_interactive_info->set_is_need_safety_check(true);
557 }
558
559 // set some debug info
560 anti_slip_debug_info->set_hill_start_window(hill_start_window_);
561 anti_slip_debug_info->set_preview_length(preview_length_);
562 anti_slip_debug_info->set_quit_hill_start_speed(quit_hill_start_speed_);
563 anti_slip_debug_info->set_normal_start_tartget_acc(normal_start_tartget_acc_);
564 anti_slip_debug_info->set_in_hill_start_condition(in_hill_start_condition_);
565 anti_slip_debug_info->set_in_normal_start_condition(in_normal_start_condition_);
566 anti_slip_debug_info->set_hill_start_acc_gain_rate(hill_start_acc_gain_rate_);
567 anti_slip_debug_info->set_normal_start_acc_gain_rate(normal_start_acc_gain_rate_);
568 anti_slip_debug_info->set_on_obstacle(on_obstacle_);
569 anti_slip_debug_info->set_from_else_to_auto(from_else_to_auto_);
570 anti_slip_debug_info->set_previous_is_auto(previous_is_auto_);
571 anti_slip_debug_info->set_uphill_too_fast(uphill_too_fast_);
572 anti_slip_debug_info->set_only_use_brk_downhill(only_use_brk_downhill_);
573 anti_slip_debug_info->set_erase_brk_in_go(erase_brk_in_go_);
574 anti_slip_debug_info->set_erase_brk_in_end(erase_brk_in_end_);
575 anti_slip_debug_info->set_anti_cmd_brake(brake_cmd);
576 anti_slip_debug_info->set_anti_cmd_throttle(throttle_cmd);
577 anti_slip_debug_info->set_hill_start_first_acc(hill_start_first_acc_);
578 anti_slip_debug_info->set_slope_start_acc(slope_start_acc_);
579 anti_slip_debug_info->set_anti_stage(anti_stage_);
580
581 return Status::OK();
582}
583
584void AntiSlipControlTask::SetDigitalFilterPitchAngle() {
585 double cutoff_freq = antislip_control_task_conf_.pitch_angle_filter_conf().cutoff_freq();
586 double ts = antislip_control_task_conf_.ts();
587 SetDigitalFilter(ts, cutoff_freq, &digital_filter_pitch_angle_);
588}
589
590void AntiSlipControlTask::SetDigitalFilter(double ts, double cutoff_freq, common::DigitalFilter *digital_filter) {
591 std::vector<double> denominators;
592 std::vector<double> numerators;
593 common::LpfCoefficients(ts, cutoff_freq, &denominators, &numerators);
594 digital_filter->set_coefficients(denominators, numerators);
595}
596
597void AntiSlipControlTask::InitControlCalibrationTable() {
598 ADEBUG << "[Anti-slip] Control calibration table size is " << calibration_table_.calibration_size();
600 for (const auto &calibration : calibration_table_.calibration()) {
601 xyz.push_back(std::make_tuple(calibration.speed(), calibration.acceleration(), calibration.command()));
602 }
603 control_interpolation_.reset(new Interpolation2D);
604 ACHECK(control_interpolation_->Init(xyz)) << "Fail to load control calibration table";
605}
606
607bool AntiSlipControlTask::CheckSlope(double vehicle_pitch) {
608 if (std::fabs(vehicle_pitch) >= antislip_control_task_conf_.slope_offset_threhold()) {
609 ADEBUG << "Current vehicle is in slope.";
610 return true;
611 }
612
613 return false;
614}
615
616void AntiSlipControlTask::UseVehicleEpb(const canbus::Chassis *chassis, ControlCommand *control_command) {
617 auto lon_debug = control_command->mutable_debug()->mutable_simple_lon_debug();
618 double brake_cmd = control_command->brake();
619 if (previous_park_brake_ && !control_command->parking_brake()) {
620 brake_cmd = antislip_control_task_conf_.epb_brake_cmd();
621 is_brake_hold_ = true;
622 ADEBUG << "is_brake_hold_ is true.";
623 }
624 if (is_brake_hold_ && (lon_debug->acceleration_lookup() > lon_debug->slope_offset_compensation())) {
625 brake_cmd = 0.0;
626 is_brake_hold_ = false;
627 ADEBUG << "is_brake_hold_ is false.";
628 }
629 control_command->set_brake(brake_cmd);
630}
631
632bool AntiSlipControlTask::DetectHillStartCondition(
633 ControlCommand *control_command,
634 const planning::ADCTrajectory *planning_published_trajectory,
635 const double &current_speed) {
636 ADEBUG << "in detect hill start condition";
637 auto lon_debug = control_command->mutable_debug()->mutable_simple_lon_debug();
638 ADEBUG << "previous_park_brake_" << previous_park_brake_;
639 ADEBUG << "control_command->parking_brake()" << control_command->parking_brake();
640 ADEBUG << "lon_debug->vehicle_pitch()" << lon_debug->vehicle_pitch();
641 if (((previous_park_brake_ && !control_command->parking_brake()) || from_else_to_auto_)
642 && (lon_debug->vehicle_pitch() > antislip_control_task_conf_.hill_start_pitch_threshold())) {
643 // command means that parking brake will be released,and the car is on a
644 // hill if the follower conditions are true, the car will go into the hill
645 // start condition
646 ADEBUG << "traj size = " << planning_published_trajectory->trajectory_point_size();
647 if (planning_published_trajectory->trajectory_point_size()
648 > antislip_control_task_conf_.min_hill_start_hill_start_trajs()) {
649 // ADEBUG << "size is over";
650 ADEBUG << "v is " << current_speed;
651 ADEBUG << "max speed is " << quit_hill_start_speed_;
652 if (quit_hill_start_speed_ > antislip_control_task_conf_.hill_start_min_speed()
653 && current_speed < antislip_control_task_conf_.hill_start_still_speed()) {
654 ADEBUG << "all is satisfied,in hill start";
655 return true;
656 }
657 }
658 }
659 return false;
660}
661
662bool AntiSlipControlTask::DetectQuitHillStart(ControlCommand *cmd, const double &current_speed) {
663 if ((!in_hill_start_condition_) && (!in_normal_start_condition_)) {
664 ADEBUG << "not in hill start condition ,return";
665 return false;
666 }
667 auto lon_debug = cmd->mutable_debug()->mutable_simple_lon_debug();
668 ADEBUG << "speed error = " << lon_debug->speed_error();
669 ADEBUG << "detect if hill start speed is enough";
670 if (((current_speed) >= quit_hill_start_speed_)
671 || (hill_start_acc_count_ > antislip_control_task_conf_.hill_start_quit_window())
672 || (normal_start_maintain_count_ > antislip_control_task_conf_.normal_start_maintain_window())
673 || (lon_debug->speed_error() < antislip_control_task_conf_.quit_hill_start_v_err())) {
674 return true;
675 } else {
676 ADEBUG << "speed not enough ,stay in hill start";
677 return false;
678 }
679}
680
681void AntiSlipControlTask::FindMaxSpeedInPreviewWindow(const planning::ADCTrajectory *planning_published_trajectory) {
682 ADEBUG << "in find max speed ";
683 int index = 0;
684 preview_length_ = std::min(planning_published_trajectory->trajectory_point_size(), hill_start_window_);
685
686 for (index = 0; index < preview_length_; index++) {
687 quit_hill_start_speed_
688 = std::max(planning_published_trajectory->trajectory_point(index).v(), quit_hill_start_speed_);
689 }
690 // normal_start_tartget_acc_ = quit_hill_start_speed_ / (preview_length_ * 0.1);
691 if (preview_length_ > 50) {
692 normal_start_tartget_acc_ = planning_published_trajectory->trajectory_point(49).v() / (49 * 0.02);
693 } else {
694 normal_start_tartget_acc_
695 = planning_published_trajectory->trajectory_point(preview_length_ - 1).v() / (preview_length_ * 0.02);
696 }
697 ADEBUG << "max speed = " << quit_hill_start_speed_;
698}
699
700void AntiSlipControlTask::FindMinSpeedInPreviewWindow(const planning::ADCTrajectory *planning_published_trajectory) {
701 ADEBUG << "in find min speed ";
702 int index = 0;
703 min_speed_preview_length_ = planning_published_trajectory->trajectory_point_size();
704
705 for (index = 0; index < min_speed_preview_length_; index++) {
706 min_speed_preview_ = std::min(planning_published_trajectory->trajectory_point(index).v(), min_speed_preview_);
707 }
708}
709
710void AntiSlipControlTask::CalculateHillStartACCAndBrakeRate(
711 ControlCommand *control_command,
712 const planning::ADCTrajectory *planning_published_trajectory) {
713 ADEBUG << "cal hill start acc and brake";
714 auto lon_debug = control_command->mutable_debug()->mutable_simple_lon_debug();
715 // window * ts * max_acc * 0.5 = quit_hill_start_speed,
716 double max_real_acc = antislip_control_task_conf_.hill_up_acc_rate() * quit_hill_start_speed_
717 / (hill_start_window_ * 0.5 * antislip_control_task_conf_.ts());
718 ADEBUG << "max_real_acc" << max_real_acc;
719 hill_start_first_acc_ = GRA_ACC * std::sin(std::fabs(lon_debug->vehicle_pitch()) * M_PI / 180)
720 * antislip_control_task_conf_.gravity_hill_start_gain();
721 ADEBUG << "hill_start_first_acc" << hill_start_first_acc_;
722
723 hill_start_acc_gain_rate_ = max_real_acc / hill_start_window_;
724 hill_start_brake_dec_rate_ = antislip_control_task_conf_.epb_brake_cmd()
725 / (antislip_control_task_conf_.hill_start_brake_window()
726 - antislip_control_task_conf_.hill_start_brake_standby_window());
727 ADEBUG << "hill_start_acc_gain_rate" << hill_start_acc_gain_rate_;
728 ADEBUG << "hill_start_brake_dec_rate" << hill_start_brake_dec_rate_;
729}
730
731void AntiSlipControlTask::CalculateNormalStartACC(ControlCommand *control_command) {
732 ADEBUG << "cal normal start acc and brake";
733 auto lon_debug = control_command->mutable_debug()->mutable_simple_lon_debug();
734 hill_start_first_acc_ = GRA_ACC * std::sin(lon_debug->vehicle_pitch() * M_PI / 180)
735 * antislip_control_task_conf_.gravity_hill_start_gain();
736 if (hill_start_first_acc_ < 0) {
737 hill_start_first_acc_ = 0.0;
738 }
739
740 normal_start_acc_gain_rate_ = (normal_start_tartget_acc_ + hill_start_first_acc_)
741 / antislip_control_task_conf_.normal_start_gain_window();
742}
743
744AntiSlipControlTaskConf::VehicleMoveState AntiSlipControlTask::CheckAccGainPoint(
745 double path_remain_threshold,
746 SimpleLongitudinalDebug *lon_debug,
747 const SimpleLongitudinalDebug *lon_debug_previous) {
748 if ((std::fabs(lon_debug_previous->path_remain()) < path_remain_threshold)
749 && (std::fabs(lon_debug->path_remain()) < path_remain_threshold)) {
750 ADEBUG << "[CheckAccGainPoint] Current path remain is " << lon_debug->path_remain();
751 ADEBUG << "[CheckAccGainPoint] CLOSING_DESTNATION";
752 return AntiSlipControlTaskConf::CLOSING_DESTNATION;
753
754 } else if (
755 lon_debug_previous->path_remain() < path_remain_threshold
756 && lon_debug->path_remain() > antislip_control_task_conf_.new_dest_path_remain_threshold()) {
757 vehicle_start_up_ = true;
758 start_path_remian_ = lon_debug->path_remain();
759 } else if (vehicle_start_up_) {
760 if (lon_debug->path_remain() > (start_path_remian_ - path_remain_threshold)
761 && lon_debug->path_remain() < start_path_remian_) {
762 ADEBUG << "[CheckAccGainPoint] Current path remain is " << lon_debug->path_remain();
763 ADEBUG << "[CheckAccGainPoint] MOVING_START_POINT";
764 return AntiSlipControlTaskConf::MOVING_START_POINT;
765 } else {
766 vehicle_start_up_ = false;
767 start_path_remian_ = 0.0;
768 }
769 }
770
771 ADEBUG << "[CheckAccGainPoint] MOVING_DEFAULT_DESTNATION";
772 return AntiSlipControlTaskConf::MOVING_DEFAULT_DESTNATION;
773}
774
775void AntiSlipControlTask::ResetHillStart() {
776 ADEBUG << "reset h start";
777 in_hill_start_condition_ = false;
778 in_normal_start_condition_ = false;
779 hill_start_acc_count_ = 0;
780 hill_start_brake_count_ = 0;
781 previous_hill_start_acc_ = 0.0;
782 previous_hill_start_brake_ = 0.0;
783 hill_start_acc_gain_rate_ = 0.0;
784 hill_start_brake_dec_rate_ = 0.0;
785 hill_start_first_acc_ = 0.0;
786 normal_start_tartget_acc_ = 0.0;
787 normal_start_gain_count_ = 0;
788 normal_start_maintain_count_ = 0;
789 normal_start_acc_gain_rate_ = 0.0;
790 preview_length_ = 0;
791}
792
793void AntiSlipControlTask::ResetDetectObstacleFlags() {
794 unusual_stop_count_ = 0;
795 quit_obstacle_count_ = 0;
796 on_obstacle_ = false;
797 previous_obs_throttle_ = 0;
798 speed_stable_count_ = 0;
799}
800void AntiSlipControlTask::DetectObstacle(
801 ControlCommand *cmd,
802 const canbus::Chassis *chassis,
803 const double &current_speed) {
804 auto lon_debug = cmd->mutable_debug()->mutable_simple_lon_debug();
805
806 // obstacal cant be activated when hill start or normal start
807 if (in_hill_start_condition_ || in_normal_start_condition_
808 || chassis->gear_location() == canbus::Chassis::GEAR_REVERSE) {
809 ADEBUG << "[obstacle] in hill start condition or in reverse gear ,return";
810 ResetDetectObstacleFlags();
811 return;
812 }
813
814 ADEBUG << "[obstacle] in detect obstacle";
815 // v > threshold, or acc > threshold,
816 // or full stop, or brake > 0, than quit
817 ADEBUG << "[obstacle] on obstacle,detect whether to quit or not";
818 if (lon_debug->is_full_stop() || lon_debug->is_full_stop_soft()
819 || quit_hill_start_speed_ < antislip_control_task_conf_.obstacle_speed_safety_threshold()
820 || cmd->brake() > antislip_control_task_conf_.obstacle_brake_cmd_threshold()) {
821 ADEBUG << "[obstacle] quit obstacle,safety check reason";
822 ResetDetectObstacleFlags();
823 return;
824 }
825 if (quit_obstacle_count_ > antislip_control_task_conf_.quit_opbstacle_window()) {
826 ADEBUG << "[obstacle] quit obstacle";
827 ResetDetectObstacleFlags();
828 ADEBUG << "[obstacle] print quit reason:max window satisfied";
829 return;
830 }
831
832 if (current_speed > antislip_control_task_conf_.quit_opbstacle_safety_high_speed()) {
833 ADEBUG << "[obstacle] over high speed, quit obstacle at once";
834 ResetDetectObstacleFlags();
835 return;
836 }
837
838 if (current_speed > antislip_control_task_conf_.speed_stable()) {
839 ADEBUG << "[obstacle] over stable speed, count = " << speed_stable_count_;
840 speed_stable_count_++;
841 } else {
842 ADEBUG << "[obstacle] speed jump back to 0 ";
843 speed_stable_count_ = 0;
844 }
845
846 if (speed_stable_count_ > antislip_control_task_conf_.speed_stable_window()) {
847 ADEBUG << "[obstacle] speed is stable,quit";
848 ResetDetectObstacleFlags();
849 }
850
851 if (chassis->throttle_percentage() > antislip_control_task_conf_.obstacle_throttle_cmd_threshold()
852 && current_speed < antislip_control_task_conf_.obstacle_speed_safety_threshold()
853 && injector_->vehicle_state()->linear_acceleration() < antislip_control_task_conf_.obstacle_acc_threshold()
854 && !lon_debug->is_full_stop() && !lon_debug->is_full_stop_soft()
855 && quit_hill_start_speed_ > antislip_control_task_conf_.in_obstacle_preview_speed()
856 && (lon_debug->path_remain() >= antislip_control_task_conf_.cncl_brake_max_path())
857 && (chassis->gear_location() == canbus::Chassis::GEAR_DRIVE)) {
858 ADEBUG << "[obstacle] meet obstacle,count + " << unusual_stop_count_;
859 unusual_stop_count_++;
860 }
861
862 if (unusual_stop_count_ >= antislip_control_task_conf_.obstacle_stop_window_threshold() && !on_obstacle_) {
863 ADEBUG << "[obstacle]=========== =AL= =======begin overcomingggg obstacle ";
864 on_obstacle_ = true;
865 previous_obs_throttle_ = cmd->throttle() + antislip_control_task_conf_.obs_throttle_add_default();
866 min_throttle_count_ = 0;
867 speed_stable_count_ = 0;
868 }
869}
870
872
874 previous_is_auto_ = false;
875 in_hill_start_condition_ = false;
876 in_normal_start_condition_ = false;
877 hill_start_acc_count_ = 0;
878 hill_start_brake_count_ = 0;
879 previous_hill_start_acc_ = 0.0;
880 previous_hill_start_brake_ = 0.0;
881 hill_start_acc_gain_rate_ = 0.0;
882 hill_start_brake_dec_rate_ = 0.0;
883 quit_hill_start_speed_ = 0.0;
884 hill_start_first_acc_ = 0.0;
885 normal_start_tartget_acc_ = 0.0;
886 normal_start_gain_count_ = 0;
887 normal_start_maintain_count_ = 0;
888 normal_start_acc_gain_rate_ = 0.0;
889 preview_length_ = 0;
890 slope_start_acc_ = 0.0;
891 return Status::OK();
892}
893
894std::string AntiSlipControlTask::Name() const {
895 return name_;
896}
897
898} // namespace control
899} // namespace apollo
Defines the AntiSlipControlTask class.
The DigitalFilter class is used to pass signals with a frequency lower than a certain cutoff frequenc...
void set_coefficients(const std::vector< double > &denominators, const std::vector< double > &numerators)
set denominators and numerators
A general class to denote the return status of an API call.
Definition status.h:43
static Status OK()
generate a success status.
Definition status.h:60
common::Status Reset() override
reset demo control task
common::Status Init(std::shared_ptr< DependencyInjector > injector) override
initialize AntiSlipControlTask
std::shared_ptr< DependencyInjector > injector_
void Stop() override
stop AntislipControlTask
common::Status ComputeControlCommand(const localization::LocalizationEstimate *localization, const canbus::Chassis *chassis, const planning::ADCTrajectory *trajectory, control::ControlCommand *cmd) override
compute brake / throttle values based on current vehicle status and target trajectory
std::string Name() const override
AntiSlipControlTask name
bool LoadParams(ParamsPipeline *params_pipeline)
double ThrottleCmdFilter(const bool &use_filter, const double &filter_coeff, const double &throttle)
double GetVehicleSpeed(std::shared_ptr< DependencyInjector > injector, const bool &use_filter, const double &filter_coeff)
bool LoadCalibrationTable(calibration_table *calibration_table_conf)
std::vector< std::tuple< double, double, double > > DataType
std::string GetPluginConfPath(const std::string &class_name, const std::string &conf_name)
get plugin configuration file location
static PluginManager * Instance()
get singleton instance of PluginManager
#define ACHECK(cond)
Definition log.h:80
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
void LpfCoefficients(const double ts, const double cutoff_freq, std::vector< double > *denominators, std::vector< double > *numerators)
Get low-pass coefficients for digital filter.
constexpr double GRA_ACC
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132
class register implement
Definition arena_queue.h:37
optional GearPosition gear_location
optional DrivingMode driving_mode
optional float speed_mps
Definition chassis.proto:70
optional bool parking_brake
Definition chassis.proto:94
optional TrajectoryType trajectory_type
optional apollo::canbus::Chassis::GearPosition gear