308 {
309 auto vehicle_state =
injector_->vehicle_state();
310 auto previous_lon_debug =
injector_->Get_previous_lon_debug_info();
311 auto target_tracking_trajectory = *planning_published_trajectory;
312
313 if (FLAGS_use_navigation_mode &&
315 auto time_stamp_diff =
316 planning_published_trajectory->header().timestamp_sec() -
318
319 auto curr_vehicle_x = localization->pose().position().x();
320 auto curr_vehicle_y = localization->pose().position().y();
321
322 double curr_vehicle_heading = 0.0;
323 const auto &orientation = localization->pose().orientation();
324 if (localization->pose().has_heading()) {
325 curr_vehicle_heading = localization->pose().heading();
326 } else {
327 curr_vehicle_heading =
329 orientation.qy(), orientation.qz());
330 }
331
332
333 if (time_stamp_diff > 1.0e-6) {
337
339 planning_published_trajectory->header().timestamp_sec();
340 } else {
344
347
348 auto x_diff_veh = cos_map_veh * x_diff_map + sin_map_veh * y_diff_map;
349 auto y_diff_veh = -sin_map_veh * x_diff_map + cos_map_veh * y_diff_map;
350
351 auto cos_theta_diff = std::cos(-theta_diff);
352 auto sin_theta_diff = std::sin(-theta_diff);
353
354 auto tx = -(cos_theta_diff * x_diff_veh - sin_theta_diff * y_diff_veh);
355 auto ty = -(sin_theta_diff * x_diff_veh + cos_theta_diff * y_diff_veh);
356
357 auto ptr_trajectory_points =
358 target_tracking_trajectory.mutable_trajectory_point();
359 std::for_each(
360 ptr_trajectory_points->begin(), ptr_trajectory_points->end(),
361 [&cos_theta_diff, &sin_theta_diff, &tx, &ty,
362 &theta_diff](common::TrajectoryPoint &p) {
363 auto x = p.path_point().x();
364 auto y = p.path_point().y();
365 auto theta = p.path_point().theta();
366
367 auto x_new = cos_theta_diff * x - sin_theta_diff * y + tx;
368 auto y_new = sin_theta_diff * x + cos_theta_diff * y + ty;
369 auto theta_new = common::math::NormalizeAngle(theta - theta_diff);
370
371 p.mutable_path_point()->set_x(x_new);
372 p.mutable_path_point()->set_y(y_new);
373 p.mutable_path_point()->set_theta(theta_new);
374 });
375 }
376 }
377
379 std::move(TrajectoryAnalyzer(&target_tracking_trajectory));
380
381
382
389 }
390
391
392
393
395
396
397
398
399
400
401
402
403
408 } else {
409
410
411
412
413
414
415
416
417
422 }
429
430
431
432
436
438
439 SimpleLateralDebug *debug = cmd->mutable_debug()->mutable_simple_lat_debug();
440 debug->Clear();
441
442
443
445
447
448
450
451
453 int reverse_q_param_size =
456 for (int i = 0; i < reverse_q_param_size; ++i) {
458 }
459 } else {
460 for (int i = 0; i < q_param_size; ++i) {
462 }
463 }
464
465 uint num_iteration;
466 double result_diff;
467
468 if (FLAGS_enable_gain_scheduler) {
471 std::fabs(vehicle_state->linear_velocity()));
474 std::fabs(vehicle_state->linear_velocity()));
477 &
matrix_k_, &num_iteration, &result_diff);
478 } else {
481 &
matrix_k_, &num_iteration, &result_diff);
482 }
483
484 ADEBUG <<
"LQR num_iteration is " << num_iteration
486 << "; result_diff is " << result_diff;
487
488
489
490
494
496
497 double steer_angle = 0.0;
498 double steer_angle_feedback_augment = 0.0;
499
502 .enable_feedback_augment_on_high_speed() ||
504 steer_angle_feedback_augment =
507 if (std::fabs(vehicle_state->linear_velocity()) >
509
510
514 }
515 }
516 }
517 steer_angle = steer_angle_feedback + steer_angle_feedforward +
518 steer_angle_feedback_augment;
519
520
521
522 const double steer_limit =
524 (vehicle_state->linear_velocity() *
525 vehicle_state->linear_velocity())) *
528 : 100.0;
529
530 const double steer_diff_with_max_rate =
534 : 100.0;
535
536 const double steering_position = chassis->steering_percentage();
537
538
539
541 const int mrac_model_order =
543 Matrix steer_state = Matrix::Zero(mrac_model_order, 1);
544 steer_state(0, 0) = chassis->steering_percentage();
545 if (mrac_model_order > 1) {
547 }
548 if (std::fabs(vehicle_state->linear_velocity()) >
549 FLAGS_minimum_speed_resolution) {
552 } else {
555 }
557 steer_angle, steer_state, steer_limit, steer_diff_with_max_rate /
ts_);
558
559 MracDebug *mracdebug = debug->mutable_steer_mrac_debug();
561 mracdebug->set_mrac_model_order(mrac_model_order);
562 for (int i = 0; i < mrac_model_order; ++i) {
563 mracdebug->add_mrac_reference_state(steer_reference(i, 0));
564 mracdebug->add_mrac_state_error(steer_state(i, 0) -
565 steer_reference(i, 0));
566 mracdebug->mutable_mrac_adaptive_gain()->add_state_adaptive_gain(
568 }
569 mracdebug->mutable_mrac_adaptive_gain()->add_input_adaptive_gain(
571 mracdebug->set_mrac_reference_saturation_status(
573 mracdebug->set_mrac_control_saturation_status(
575 }
578
579
580 double steer_angle_limited =
582 steer_angle = steer_angle_limited;
583 debug->set_steer_angle_limited(steer_angle_limited);
584
585
588
589
590
592 if ((std::abs(vehicle_state->linear_velocity()) <
594 previous_lon_debug->path_remain() <= 0) &&
597 ADEBUG <<
"Into lock steer, path_remain is "
598 << previous_lon_debug->path_remain() << "linear_velocity is "
599 << vehicle_state->linear_velocity();
601 }
602 }
603
604
608 cmd->set_steering_rate(FLAGS_steer_angle_rate);
609
611
612
613 const double steer_angle_lateral_contribution =
616
617 const double steer_angle_lateral_rate_contribution =
620
621 const double steer_angle_heading_contribution =
624
625 const double steer_angle_heading_rate_contribution =
628
630 debug->set_steer_angle(steer_angle);
631 debug->set_steer_angle_feedforward(steer_angle_feedforward);
632 debug->set_steer_angle_lateral_contribution(steer_angle_lateral_contribution);
633 debug->set_steer_angle_lateral_rate_contribution(
634 steer_angle_lateral_rate_contribution);
635 debug->set_steer_angle_heading_contribution(steer_angle_heading_contribution);
636 debug->set_steer_angle_heading_rate_contribution(
637 steer_angle_heading_rate_contribution);
638 debug->set_steer_angle_feedback(steer_angle_feedback);
639 debug->set_steer_angle_feedback_augment(steer_angle_feedback_augment);
640 debug->set_steering_position(steering_position);
641 debug->set_ref_speed(vehicle_state->linear_velocity());
642
645}
double Filter(const double x_insert)
Processes a new measurement with the filter.
static Status OK()
generate a success status.
Eigen::MatrixXd matrix_a_coeff_
void UpdateMatrixCompound()
double current_trajectory_timestamp_
Eigen::MatrixXd matrix_bdc_
double ComputeFeedForward(double ref_curvature) const
MracController mrac_controller_
TrajectoryAnalyzer trajectory_analyzer_
void UpdateState(SimpleLateralDebug *debug, const canbus::Chassis *chassis)
Eigen::MatrixXd matrix_adc_
double pre_steering_position_
Eigen::MatrixXd matrix_a_
void ProcessLogs(const SimpleLateralDebug *debug, const canbus::Chassis *chassis)
Eigen::MatrixXd matrix_b_
Eigen::MatrixXd matrix_k_
void UpdateDrivingOrientation()
Eigen::MatrixXd matrix_q_
double steer_single_direction_max_degree_
double driving_orientation_
common::DigitalFilter digital_filter_
LatBaseLqrControllerConf lat_based_lqr_controller_conf_
bool enable_look_ahead_back_control_
std::unique_ptr< Interpolation1D > heading_err_interpolation_
Eigen::MatrixXd matrix_state_
std::shared_ptr< DependencyInjector > injector_
Eigen::MatrixXd matrix_q_updated_
LeadlagController leadlag_controller_
std::unique_ptr< Interpolation1D > lat_err_interpolation_
double init_vehicle_heading_
common::VehicleParam vehicle_param_
Eigen::MatrixXd matrix_r_
Eigen::MatrixXd matrix_bd_
virtual double Control(const double error, const double dt)
compute control value based on the error
void SetInputAdaptionRate(const double ratio_input)
set convergence ratio for input components in adaptive dynamics
Eigen::MatrixXd CurrentInputAdaptionGain() const
get current input adaptive gain for mrac control
virtual double Control(const double command, const Eigen::MatrixXd state, const double input_limit, const double input_rate_limit)
compute control value based on the original command
int ReferenceSaturationStatus() const
get saturation status for reference system
int ControlSaturationStatus() const
get saturation status for control system
void SetStateAdaptionRate(const double ratio_state)
set convergence ratio for state components in adaptive dynamics
Eigen::MatrixXd CurrentReferenceState() const
get current state for reference system
Eigen::MatrixXd CurrentStateAdaptionGain() const
get current state adaptive gain for mrac control
void TrajectoryTransformToCOM(const double rear_to_com_distance)
Transform the current trajectory points to the center of mass(COM) of the vehicle,...
T lerp(const T &x0, const double t0, const T &x1, const double t1, const double t)
Linear interpolation between two points of type T.
void SolveLQRProblem(const Matrix &A, const Matrix &B, const Matrix &Q, const Matrix &R, const Matrix &M, const double tolerance, const uint max_num_iteration, Matrix *ptr_K, uint *iterate_num, double *result_diff)
T Clamp(const T value, T bound1, T bound2)
Clamp a value between two bounds.
double QuaternionToHeading(const double qw, const double qx, const double qy, const double qz)
optional double max_steer_angle_rate