132 trajectory_message_ = planning_published_trajectory;
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!");
143 uphill_too_fast_ =
false;
144 only_use_brk_downhill_ =
false;
145 erase_brk_in_go_ =
false;
146 erase_brk_in_end_ =
false;
151 auto anti_slip_debug_info =
injector_->mutable_control_debug_info()->mutable_simple_anti_slope_debug();
152 anti_slip_debug_info->Clear();
154 from_else_to_auto_ =
true;
155 ADEBUG <<
"From else to auto!!!";
157 from_else_to_auto_ =
false;
160 && gear_drive_count_ > antislip_control_task_conf_.gear_drive_count_num()) {
161 previous_is_auto_ =
true;
163 previous_is_auto_ =
false;
167 gear_drive_count_ = 0;
168 previous_is_auto_ =
false;
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();
177 double brake_cmd = cmd->
brake();
179 if (brake_lowerbound <= antislip_control_task_conf_.brake_minimum_action()) {
180 brake_lowerbound = antislip_control_task_conf_.brake_minimum_action();
182 double calibration_value = 0.0;
184 double max_path_remain_when_stopped
185 = FLAGS_max_path_remain_when_stopped + antislip_control_task_conf_.path_remain_threshold();
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;
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.";
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();
213 uphill_too_fast_ =
true;
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();
221 uphill_too_fast_ =
true;
223 if (std::isnan(slope_offset_compensation)) {
224 slope_offset_compensation = 0;
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 "
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;
243 anti_slip_debug_info->set_anti_acc_lookup(acceleration_lookup);
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";
254 throttle_cmd = throttle_lowerbound;
255 anti_stage_ =
"acc lookup > 0 ,cali < 0, stage2";
258 previous_downhill_go_brk_ = 0.0;
259 pre_cali_down_hill_ = 0.0;
263 if (calibration_value >= 0) {
264 brake_cmd = brake_lowerbound;
266 previous_downhill_go_brk_ = 0.0;
267 pre_cali_down_hill_ = 0.0;
268 anti_stage_ =
"acc lookup < 0 and cali > 0, stage3";
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);
276 if (reverse_flag == 1 && (vehicle_pitch < 0)) {
301 if (std::fabs(current_speed) < antislip_control_task_conf_.maintain_min_speed()) {
303 anti_stage_ =
"acc lookup < 0 and cali < 0, stage4";
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();
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();
319 if (brake_cmd == 0.0) {
321 = pre_cali_down_hill_ * antislip_control_task_conf_.downhill_brake_rate();
323 pre_cali_down_hill_ = brake_cmd;
346 if (brake_cmd <= 0) {
347 anti_stage_ =
"brk < 0, set brk 0 stage5";
350 ADEBUG <<
"usr brk to go,cmd = " << brake_cmd <<
"calibration_value = " << calibration_value;
351 ADEBUG <<
"acceleration_lookup = " << acceleration_lookup;
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_)
361 erase_brk_in_go_ =
true;
365 if ((vehicle_pitch <= antislip_control_task_conf_.uphill_start_pitch())
366 && (vehicle_pitch >= antislip_control_task_conf_.normal_start_pitch())
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();
380 erase_brk_in_end_ =
true;
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();
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);
406 if (FLAGS_use_vehicle_epb) {
407 UseVehicleEpb(chassis, cmd);
408 ADEBUG <<
"[anti-slip stop in condition]: Into vehicle epb, parking "
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 "
415 lon_debug->set_is_epb_brake(
true);
416 ADEBUG <<
"anti slip brake triggered in slope: " << lon_debug->is_epb_brake();
418 lon_debug->set_is_epb_brake(
false);
419 ADEBUG <<
"[anti-slip stop out condition]: anti slip brake is not "
420 "triggered in slope.";
424 if (in_hill_start_condition_) {
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";
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);
437 if (hill_start_brake_count_ >= antislip_control_task_conf_.hill_start_brake_window()) {
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;
444 brake_cmd = antislip_control_task_conf_.epb_brake_cmd();
446 hill_start_acc_count_++;
447 hill_start_brake_count_++;
450 brake_cmd = antislip_control_task_conf_.epb_brake_cmd();
454 if (in_normal_start_condition_) {
457 if (normal_start_gain_count_ >= antislip_control_task_conf_.normal_start_gain_window()) {
458 normal_start_acc_gain_rate_ = 0.0;
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;
464 if (slope_start_acc_ >= normal_start_tartget_acc_) {
465 slope_start_acc_ = normal_start_tartget_acc_;
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_++;
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;
496 slope_start_acc_ = 0.0;
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()) {
504 =
ThrottleCmdFilter(FLAGS_use_throttle_filter, FLAGS_throttle_smoothing_factor, throttle_cmd);
505 cmd->set_throttle(throttle_cmd);
506 cmd->set_brake(brake_cmd);
508 previous_is_auto_ =
false;
513 ADEBUG <<
"Not into anti-slip stop process because out of enable threshold: "
514 << antislip_control_task_conf_.slope_offset_threhold();
516 DetectObstacle(cmd, chassis, current_speed);
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()) {
524 if (previous_obs_throttle_ > 99.0) {
525 previous_obs_throttle_ = 99.0;
527 cmd->set_throttle(previous_obs_throttle_);
534 brake_cmd = antislip_control_task_conf_.epb_brake_cmd();
536 cmd->set_throttle(throttle_cmd);
537 cmd->set_brake(brake_cmd);
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())) {
551 control_interactive_info->set_is_need_safety_check(
false);
553 control_interactive_info->set_is_need_safety_check(
true);
556 control_interactive_info->set_is_need_safety_check(
true);
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_);