25#include "absl/strings/str_cat.h"
45using Matrix = Eigen::MatrixXd;
50std::string GetLogFileName() {
55 localtime_r(&raw_time, &time_tm);
56 strftime(name_buffer, 80,
"/tmp/steer_log_simple_optimal_%F_%H%M%S.csv", &time_tm);
57 return std::string(name_buffer);
60void WriteHeaders(std::ofstream &file_stream) {
61 file_stream <<
"current_lateral_error," <<
"current_ref_heading," <<
"current_heading," <<
"current_heading_error,"
62 <<
"heading_error_rate," <<
"lateral_error_rate," <<
"current_curvature," <<
"steer_angle,"
63 <<
"steer_angle_feedforward," <<
"steer_angle_lateral_contribution,"
64 <<
"steer_angle_lateral_rate_contribution," <<
"steer_angle_heading_contribution,"
65 <<
"steer_angle_heading_rate_contribution," <<
"steer_angle_feedback," <<
"steering_position," <<
"v"
71 if (FLAGS_enable_csv_debug) {
85 const LatBaseLqrPlusControllerConf ¤t_lat_based_lqr_plus_controller_conf) {
86 vehicle_param_ = common::VehicleConfigHelper::Instance()->GetConfig().vehicle_param();
88 ts_ = current_lat_based_lqr_plus_controller_conf.ts();
90 AERROR <<
"[LatPlusController] Invalid control update interval.";
93 preview_window_ = current_lat_based_lqr_plus_controller_conf.preview_window();
98 AHC_container_.resize(current_lat_based_lqr_plus_controller_conf.ahc_container_size());
106 matrix_adc_ = Matrix::Zero(matrix_size, matrix_size);
118 matrix_k_ = Matrix::Zero(1, matrix_size);
120 matrix_q_ = Matrix::Zero(matrix_size, matrix_size);
126 const LatBaseLqrPlusControllerConf ¤t_lat_based_lqr_plus_controller_conf) {
127 cf_ = current_lat_based_lqr_plus_controller_conf.cf();
128 cr_ = current_lat_based_lqr_plus_controller_conf.cr();
129 preview_window_ = current_lat_based_lqr_plus_controller_conf.preview_window();
134 max_lat_acc_ = current_lat_based_lqr_plus_controller_conf.max_lateral_acceleration();
135 low_speed_bound_ = current_lat_based_lqr_plus_controller_conf.switch_speed();
136 low_speed_window_ = current_lat_based_lqr_plus_controller_conf.switch_speed_window();
138 const double mass_fl = current_lat_based_lqr_plus_controller_conf.mass_fl();
139 const double mass_fr = current_lat_based_lqr_plus_controller_conf.mass_fr();
140 const double mass_rl = current_lat_based_lqr_plus_controller_conf.mass_rl();
141 const double mass_rr = current_lat_based_lqr_plus_controller_conf.mass_rr();
142 const double mass_front = mass_fl + mass_fr;
143 const double mass_rear = mass_rl + mass_rr;
144 mass_ = mass_front + mass_rear;
152 lqr_eps_ = current_lat_based_lqr_plus_controller_conf.eps();
188 int q_param_size = current_lat_based_lqr_plus_controller_conf.matrix_q_size();
189 if (matrix_size != q_param_size) {
190 const auto error_msg = absl::StrCat(
191 "lateral controller error: matrix_q size: ",
193 " in parameter file not equal to matrix_size: ",
199 for (
int i = 0; i < q_param_size; ++i) {
200 matrix_q_(i, i) = current_lat_based_lqr_plus_controller_conf.matrix_q(i);
204 enable_leadlag_ = current_lat_based_lqr_plus_controller_conf.enable_reverse_leadlag_compensation();
217 const std::string log_str = absl::StrCat(
248 injector_->vehicle_state()->linear_velocity());
249 if (FLAGS_enable_csv_debug) {
252 ADEBUG <<
"Steer_Control_Detail: " << log_str;
257 AINFO <<
"Update the vehicle mass.";
258 AINFO <<
"[LatPlusController parameters]" <<
" mass_: " <<
mass_ <<
"," <<
" iz_: " <<
iz_ <<
","
259 <<
" lf_: " <<
lf_ <<
"," <<
" lr_: " <<
lr_;
266 std::vector<double> den(3, 0.0);
267 std::vector<double> num(3, 0.0);
278 AERROR <<
"failed to load control conf in init.";
279 return Status(ErrorCode::CONTROL_INIT_ERROR,
"failed to load lat control_conf init");
283 AERROR <<
"failed to load control conf in init.";
284 return Status(ErrorCode::CONTROL_INIT_ERROR,
"failed to load control_conf init");
288 AERROR <<
"failed to update control conf in init.";
289 return Status(ErrorCode::CONTROL_INIT_ERROR,
"failed to update control_conf init");
292 if (!ControlTaskExtend::LoadParamsPipelineConfig<ParamsPipeline>(&
params_pipeline_)) {
293 AERROR <<
"failed to load lon pid params pipeline config in init.";
294 return Status(ErrorCode::CONTROL_INIT_ERROR,
"failed to load lon pid params pipeline config");
298 AERROR <<
"failed to load lat lqr controller params.";
299 return Status(ErrorCode::CONTROL_INIT_ERROR,
"failed to load lon pid params pipeline config");
319 AINFO <<
"Into the lat load params.";
320 for (
int i = 0; i < params_pipeline->params_declare_size(); i++) {
321 LatBaseLqrPlusControllerConf param_config;
322 auto param_config_path = params_pipeline->params_declare(i).config_path();
323 std::string param_config_path_relative = absl::StrCat(
"conf",
"/", param_config_path);
324 AINFO <<
"Param config_path_relative is " << param_config_path_relative;
325 std::string param_config_path_absolute
327 "apollo::control::LatPlusController", param_config_path_relative);
328 AINFO <<
"Param config_path_absolute is " << param_config_path_absolute;
330 AERROR <<
"Load config: " << params_pipeline->params_declare(i).config_name() <<
" param failed!";
333 AINFO <<
"Load the lat config file successfully, file path: " << param_config_path;
334 params_list_.push_back(std::make_pair(params_pipeline->params_declare(i).config_name(), param_config));
346 const std::string param_config_name,
347 LatBaseLqrPlusControllerConf ¤t_lat_based_lqr_plus_controller_conf) {
348 bool set_success =
false;
350 if (param.first == param_config_name) {
351 current_lat_based_lqr_plus_controller_conf.CopyFrom(param.second);
357 AERROR <<
"Fail to find lat current param[" << param_config_name <<
"]";
363 LatBaseLqrPlusControllerConf ¤t_lat_based_lqr_plus_controller_conf,
365 std::string param_config_name =
"public_road_forward_param";
368 param_config_name =
"public_road_backward_param";
376 param_config_name =
"public_road_forward_s_turn_param";
381 param_config_name =
"open_space_forward_param";
383 param_config_name =
"open_space_backward_param";
392 param_config_name =
"edge_follow_public_road_forward_param";
395 param_config_name =
"edge_follow_public_road_forward_sl_turn_param";
397 param_config_name =
"edge_follow_public_road_forward_sr_turn_param";
404 param_config_name =
"zone_cover_backward_param";
406 param_config_name =
"zone_cover_forward_param";
410 if (!
SetCurrentParam(param_config_name, current_lat_based_lqr_plus_controller_conf)) {
411 AERROR <<
"Failed to set current lat param config: " << param_config_name;
415 AINFO <<
"Update the current lat param config name is " << param_config_name;
438 AERROR <<
"Fail to update the vehicle status identification!";
439 return Status(ErrorCode::CONTROL_COMPUTE_ERROR,
"Fail to update the vehicle status identification!");
443 AERROR <<
"Fail to load the current lon control param!";
444 return Status(ErrorCode::CONTROL_COMPUTE_ERROR,
"Fail to load the current lon control param!");
448 AERROR <<
"failed to load control conf";
449 return Status(ErrorCode::CONTROL_COMPUTE_ERROR,
"failed to load control_conf");
456 auto vehicle_state =
injector_->vehicle_state();
457 auto previous_lon_debug =
injector_->Get_previous_lon_debug_info();
458 auto target_tracking_trajectory = *planning_published_trajectory;
460 if (FLAGS_use_navigation_mode
467 double curr_vehicle_heading = 0.0;
469 if (localization->
pose().has_heading()) {
470 curr_vehicle_heading = localization->
pose().
heading();
473 orientation.qw(), orientation.qx(), orientation.qy(), orientation.qz());
477 if (time_stamp_diff > 1.0e-6) {
491 auto x_diff_veh = cos_map_veh * x_diff_map + sin_map_veh * y_diff_map;
492 auto y_diff_veh = -sin_map_veh * x_diff_map + cos_map_veh * y_diff_map;
494 auto cos_theta_diff = std::cos(-theta_diff);
495 auto sin_theta_diff = std::sin(-theta_diff);
497 auto tx = -(cos_theta_diff * x_diff_veh - sin_theta_diff * y_diff_veh);
498 auto ty = -(sin_theta_diff * x_diff_veh + cos_theta_diff * y_diff_veh);
500 auto ptr_trajectory_points = target_tracking_trajectory.mutable_trajectory_point();
502 ptr_trajectory_points->begin(),
503 ptr_trajectory_points->end(),
505 auto x = p.path_point().x();
506 auto y = p.path_point().y();
507 auto theta = p.path_point().theta();
509 auto x_new = cos_theta_diff * x - sin_theta_diff * y + tx;
510 auto y_new = sin_theta_diff * x + cos_theta_diff * y + ty;
511 auto theta_new = common::math::NormalizeAngle(theta - theta_diff);
513 p.mutable_path_point()->set_x(x_new);
514 p.mutable_path_point()->set_y(y_new);
515 p.mutable_path_point()->set_theta(theta_new);
580 auto lat_debug_info =
injector_->mutable_control_debug_info()->mutable_simple_lat_debug();
581 lat_debug_info->Clear();
594 for (
int i = 0; i < q_param_size; ++i) {
598 if (
enable_enhance_qparam_ && (!previous_lon_debug->is_full_stop()) && (!previous_lon_debug->is_full_stop_soft())) {
600 lat_debug_info->lateral_error_match_local(),
601 lat_debug_info->heading_error_match_local(),
602 planning_published_trajectory,
611 if (FLAGS_enable_gain_scheduler) {
612 double curvature = std::fabs(debug->
curvature());
613 double speed = std::fabs(vehicle_state->linear_velocity());
657 ADEBUG <<
"current vehicle is " << speed <<
", curvature is " << curvature;
687 <<
"; result_diff is " << result_diff;
689 lat_debug_info->set_lqr_iteration_num(num_iteration);
690 lat_debug_info->set_lqr_result_diff(result_diff);
695 const double steer_angle_feedback
698 double curvature = 0.0;
702 curvature = lat_debug_info->lookback_curvature_new();
704 curvature = lat_debug_info->lookahead_curvature_new();
707 curvature = lat_debug_info->lookahead_curvature();
715 double steer_angle = 0.0;
716 double steer_angle_feedback_augment = 0.0;
727 steer_angle_feedback_augment,
731 std::fabs(vehicle_state->linear_velocity()));
735 steer_angle = steer_angle_feedback + steer_angle_feedforward + steer_angle_feedback_augment;
739 const double steer_limit = FLAGS_set_steer_limit
745 const double steer_diff_with_max_rate
756 Matrix steer_state = Matrix::Zero(mrac_model_order, 1);
758 if (mrac_model_order > 1) {
761 if (std::fabs(vehicle_state->linear_velocity()) > FLAGS_minimum_speed_resolution) {
770 MracDebug *mracdebug = debug->mutable_steer_mrac_debug();
772 mracdebug->set_mrac_model_order(mrac_model_order);
773 for (
int i = 0; i < mrac_model_order; ++i) {
774 mracdebug->add_mrac_reference_state(steer_reference(i, 0));
775 mracdebug->add_mrac_state_error(steer_state(i, 0) - steer_reference(i, 0));
776 mracdebug->mutable_mrac_adaptive_gain()->add_state_adaptive_gain(
779 mracdebug->mutable_mrac_adaptive_gain()->add_input_adaptive_gain(
789 steer_angle = steer_angle_limited;
790 debug->set_steer_angle_limited(steer_angle_limited);
799 || previous_lon_debug->path_remain() <= 0)
802 ADEBUG <<
"Into lock steer, path_remain is " << previous_lon_debug->path_remain() <<
"linear_velocity is "
803 << vehicle_state->linear_velocity();
804 lat_debug_info->set_is_lock_steer(
true);
807 lat_debug_info->set_is_lock_steer(
false);
814 cmd->set_steering_rate(FLAGS_steer_angle_rate);
832 debug->set_steer_angle(steer_angle);
833 debug->set_steer_angle_feedforward(steer_angle_feedforward);
834 debug->set_steer_angle_lateral_contribution(steer_angle_lateral_contribution);
835 debug->set_steer_angle_lateral_rate_contribution(steer_angle_lateral_rate_contribution);
836 debug->set_steer_angle_heading_contribution(steer_angle_heading_contribution);
837 debug->set_steer_angle_heading_rate_contribution(steer_angle_heading_rate_contribution);
838 debug->set_steer_angle_feedback(steer_angle_feedback);
839 debug->set_steer_angle_feedback_augment(steer_angle_feedback_augment);
840 debug->set_steering_position(steering_position);
841 debug->set_ref_speed(vehicle_state->linear_velocity());
844 lat_debug_info->set_ed_rate(
ed_date_);
874 auto vehicle_state =
injector_->vehicle_state();
875 if (FLAGS_use_navigation_mode) {
880 vehicle_state->linear_velocity(),
881 vehicle_state->angular_velocity(),
882 vehicle_state->linear_acceleration(),
891 double com_length = 0.0;
926 debug_info->set_com_length(com_length);
927 const auto &com = vehicle_state->ComputeCOMPosition(com_length);
928 debug_info->mutable_lat_com_position()->set_x(com.x());
929 debug_info->mutable_lat_com_position()->set_y(com.y());
934 vehicle_state->linear_velocity(),
935 vehicle_state->angular_velocity(),
936 vehicle_state->linear_acceleration(),
962 const double preview_time =
ts_ * (i + 1);
966 preview_point.path_point().x(), preview_point.path_point().y());
968 const double dx = preview_point.
path_point().
x() - matched_point.path_point().x();
969 const double dy = preview_point.path_point().y() - matched_point.path_point().y();
971 const double cos_matched_theta = std::cos(matched_point.path_point().theta());
972 const double sin_matched_theta = std::sin(matched_point.path_point().theta());
973 const double preview_d_error = cos_matched_theta * dy - sin_matched_theta * dx;
978 const auto &track_com
980 debug_info->mutable_lat_track_com_position()->set_x(track_com.x());
981 debug_info->mutable_lat_track_com_position()->set_y(track_com.y());
988 vehicle_state->linear_velocity(),
990 control::ChooseRefTrajectoryPoint::USE_LAT_MATCH_LOCAL,
997 vehicle_state->linear_velocity(),
1011 ADEBUG <<
"Current vehicle is left of trajectory";
1033 ADEBUG <<
"Current vehicle is right of trajectory";
1075 AINFO <<
"Into turbulence condition";
1080 ADEBUG <<
"Quit turbulence condition";
1095 auto vehicle_state =
injector_->vehicle_state();
1111 ADEBUG <<
"Into ResetComLengthFromTurbulence";
1112 auto vehicle_state =
injector_->vehicle_state();
1121 const uint8_t window_size,
1123 const double threshold,
1124 std::vector<double> *arr,
1125 int32_t *current_sign) {
1126 arr->push_back(error);
1128 if (arr->size() < window_size) {
1129 AERROR <<
"Not enough elements in the array.";
1133 if (arr->size() > window_size) {
1134 arr->erase(arr->begin(), arr->begin() + (arr->size() - window_size));
1137 int8_t currentIndex = arr->size() - 1;
1138 int32_t current_direction = 0;
1139 for (
int i = currentIndex; i > currentIndex - window_size; --i) {
1140 current_direction = ((*arr)[i] >= threshold) ? 1 : ((*arr)[i] <= -threshold) ? -1 : 0;
1141 ADEBUG <<
"current_direction is " << current_direction <<
" with: " << (*arr)[i] <<
" " << i;
1142 double current_error_abs = std::fabs((*arr)[i]);
1145 ADEBUG <<
"Elements at positions " << i <<
" and " << i - 1 <<
" do not satisfy the condition.";
1146 current_direction = 0;
1147 *current_sign = current_direction;
1148 ADEBUG <<
"current_sign is " << *current_sign;
1154 *current_sign = current_direction;
1155 ADEBUG <<
"current_sign is " << *current_sign;
1196 const double v =
injector_->vehicle_state()->linear_velocity();
1197 double steer_angle_feedforwardterm = 0.0;
1202 steer_angle_feedforwardterm
1203 = (
wheelbase_ * ref_curvature + kv * v * v * ref_curvature
1209 return steer_angle_feedforwardterm;
1216 const double linear_v,
1218 const enum ChooseRefTrajectoryPoint &choose_point,
1220 double lateral_error = 0.0;
1221 double heading_error = 0.0;
1222 double curvature = 0.0;
1224 switch (choose_point) {
1225 case control::ChooseRefTrajectoryPoint::USE_LAT_MATCH_LR: {
1232 case control::ChooseRefTrajectoryPoint::USE_LAT_MATCH_LOCAL: {
1239 case control::ChooseRefTrajectoryPoint::USE_LAT_ABSOLUTE_LOCAL: {
1246 case control::ChooseRefTrajectoryPoint::USE_LAT_TRACK_COM: {
1249 double s_track_com, s_dot_track_com, d_track_com, d_dot_track_com;
1255 matched_track_point_com,
1261 lateral_error = d_track_com;
1268 double s_track_com, s_dot_track_com, d_track_com, d_dot_track_com;
1274 matched_track_point_com,
1280 lateral_error = d_track_com;
1285 lat_debug->mutable_track_point_com()->mutable_path_point()->set_x(matched_track_point_com.
x());
1286 lat_debug->mutable_track_point_com()->mutable_path_point()->set_y(matched_track_point_com.
y());
1287 lat_debug->set_lateral_error_track_com(lateral_error);
1288 lat_debug->set_heading_error_track_com(heading_error);
1295 const double linear_v,
1296 const double angular_v,
1297 const double linear_a,
1300 const enum ChooseRefTrajectoryPoint &choose_point,
1309 if (FLAGS_use_navigation_mode
1317 ADEBUG <<
"x point: " << x <<
" y point: " << y;
1318 ADEBUG <<
"match trajectory point information : " << target_point.ShortDebugString();
1320 auto vehicle_state =
injector_->vehicle_state();
1323 const auto &com_lr = vehicle_state->ComputeCOMPosition(
lr_);
1324 lat_debug->set_lr(
lr_);
1325 lat_debug->mutable_lat_lr_position()->set_x(com_lr.x());
1326 lat_debug->mutable_lat_lr_position()->set_y(com_lr.y());
1328 lat_debug->mutable_target_point_lr()->mutable_path_point()->set_x(target_point_lr.path_point().x());
1329 lat_debug->mutable_target_point_lr()->mutable_path_point()->set_y(target_point_lr.path_point().y());
1330 double s_target_lr, s_dot_target_lr, d_target_lr, d_dot_target_lr;
1334 vehicle_state->heading(),
1341 debug->set_ref_heading(target_point_lr.path_point().theta());
1342 lat_debug->set_curvature_target_lr(target_point_lr.path_point().kappa());
1343 lat_debug->set_lateral_error_target_lr(d_target_lr);
1348 debug->mutable_current_target_point()->mutable_path_point()->set_x(target_point.
path_point().
x());
1349 debug->mutable_current_target_point()->mutable_path_point()->set_y(target_point.
path_point().
y());
1350 double s_target_com, s_dot_target_com, d_target_com, d_dot_target_com;
1354 vehicle_state->heading(),
1362 lat_debug->set_curvature_target_com(target_point.
path_point().
kappa());
1363 lat_debug->set_lateral_error_target_com(d_target_com);
1368 lat_debug->mutable_matched_point_com()->mutable_path_point()->set_x(matched_point_com.x());
1369 lat_debug->mutable_matched_point_com()->mutable_path_point()->set_y(matched_point_com.y());
1370 double s_match_com, s_dot_match_com, d_match_com, d_dot_match_com;
1372 x, y, theta, linear_v, matched_point_com, &s_match_com, &s_dot_match_com, &d_match_com, &d_dot_match_com);
1373 debug->set_ref_heading(matched_point_com.theta());
1374 lat_debug->set_curvature_match_com(matched_point_com.kappa());
1375 lat_debug->set_lateral_error_match_com(d_match_com);
1379 auto matched_point_local = trajectory_analyzer.
QueryMatchedPathPoint(vehicle_state->x(), vehicle_state->y());
1380 lat_debug->mutable_matched_point_local()->mutable_path_point()->set_x(matched_point_local.x());
1381 lat_debug->mutable_matched_point_local()->mutable_path_point()->set_y(matched_point_local.y());
1382 double s_match_local, s_dot_match_local, d_match_local, d_dot_match_local;
1388 matched_point_local,
1392 &d_dot_match_local);
1393 debug->set_ref_heading(matched_point_local.theta());
1394 lat_debug->set_curvature_match_local(matched_point_local.kappa());
1395 lat_debug->set_lateral_error_match_local(d_match_local);
1399 double current_absolute_time = FLAGS_sim_by_record
1403 lat_debug->mutable_absolute_point_local()->mutable_path_point()->set_x(absolute_point_local.path_point().x());
1404 lat_debug->mutable_absolute_point_local()->mutable_path_point()->set_y(absolute_point_local.path_point().y());
1405 double s_absolute_local, s_dot_absolute_local, d_absolute_local, d_dot_absolute_local;
1411 absolute_point_local.path_point(),
1413 &s_dot_absolute_local,
1415 &d_dot_absolute_local);
1416 debug->set_ref_heading(absolute_point_local.path_point().theta());
1417 lat_debug->set_curvature_absolute_local(absolute_point_local.path_point().kappa());
1418 lat_debug->set_lateral_error_absolute_local(d_absolute_local);
1419 lat_debug->set_heading_error_absolute_local(
1422 double lateral_error = 0.0;
1423 double heading_error = 0.0;
1424 double curvature = 0.0;
1426 switch (choose_point) {
1427 case control::ChooseRefTrajectoryPoint::USE_LAT_TARGET_COM: {
1433 case control::ChooseRefTrajectoryPoint::USE_LAT_MATCH_COM: {
1439 case control::ChooseRefTrajectoryPoint::USE_LAT_MATCH_LOCAL: {
1445 case control::ChooseRefTrajectoryPoint::USE_LAT_ABSOLUTE_LOCAL: {
1452 const double dx = com_lr.x() - target_point.
path_point().
x();
1453 const double dy = com_lr.y() - target_point.
path_point().
y();
1454 const double cos_target_heading = std::cos(target_point.
path_point().
theta());
1455 const double sin_target_heading = std::sin(target_point.
path_point().
theta());
1457 double lateral_error = cos_target_heading * dy - sin_target_heading * dx;
1469 debug->set_curvature(curvature);
1476 lat_debug->set_current_min_error_point(control::ChooseRefTrajectoryPoint::USE_LAT_MATCH_COM);
1479 lat_debug->set_current_min_error_point(control::ChooseRefTrajectoryPoint::USE_LAT_MATCH_LOCAL);
1488 lat_debug->set_lateral_error_lqr_input(lateral_error);
1489 lat_debug->set_lateral_error_lqr_input_change(
1494 lat_debug->set_heading_error_by_ref(heading_error);
1502 heading_error -= compensation_output_value;
1503 lat_debug->set_heading_error_by_auto_compensation(heading_error);
1505 ->mutable_simple_lat_debug()
1506 ->mutable_ahc_value()
1507 ->set_compensation_output_value(compensation_output_value);
1515 lat_debug->set_heading_error_lqr_input(heading_error);
1516 lat_debug->set_heading_error_lqr_input_change(
1522 double lookahead_station = 0.0;
1523 double lookback_station = 0.0;
1536 std::fabs(linear_v));
1542 std::fabs(linear_v));
1544 lat_debug->set_lookahead_station(lookahead_station);
1545 lat_debug->set_lookback_station(lookback_station);
1548 switch (choose_point) {
1549 case control::ChooseRefTrajectoryPoint::USE_LAT_TARGET_COM: {
1558 trajectory_analyzer,
1563 case control::ChooseRefTrajectoryPoint::USE_LAT_MATCH_COM: {
1572 trajectory_analyzer,
1577 case control::ChooseRefTrajectoryPoint::USE_LAT_MATCH_LOCAL: {
1585 absolute_point_local,
1586 trajectory_analyzer,
1591 case control::ChooseRefTrajectoryPoint::USE_LAT_ABSOLUTE_LOCAL: {
1599 absolute_point_local,
1600 trajectory_analyzer,
1614 trajectory_analyzer,
1623 auto lateral_error_dot = linear_v * std::sin(heading_error);
1624 auto lateral_error_dot_dot = linear_a * std::sin(heading_error);
1625 if (FLAGS_reverse_heading_control) {
1627 lateral_error_dot = -lateral_error_dot;
1628 lateral_error_dot_dot = -lateral_error_dot_dot;
1631 auto centripetal_acceleration = linear_v * linear_v /
wheelbase_
1633 debug->set_lateral_error_rate(lateral_error_dot);
1634 debug->set_lateral_acceleration(lateral_error_dot_dot);
1635 debug->set_lateral_centripetal_acceleration(centripetal_acceleration);
1640 debug->set_heading_rate(-angular_v);
1642 debug->set_heading_rate(angular_v);
1644 debug->set_ref_heading_rate(target_point.
path_point().
kappa() * target_point.
v());
1661 const double lookahead_station,
1662 const double lookback_station,
1663 const double pose_x,
1664 const double pose_y,
1666 const double linear_v,
1672 debug_info->mutable_lookahead_point_new()->CopyFrom(lookahead_point_new);
1675 debug_info->mutable_lookback_point_new()->CopyFrom(lookback_point_new);
1679 + lookahead_station / (std::max(std::fabs(linear_v), 0.1) * std::cos(debug->
heading())));
1682 debug_info->set_lookahead_station_s_diff(lookahead_station);
1687 double heading_error_feedback = 0.0;
1688 double heading_error_feedback_new = 0.0;
1689 double lookahead_time_new = 0.0;
1690 double lookahead_station_s_diff_new = 0.0;
1691 double lookback_time_new = 0.0;
1692 double lookback_station_s_diff_new = 0.0;
1697 lookback_time_new = lookahead_point_new.relative_time() - ref_point.
relative_time();
1698 lookback_station_s_diff_new = lookahead_point_new.path_point().s() - ref_point.
path_point().
s();
1702 - lookahead_point.path_point().theta());
1704 lookahead_time_new = lookahead_point_new.relative_time() - ref_point.
relative_time();
1705 lookahead_station_s_diff_new = lookahead_point_new.path_point().s() - ref_point.
path_point().
s();
1707 debug_info->set_lookahead_time_new(lookahead_time_new);
1708 debug_info->set_lookahead_station_s_diff_new(lookahead_station_s_diff_new);
1709 debug_info->set_lookback_time_new(lookback_time_new);
1710 debug_info->set_lookback_station_s_diff_new(lookback_station_s_diff_new);
1712 debug_info->set_lookahead_curvature(lookahead_point.path_point().kappa());
1713 debug_info->set_lookahead_curvature_new(lookahead_point_new.path_point().kappa());
1714 debug_info->set_lookback_curvature_new(lookback_point_new.path_point().kappa());
1716 debug->set_heading_error_feedback(heading_error_feedback);
1717 debug_info->set_heading_error_feedback_new(heading_error_feedback_new);
1722 double lateral_error_feedback = 0.0;
1723 double lateral_error_feedback_new = 0.0;
1726 const double dx = pose_x - lookback_point_new.path_point().x();
1727 const double dy = pose_y - lookback_point_new.path_point().y();
1728 const double cos_target_heading = std::cos(lookback_point_new.path_point().theta());
1729 const double sin_target_heading = std::sin(lookback_point_new.path_point().theta());
1730 lateral_error_feedback_new = cos_target_heading * dy - sin_target_heading * dx;
1733 const double dx = pose_x - lookahead_point_new.path_point().x();
1734 const double dy = pose_y - lookahead_point_new.path_point().y();
1735 const double cos_target_heading = std::cos(lookahead_point_new.path_point().theta());
1736 const double sin_target_heading = std::sin(lookahead_point_new.path_point().theta());
1737 lateral_error_feedback_new = cos_target_heading * dy - sin_target_heading * dx;
1739 debug->set_lateral_error_feedback(lateral_error_feedback);
1740 debug_info->set_lateral_error_feedback_new(lateral_error_feedback_new);
1742 ADEBUG <<
"lateral_error_feedback: " << lateral_error_feedback
1743 <<
", lateral_error_feedback_new: " << lateral_error_feedback_new;
1747 auto vehicle_state =
injector_->vehicle_state();
1751 if (FLAGS_reverse_heading_control) {
1756 ADEBUG <<
"Matrix_b changed due to gear direction";
1765 && fabs(
injector_->vehicle_state()->linear_velocity())
1806 injector_->mutable_control_debug_info()->mutable_simple_lat_debug()->mutable_ahc_value()->set_ahc_sum(
AHC_sum_);
1807 injector_->mutable_control_debug_info()->mutable_simple_lat_debug()->mutable_ahc_value()->set_ahc_mean(
AHC_mean_);
1808 injector_->mutable_control_debug_info()->mutable_simple_lat_debug()->mutable_ahc_value()->set_ahc_peak(
AHC_peak_);
1810 ->mutable_simple_lat_debug()
1811 ->mutable_ahc_value()
1813 injector_->mutable_control_debug_info()->mutable_simple_lat_debug()->mutable_ahc_value()->set_ahc_compensated_value(
1815 injector_->mutable_control_debug_info()->mutable_simple_lat_debug()->mutable_ahc_value()->set_ahc_is_compensating(
1829 return output_value;
1865 const double lateral_error,
1866 const double heading_error,
1876 ADEBUG <<
"[AL new reverse]" <<
"first in reverse";
1880 ADEBUG <<
"[AL new reverse]" <<
"in 000000000000 stage damagely change heading ";
1885 ADEBUG <<
"[AL new reverse]" <<
"quit 00000000000 stage==============";
1895 }
else if (
now_reverse_stage_ == ReverseLogicStage::QUIT_FIRST_HEADING_HANDLE_STAGE) {
1896 ADEBUG <<
"[AL new reverse]" <<
"in 1111111111111 clear stage";
1900 ADEBUG <<
"[AL new reverse]" <<
"quit 111111111 stage==============";
1908 ADEBUG <<
"[AL new reverse]" <<
"in 222222222 lat err stage";
1917 ADEBUG <<
"[AL new reverse]" <<
"quit 222222222 stage==============";
1929 AINFO <<
"[STEERDEAD quit ,right behind ]" <<
"quit lat stage=======";
1941 AINFO <<
"[STEERDEAD quit ,left behind ]" <<
"quit lat stage=======";
1952 ADEBUG <<
"[AL new reverse]" <<
"in 33333333333 heading err stage";
1959 ADEBUG <<
"[AL new reverse]" <<
"quit 333333333 stage==============";
1969 ADEBUG <<
"[AL new reverse]" <<
"wrong!!!!! don't change any param";
1974 ADEBUG <<
"[AL new reverse]" <<
"quit reverse ,clear all marks";
1988 ADEBUG <<
"[FINALCHECK]final check in reverse park";
1997 u_int32_t max_uint32 = std::numeric_limits<uint32_t>::max();
1999 auto lat_check_debug = debug_info->mutable_lat_control_check_debug();
2001 double lateral_error
2004 if (lateral_error_failed ==
WARNING) {
2007 lat_check_debug->set_lateral_error_w(lateral_error);
2009 lat_check_debug->set_lateral_error_w(0.0);
2012 if (lateral_error_failed ==
ERROR) {
2015 lat_check_debug->set_lateral_error_e(lateral_error);
2017 lat_check_debug->set_lateral_error_e(0.0);
2019 lat_check_debug->set_lateral_error_check_result(lateral_error_failed);
2025 debug->set_lateral_error_feedback(lateral_error);
2027 debug_info->set_lateral_error_lqr_input(lateral_error);
void set_coefficients(const std::vector< double > &denominators, const std::vector< double > &numerators)
set denominators and numerators
double Filter(const double x_insert)
Processes a new measurement with the filter.
The MeanFilter class is used to smoothen a series of noisy numbers, such as sensor data or the output...
double Update(const double measurement)
Processes a new measurement in amortized constant time.
A general class to denote the return status of an API call.
static Status OK()
generate a success status.
The class of vehicle state.
static ControlCheckStatus check_lateral_error(const SafetyCheckConf &conf, double *lateral_error)
bool IsLargeCurvature(const double ref_curvature, const double min_large_ref_curvature, bool *is_in_large_curvature)
bool VehicleStatusIdentificationUpdate(const localization::LocalizationEstimate *localization, const canbus::Chassis *chassis, const planning::ADCTrajectory *trajectory)
bool IsLeftCurvature(const double ref_curvature)
static double interpolation_1d(const double &value, const google::protobuf::RepeatedField< double > &input_vector, const google::protobuf::RepeatedField< double > &output_vector)
Eigen::MatrixXd matrix_a_coeff_
double lookback_station_low_speed_
Eigen::MatrixXd matrix_b_
void LateralSafetyCheck(SimpleLateralDebug *debug, SimpleLateralPlusDebug *debug_info)
Eigen::MatrixXd matrix_k_
double AHC_compensated_value_
uint32_t lateral_error_w_count_
MracController mrac_controller_
double AHC_prev_compensated_value_
LatBaseLqrPlusControllerConf current_lat_based_lqr_plus_controller_conf_
Eigen::MatrixXd matrix_r_
void UpdateState(SimpleLateralDebug *debug, SimpleLateralPlusDebug *debug_info, const canbus::Chassis *chassis)
std::deque< double > AHC_container_
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)
double previous_ref_heading_acceleration_
double pre_steering_position_
bool InitControlConf(const LatBaseLqrPlusControllerConf ¤t_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)
LeadlagPlusController leadlag_controller_
double lookahead_station_low_speed_
double previous_lateral_acceleration_
LatPlusController()
constructor
std::vector< std::pair< std::string, LatBaseLqrPlusControllerConf > > params_list_
double CalculateTempAHCValue(const double &speed)
std::string current_param_config_name_
ReverseLogicStage::ReverseStageType now_reverse_stage_
bool enable_look_ahead_back_control_
Eigen::MatrixXd matrix_bd_
double AHC_compensating_value_
bool is_need_cover_turn_out_lane_com_length_
void ResetLateralSafetyCheck()
double ref_curvature_last_
bool LoadParams(ParamsPipeline *params_pipeline)
double query_relative_time_
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_
int reverse_handle_count_
virtual ~LatPlusController()
destructor
common::VehicleParam vehicle_param_
uint32_t lateral_error_e_count_
common::DigitalFilter digital_filter_
void ProcessLogs(const SimpleLateralDebug *debug, const canbus::Chassis *chassis)
Eigen::MatrixXd matrix_adc_
double ComputeFeedForward(double ref_curvature)
Eigen::MatrixXd matrix_q_
bool ChooseCurrentParam(LatBaseLqrPlusControllerConf ¤t_lat_based_lqr_plus_controller_conf, const planning::ADCTrajectory *planning_published_trajectory)
double lookback_station_high_speed_
common::Status Init(std::shared_ptr< DependencyInjector > injector) override
initialize Lateral Controller
double minimum_speed_protection_
double com_length_turbulence_
double steer_single_direction_max_degree_
double previous_ref_heading_rate_
double previous_heading_rate_
void UpdateMatrixCompound()
bool is_in_large_curvature_
Eigen::MatrixXd matrix_q_updated_
Eigen::MatrixXd matrix_state_
ParamsPipeline params_pipeline_
void UpdateDrivingOrientation()
double AHC_prev_output_value_
Eigen::MatrixXd matrix_bdc_
bool enable_enhance_qparam_
double driving_orientation_
double AutoCompensatedHeadingValue(const double &speed)
std::ofstream steer_log_file_
bool SetCurrentParam(const std::string param_config_name, LatBaseLqrPlusControllerConf ¤t_lat_based_lqr_plus_controller_conf)
bool IsDrivingStraight(const canbus::Chassis *chassis, double ref_curvature)
void ResetComLengthFromTurbulence()
common::MeanFilter heading_error_filter_
bool use_new_look_ahead_back_
Eigen::MatrixXd matrix_a_
void UpdateAHCParam(const double &heading_err, const double &speed)
const canbus::Chassis * chassis_
std::shared_ptr< DependencyInjector > injector_
double previous_lateral_error_lqr_input_
double current_trajectory_timestamp_
double com_turbulence_change_
double previous_heading_acceleration_
bool UpdateControlConf(const LatBaseLqrPlusControllerConf ¤t_lat_based_lqr_plus_controller_conf)
bool AHC_is_compensating_
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
std::vector< double > lateral_lr_errors_
enum ChooseRefTrajectoryPoint choose_ref_point_
std::string Name() const override
Lateral controller name
bool is_lat_preview_in_straight_
const int basic_state_size_
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)
double init_vehicle_heading_
common::MeanFilter lateral_error_filter_
uint8_t check_continous_errors_window_
double previous_heading_error_lqr_input_
double com_change_turbulence_add_
common::Status Reset() override
reset Lateral Controller
LatBaseLqrPlusControllerConf lat_based_lqr_plus_controller_conf_
double lookahead_station_high_speed_
Eigen::MatrixXd matrix_ad_
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
bool is_need_cover_turbulence_com_length_
virtual double Control(const double error, const double dt)
compute control value based on the error
void SetLeadlagConf(const LeadlagConf &leadlag_conf)
alpha, beta and tau
void InitLeadlag()
initialize lead/lag controller
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
void Init(const MracConf &mrac_conf, const common::LatencyParam &latency_param, const double dt)
initialize mrac controller
int ReferenceSaturationStatus() const
get saturation status for reference system
void Reset()
reset all the variables (including all the states, gains and externally-setting control parameters) f...
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
process point query and conversion related to trajectory
common::TrajectoryPoint QueryNearestPointByRelativeStation(const common::TrajectoryPoint &ref_point, const double &relative_station) const
query a point of trajectory that its s distance for reference trajectory point is closest to the give...
common::TrajectoryPoint QueryNearestPointByPosition(const double x, const double y) const
query a point of trajectory that its position is closest to the given position.
void TrajectoryTransformToCOM(const double rear_to_com_distance)
Transform the current trajectory points to the center of mass(COM) of the vehicle,...
common::PathPoint QueryMatchedPathPoint(const double x, const double y) const
query a point on trajectory that its position is closest to the given position.
common::TrajectoryPoint QueryNearestPointByAbsoluteTime(const double t) const
query a point of trajectory that its absolute time is closest to the give time.
void ToTrajectoryFrame(const double x, const double y, const double theta, const double v, const common::PathPoint &matched_point, double *ptr_s, double *ptr_s_dot, double *ptr_d, double *ptr_d_dot) const
convert a position with theta and speed to trajectory frame,
common::TrajectoryPoint QueryNearestPointByRelativeTime(const double t) const
query a point of trajectory that its relative time is closest to the give time.
a singleton clock that can be used to get the current timestamp.
static double NowInSeconds()
gets the current time in second.
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
Math-related util functions.
Defines the LatPlusController class.
Linear interpolation functions.
Solver for discrete-time linear quadratic problem.
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)
double NormalizeAngle(const double angle)
Normalize angle to [-PI, PI).
void LpfCoefficients(const double ts, const double cutoff_freq, std::vector< double > *denominators, std::vector< double > *numerators)
Get low-pass coefficients for digital filter.
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,...
Contains a number of helper functions related to quaternions.
optional apollo::common::Header header
optional DrivingMode driving_mode
optional float steering_percentage
optional double relative_time
optional PathPoint path_point
optional double max_steer_angle
optional LatencyParam steering_latency_param
optional double steer_ratio
optional double max_steer_angle_rate
optional double wheel_base
optional double steering_target
optional double steer_angle_lateral_rate_contribution
optional double heading_rate
optional double steer_angle_feedforward
optional double steer_angle
optional double heading_error_feedback
optional double steer_angle_heading_rate_contribution
optional double lateral_error
optional double ref_heading_rate
optional double steer_angle_lateral_contribution
optional double lateral_error_feedback
optional double heading_error_rate
optional double ref_heading_jerk
optional double lateral_acceleration
optional double ref_heading_acceleration
optional double steer_angle_feedback
optional double steer_angle_heading_contribution
optional double lateral_error_rate
optional double heading_jerk
optional double ref_heading
optional double heading_error
optional double heading_acceleration
optional double curvature
optional double lateral_error_feedback_new
optional double com_length
optional double heading_error_match_local
optional double lateral_error_lqr_input_change
optional double heading_error_lqr_input
optional apollo::common::TrajectoryPoint absolute_point_local
optional double lateral_error_target_lr
optional double lateral_error_target_com
optional double heading_error_lqr_input_change
optional double heading_error_absolute_local
optional double heading_error_target_lr
optional double curvature_match_local
optional double lateral_error_track_com
optional double heading_error_target_com
optional apollo::common::TrajectoryPoint target_point_lr
optional double curvature_match_com
optional apollo::common::TrajectoryPoint matched_point_local
optional double lateral_error_match_local
optional double curvature_absolute_local
optional double lateral_error_absolute_local
optional double heading_error_match_com
optional double curvature_target_com
optional double heading_error_feedback_new
optional double lateral_error_match_com
optional double lateral_error_lqr_input
optional double path_remain
optional apollo::localization::Pose pose
optional apollo::common::Quaternion orientation
optional apollo::common::PointENU position
optional TrajectoryType trajectory_type
optional apollo::common::Header header
optional apollo::planning_internal::Debug debug
optional PlanningData planning_data
optional ScenarioDebug scenario
optional string scenario_plugin_type