compute brake / throttle values based on current vehicle status and target trajectory
131 {
132 trajectory_message_ = planning_published_trajectory;
134
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
150
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!!!";
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
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();
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();
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
205
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
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
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
242 : acceleration_cmd;
243 anti_slip_debug_info->set_anti_acc_lookup(acceleration_lookup);
244
245
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
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
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
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
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_)
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())
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_) {
426
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 }
450 brake_cmd = antislip_control_task_conf_.epb_brake_cmd();
451 }
452 }
453
454 if (in_normal_start_condition_) {
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
523
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
547
548
549
550
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
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
582}
static Status OK()
generate a success status.
std::shared_ptr< DependencyInjector > injector_
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)
optional double throttle_deadzone
optional double brake_deadzone
optional apollo::canbus::Chassis::GearPosition gear