1302 {
1303 TrajectoryPoint target_point;
1304
1306 target_point
1308 } else {
1309 if (FLAGS_use_navigation_mode
1311 target_point
1313 } else {
1314 target_point = trajectory_analyzer.QueryNearestPointByPosition(x, y);
1315 }
1316 }
1317 ADEBUG <<
"x point: " << x <<
" y point: " << y;
1318 ADEBUG <<
"match trajectory point information : " << target_point.ShortDebugString();
1319
1320 auto vehicle_state =
injector_->vehicle_state();
1321
1322
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());
1327 auto target_point_lr = trajectory_analyzer.QueryNearestPointByPosition(com_lr.x(), 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;
1331 trajectory_analyzer.ToTrajectoryFrame(
1332 com_lr.x(),
1333 com_lr.y(),
1334 vehicle_state->heading(),
1335 linear_v,
1336 target_point.path_point(),
1337 &s_target_lr,
1338 &s_dot_target_lr,
1339 &d_target_lr,
1340 &d_dot_target_lr);
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);
1345
1346
1347 target_point = trajectory_analyzer.QueryNearestPointByPosition(x, y);
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;
1351 trajectory_analyzer.ToTrajectoryFrame(
1352 x,
1353 y,
1354 vehicle_state->heading(),
1355 linear_v,
1356 target_point.path_point(),
1357 &s_target_com,
1358 &s_dot_target_com,
1359 &d_target_com,
1360 &d_dot_target_com);
1361 debug->set_ref_heading(target_point.path_point().theta());
1362 lat_debug->set_curvature_target_com(target_point.path_point().kappa());
1363 lat_debug->set_lateral_error_target_com(d_target_com);
1365
1366
1367 auto matched_point_com = trajectory_analyzer.QueryMatchedPathPoint(x, y);
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;
1371 trajectory_analyzer.ToTrajectoryFrame(
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);
1377
1378
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;
1383 trajectory_analyzer.ToTrajectoryFrame(
1384 vehicle_state->x(),
1385 vehicle_state->y(),
1386 theta,
1387 linear_v,
1388 matched_point_local,
1389 &s_match_local,
1390 &s_dot_match_local,
1391 &d_match_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);
1397
1398
1399 double current_absolute_time = FLAGS_sim_by_record
1402 auto absolute_point_local = trajectory_analyzer.QueryNearestPointByAbsoluteTime(current_absolute_time);
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;
1406 trajectory_analyzer.ToTrajectoryFrame(
1407 vehicle_state->x(),
1408 vehicle_state->y(),
1409 theta,
1410 linear_v,
1411 absolute_point_local.path_point(),
1412 &s_absolute_local,
1413 &s_dot_absolute_local,
1414 &d_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(
1421
1422 double lateral_error = 0.0;
1423 double heading_error = 0.0;
1424 double curvature = 0.0;
1425
1426 switch (choose_point) {
1427 case control::ChooseRefTrajectoryPoint::USE_LAT_TARGET_COM: {
1428 lateral_error = lat_debug->lateral_error_target_com();
1429 heading_error = lat_debug->heading_error_target_com();
1430 curvature = lat_debug->curvature_target_com();
1431 break;
1432 }
1433 case control::ChooseRefTrajectoryPoint::USE_LAT_MATCH_COM: {
1434 lateral_error = lat_debug->lateral_error_match_com();
1435 heading_error = lat_debug->heading_error_match_com();
1436 curvature = lat_debug->curvature_match_com();
1437 break;
1438 }
1439 case control::ChooseRefTrajectoryPoint::USE_LAT_MATCH_LOCAL: {
1440 lateral_error = lat_debug->lateral_error_match_local();
1441 heading_error = lat_debug->heading_error_match_local();
1442 curvature = lat_debug->curvature_match_local();
1443 break;
1444 }
1445 case control::ChooseRefTrajectoryPoint::USE_LAT_ABSOLUTE_LOCAL: {
1446 lateral_error = lat_debug->lateral_error_absolute_local();
1447 heading_error = lat_debug->heading_error_absolute_local();
1448 curvature = lat_debug->curvature_absolute_local();
1449 break;
1450 }
1451 default: {
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());
1456
1457 double lateral_error = cos_target_heading * dy - sin_target_heading * dx;
1460 }
1461 debug->set_ref_heading(target_point.path_point().theta());
1463 curvature = target_point.path_point().kappa();
1464 break;
1465 }
1466 }
1467
1468
1469 debug->set_curvature(curvature);
1472
1473
1474 if (std::fabs(lat_debug->lateral_error_match_com()) <= std::fabs(lat_debug->lateral_error_match_local())) {
1475 debug->set_lateral_error(lat_debug->lateral_error_match_com());
1476 lat_debug->set_current_min_error_point(control::ChooseRefTrajectoryPoint::USE_LAT_MATCH_COM);
1477 } else {
1478 debug->set_lateral_error(lat_debug->lateral_error_match_local());
1479 lat_debug->set_current_min_error_point(control::ChooseRefTrajectoryPoint::USE_LAT_MATCH_LOCAL);
1480 }
1481 if (std::fabs(lat_debug->heading_error_match_com()) <= std::fabs(lat_debug->heading_error_match_local())) {
1482 debug->set_heading_error(lat_debug->heading_error_match_com());
1483 } else {
1484 debug->set_heading_error(lat_debug->heading_error_match_local());
1485 }
1486
1487
1488 lat_debug->set_lateral_error_lqr_input(lateral_error);
1489 lat_debug->set_lateral_error_lqr_input_change(
1492
1493
1494 lat_debug->set_heading_error_by_ref(heading_error);
1497 }
1498
1499
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);
1510 } else {
1512 }
1513 }
1514
1515 lat_debug->set_heading_error_lqr_input(heading_error);
1516 lat_debug->set_heading_error_lqr_input_change(
1519
1520
1521
1522 double lookahead_station = 0.0;
1523 double lookback_station = 0.0;
1530 } else {
1536 std::fabs(linear_v));
1542 std::fabs(linear_v));
1543 }
1544 lat_debug->set_lookahead_station(lookahead_station);
1545 lat_debug->set_lookback_station(lookback_station);
1546
1547
1548 switch (choose_point) {
1549 case control::ChooseRefTrajectoryPoint::USE_LAT_TARGET_COM: {
1551 lookahead_station,
1552 lookback_station,
1553 x,
1554 y,
1555 theta,
1556 linear_v,
1557 target_point,
1558 trajectory_analyzer,
1559 debug,
1560 lat_debug);
1561 break;
1562 }
1563 case control::ChooseRefTrajectoryPoint::USE_LAT_MATCH_COM: {
1565 lookahead_station,
1566 lookback_station,
1567 x,
1568 y,
1569 theta,
1570 linear_v,
1571 target_point,
1572 trajectory_analyzer,
1573 debug,
1574 lat_debug);
1575 break;
1576 }
1577 case control::ChooseRefTrajectoryPoint::USE_LAT_MATCH_LOCAL: {
1579 lookahead_station,
1580 lookback_station,
1581 vehicle_state->x(),
1582 vehicle_state->y(),
1583 theta,
1584 linear_v,
1585 absolute_point_local,
1586 trajectory_analyzer,
1587 debug,
1588 lat_debug);
1589 break;
1590 }
1591 case control::ChooseRefTrajectoryPoint::USE_LAT_ABSOLUTE_LOCAL: {
1593 lookahead_station,
1594 lookback_station,
1595 vehicle_state->x(),
1596 vehicle_state->y(),
1597 theta,
1598 linear_v,
1599 absolute_point_local,
1600 trajectory_analyzer,
1601 debug,
1602 lat_debug);
1603 break;
1604 }
1605 default: {
1607 lookahead_station,
1608 lookback_station,
1609 com_lr.x(),
1610 com_lr.y(),
1611 theta,
1612 linear_v,
1613 target_point_lr,
1614 trajectory_analyzer,
1615 debug,
1616 lat_debug);
1617 break;
1618 }
1619 }
1620
1622
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;
1629 }
1630 }
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);
1638
1640 debug->set_heading_rate(-angular_v);
1641 } else {
1642 debug->set_heading_rate(angular_v);
1643 }
1644 debug->set_ref_heading_rate(target_point.path_point().kappa() * target_point.v());
1645 debug->set_heading_error_rate(debug->heading_rate() - debug->ref_heading_rate());
1646
1649 debug->set_heading_error_acceleration(debug->heading_acceleration() - debug->ref_heading_acceleration());
1652
1655 debug->set_heading_error_jerk(debug->heading_jerk() - debug->ref_heading_jerk());
1658}
double Update(const double measurement)
Processes a new measurement in amortized constant time.
double lookback_station_low_speed_
void LateralSafetyCheck(SimpleLateralDebug *debug, SimpleLateralPlusDebug *debug_info)
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 lookahead_station_low_speed_
double previous_lateral_acceleration_
double CalculateTempAHCValue(const double &speed)
double query_relative_time_
double lookback_station_high_speed_
double previous_ref_heading_rate_
double previous_heading_rate_
bool IsDrivingStraight(const canbus::Chassis *chassis, double ref_curvature)
common::MeanFilter heading_error_filter_
void UpdateAHCParam(const double &heading_err, const double &speed)
double previous_lateral_error_lqr_input_
double previous_heading_acceleration_
common::MeanFilter lateral_error_filter_
double previous_heading_error_lqr_input_
double lookahead_station_high_speed_
static double NowInSeconds()
gets the current time in second.
double NormalizeAngle(const double angle)
Normalize angle to [-PI, PI).
optional apollo::common::Header header
optional double max_steer_angle