25#include "absl/strings/str_cat.h"
27#include "modules/common_msgs/planning_msgs/sl_boundary.pb.h"
28#include "modules/planning/planning_base/proto/planning_status.pb.h"
50std::unordered_map<std::string, bool>
51 ReferenceLineInfo::junction_right_of_way_map_;
57 : vehicle_state_(vehicle_state),
58 adc_planning_point_(adc_planning_point),
59 reference_line_(reference_line),
61 if (lanes_.size() == 0) {
64 std::ostringstream segs_id;
65 segs_id.setf(std::ios::fixed);
68 for (
const auto& seg : lanes_) {
69 segs_id <<
"_" << seg.lane->id().id();
72 segs_id <<
"_" << lanes_.front().start_s <<
"_" << lanes_.back().end_s;
78 double target_speed) {
81 const auto& path_point = adc_planning_point_.
path_point();
82 Vec2d position(path_point.x(), path_point.y());
84 (param.front_edge_to_center() - param.back_edge_to_center()) / 2.0,
85 (param.left_edge_to_center() - param.right_edge_to_center()) / 2.0);
86 Vec2d center(position + vec_to_center.
rotate(path_point.theta()));
87 Box2d box(center, path_point.theta(), param.length(), param.width());
89 Vec2d vehicle_position(vehicle_state_.
x(), vehicle_state_.
y());
90 Vec2d vehicle_center(vehicle_position +
92 Box2d vehicle_box(vehicle_center, vehicle_state_.
heading(), param.length(),
102 if (adc_sl_boundary_.
end_s() < 0 ||
104 AWARN <<
"Vehicle SL " << adc_sl_boundary_.ShortDebugString()
105 <<
" is not on reference line:[0, " << reference_line_.
Length()
108 static constexpr double kOutOfReferenceLineL = 14.0;
109 if (adc_sl_boundary_.
start_l() > kOutOfReferenceLineL ||
110 adc_sl_boundary_.
end_l() < -kOutOfReferenceLineL) {
111 AERROR <<
"Ego vehicle is too far away from reference line."
112 <<
"adc_sl_boundary_.start_l:" << adc_sl_boundary_.
start_l()
113 <<
"adc_sl_boundary_.end_l:" << adc_sl_boundary_.
end_l();
116 is_on_reference_line_ = reference_line_.
IsOnLane(adc_sl_boundary_);
118 AERROR <<
"Failed to add obstacles to reference line";
122 const auto& map_path = reference_line_.
map_path();
123 for (
const auto& speed_bump : map_path.speed_bump_overlaps()) {
126 speed_bump.end_s + 1.0,
127 FLAGS_speed_bump_speed_limit);
134 vehicle_signal_.Clear();
140 return candidate_path_data_;
144 std::vector<PathData>&& candidate_path_data) {
145 candidate_path_data_ = std::move(candidate_path_data);
150 return candidate_path_boundaries_;
154 std::vector<PathBoundary>&& path_boundaries) {
155 candidate_path_boundaries_ = std::move(path_boundaries);
159 if (base_cruise_speed_ <= speed) {
162 cruise_speed_ = speed;
166 return base_cruise_speed_ > 0.0 ? base_cruise_speed_
167 : FLAGS_default_cruise_speed;
171 return cruise_speed_ > 0.0 ? cruise_speed_ : FLAGS_default_cruise_speed;
175 const double s)
const {
176 std::vector<hdmap::LaneInfoConstPtr> lanes;
179 AWARN <<
"cannot get any lane using s";
183 return lanes.front();
188 hdmap::Id* ptr_lane_id,
double* ptr_lane_width)
const {
190 if (ptr_lane_info ==
nullptr) {
196 if (ptr_lane_info->lane().left_neighbor_forward_lane_id().empty()) {
199 *ptr_lane_id = ptr_lane_info->lane().left_neighbor_forward_lane_id(0);
203 if (ptr_lane_info->lane().left_neighbor_reverse_lane_id().empty()) {
206 *ptr_lane_id = ptr_lane_info->lane().left_neighbor_reverse_lane_id(0);
210 if (ptr_lane_info->lane().right_neighbor_forward_lane_id().empty()) {
213 *ptr_lane_id = ptr_lane_info->lane().right_neighbor_forward_lane_id(0);
217 if (ptr_lane_info->lane().right_neighbor_reverse_lane_id().empty()) {
220 *ptr_lane_id = ptr_lane_info->lane().right_neighbor_reverse_lane_id(0);
226 auto ptr_neighbor_lane =
228 if (ptr_neighbor_lane ==
nullptr) {
234 double neighbor_s = 0.0;
235 double neighbor_l = 0.0;
236 if (!ptr_neighbor_lane->GetProjection({ref_point.x(), ref_point.y()},
237 &neighbor_s, &neighbor_l)) {
241 *ptr_lane_width = ptr_neighbor_lane->GetWidth(neighbor_s);
245bool ReferenceLineInfo::GetFirstOverlap(
246 const std::vector<hdmap::PathOverlap>& path_overlaps,
248 CHECK_NOTNULL(path_overlap);
249 const double start_s = adc_sl_boundary_.
end_s();
250 static constexpr double kMaxOverlapRange = 500.0;
251 double overlap_min_s = kMaxOverlapRange;
253 auto overlap_min_s_iter = path_overlaps.end();
254 for (
auto iter = path_overlaps.begin(); iter != path_overlaps.end(); ++iter) {
255 if (iter->end_s < start_s) {
258 if (overlap_min_s > iter->start_s) {
259 overlap_min_s_iter = iter;
260 overlap_min_s = iter->start_s;
265 if (overlap_min_s_iter != path_overlaps.end()) {
266 *path_overlap = *overlap_min_s_iter;
269 return overlap_min_s < kMaxOverlapRange;
272void ReferenceLineInfo::InitFirstOverlaps() {
273 const auto& map_path = reference_line_.
map_path();
275 hdmap::PathOverlap clear_area_overlap;
276 if (GetFirstOverlap(map_path.clear_area_overlaps(), &clear_area_overlap)) {
277 first_encounter_overlaps_.emplace_back(
CLEAR_AREA, clear_area_overlap);
281 hdmap::PathOverlap crosswalk_overlap;
282 if (GetFirstOverlap(map_path.crosswalk_overlaps(), &crosswalk_overlap)) {
283 first_encounter_overlaps_.emplace_back(
CROSSWALK, crosswalk_overlap);
287 hdmap::PathOverlap pnc_junction_overlap;
288 if (GetFirstOverlap(map_path.pnc_junction_overlaps(),
289 &pnc_junction_overlap)) {
290 first_encounter_overlaps_.emplace_back(
PNC_JUNCTION, pnc_junction_overlap);
294 hdmap::PathOverlap signal_overlap;
295 if (GetFirstOverlap(map_path.signal_overlaps(), &signal_overlap)) {
296 first_encounter_overlaps_.emplace_back(
SIGNAL, signal_overlap);
300 hdmap::PathOverlap stop_sign_overlap;
301 if (GetFirstOverlap(map_path.stop_sign_overlaps(), &stop_sign_overlap)) {
302 first_encounter_overlaps_.emplace_back(
STOP_SIGN, stop_sign_overlap);
306 hdmap::PathOverlap yield_sign_overlap;
307 if (GetFirstOverlap(map_path.yield_sign_overlaps(), &yield_sign_overlap)) {
308 first_encounter_overlaps_.emplace_back(
YIELD_SIGN, yield_sign_overlap);
312 hdmap::PathOverlap area_overlap;
313 if (GetFirstOverlap(map_path.area_overlaps(), &area_overlap)) {
314 first_encounter_overlaps_.emplace_back(
AREA, area_overlap);
318 if (!first_encounter_overlaps_.empty()) {
319 std::sort(first_encounter_overlaps_.begin(),
320 first_encounter_overlaps_.end(),
321 [](
const std::pair<OverlapType, hdmap::PathOverlap>& a,
322 const std::pair<OverlapType, hdmap::PathOverlap>& b) {
323 return a.second.start_s < b.second.start_s;
329 static constexpr double kEpsilon = 1e-2;
330 return overlap.
start_s - kEpsilon <= s && s <= overlap.
end_s + kEpsilon;
334 const bool is_protected)
const {
337 junction_right_of_way_map_[overlap.object_id] = is_protected;
344 if (overlap.end_s < adc_sl_boundary_.
start_s()) {
345 junction_right_of_way_map_.erase(overlap.object_id);
347 auto is_protected = junction_right_of_way_map_[overlap.object_id];
359 std::list<hdmap::Id> lane_ids;
360 for (
const auto& lane_seg : lanes_) {
361 lane_ids.push_back(lane_seg.lane->id());
367 return adc_sl_boundary_;
373 return path_decision_;
377 return reference_line_;
381 return &reference_line_;
388bool ReferenceLineInfo::AddObstacleHelper(
389 const std::shared_ptr<Obstacle>& obstacle) {
396 AERROR <<
"The provided obstacle is empty";
399 auto* mutable_obstacle = path_decision_.
AddObstacle(*obstacle);
400 if (!mutable_obstacle) {
401 AERROR <<
"failed to add obstacle " << obstacle->
Id();
408 AERROR <<
"Failed to get sl boundary for obstacle: " << obstacle->
Id();
409 return mutable_obstacle;
411 mutable_obstacle->SetPerceptionSlBoundary(perception_sl);
412 mutable_obstacle->CheckLaneBlocking(reference_line_);
413 if (mutable_obstacle->IsLaneBlocking()) {
414 ADEBUG <<
"obstacle [" << obstacle->
Id() <<
"] is lane blocking.";
416 ADEBUG <<
"obstacle [" << obstacle->
Id() <<
"] is NOT lane blocking.";
419 if (IsIrrelevantObstacle(*mutable_obstacle)) {
420 ObjectDecisionType ignore;
421 ignore.mutable_ignore();
425 obstacle->
Id(), ignore);
426 AINFO <<
"NO build reference line st boundary. id:" << obstacle->
Id();
428 AINFO <<
"build reference line st boundary. id:" << obstacle->
Id();
429 mutable_obstacle->BuildReferenceLineStBoundary(reference_line_,
432 ADEBUG <<
"reference line st boundary: t["
433 << mutable_obstacle->reference_line_st_boundary().min_t() <<
", "
434 << mutable_obstacle->reference_line_st_boundary().max_t() <<
"] s["
435 << mutable_obstacle->reference_line_st_boundary().min_s() <<
", "
436 << mutable_obstacle->reference_line_st_boundary().max_s() <<
"]";
438 return mutable_obstacle;
442 const std::vector<const Obstacle*>& obstacles) {
443 if (FLAGS_use_multi_thread_to_add_obstacles) {
444 std::vector<std::future<Obstacle*>> results;
445 for (
const auto* obstacle : obstacles) {
449 for (
auto& result : results) {
451 AERROR <<
"Fail to add obstacles.";
456 for (
const auto* obstacle : obstacles) {
458 AERROR <<
"Failed to add obstacle " << obstacle->Id();
467bool ReferenceLineInfo::IsIrrelevantObstacle(
const Obstacle& obstacle) {
473 if (obstacle_boundary.start_s() > reference_line_.
Length()) {
477 adc_sl_boundary_.
start_s() - obstacle_boundary.end_s() >
478 FLAGS_obstacle_lon_ignore_buffer &&
479 (reference_line_.
IsOnLane(obstacle_boundary) ||
480 obstacle_boundary.end_s() < 0.0)) {
487 return discretized_trajectory_;
491 planning_target_.mutable_stop_point()->CopyFrom(stop_point);
495 planning_target_.set_cruise_speed(speed);
504 const auto& prev_reference_line =
507 prev_reference_line.XYToSL(start_point, &sl_point);
508 return previous_reference_line_info.reference_line_.
IsOnLane(sl_point);
514 return fallback_path_data_;
522 return &fallback_path_data_;
532 const double relative_time,
const double start_s,
534 ACHECK(ptr_discretized_trajectory !=
nullptr);
537 const double kDenseTimeResoltuion = FLAGS_trajectory_time_min_interval;
538 const double kSparseTimeResolution = FLAGS_trajectory_time_max_interval;
539 const double kDenseTimeSec = FLAGS_trajectory_time_high_density_period;
542 AERROR <<
"path data is empty";
546 if (speed_data_.empty()) {
547 AERROR <<
"speed profile is empty";
551 for (
double cur_rel_time = 0.0; cur_rel_time < speed_data_.
TotalTime();
552 cur_rel_time += (cur_rel_time < kDenseTimeSec ? kDenseTimeResoltuion
553 : kSparseTimeResolution)) {
556 AERROR <<
"Fail to get speed point with relative time " << cur_rel_time;
565 path_point.set_s(path_point.
s() + start_s);
568 trajectory_point.mutable_path_point()->CopyFrom(path_point);
569 trajectory_point.set_v(speed_point.
v());
570 trajectory_point.set_a(speed_point.
a());
571 trajectory_point.set_relative_time(speed_point.
t() + relative_time);
575 std::for_each(ptr_discretized_trajectory->begin(),
576 ptr_discretized_trajectory->end(),
578 trajectory_point.set_v(-trajectory_point.v());
579 trajectory_point.set_a(-trajectory_point.a());
580 trajectory_point.mutable_path_point()->set_s(
581 -trajectory_point.path_point().s());
583 AINFO <<
"reversed path";
595 const std::vector<common::TrajectoryPoint>& trajectory,
597 ACHECK(adjusted_trajectory !=
nullptr);
599 static constexpr double kMaxAngleDiff = M_PI_2;
600 const double start_point_heading = planning_start_point.
path_point().
theta();
601 const double start_point_x = planning_start_point.
path_point().
x();
602 const double start_point_y = planning_start_point.
path_point().
y();
603 const double start_point_relative_time = planning_start_point.
relative_time();
606 for (
size_t i = 0; i <
trajectory.size(); ++i) {
608 if (
trajectory[i].relative_time() <= start_point_relative_time) {
612 const double cur_point_x =
trajectory[i].path_point().x();
613 const double cur_point_y =
trajectory[i].path_point().y();
614 const double tracking_heading =
615 std::atan2(cur_point_y - start_point_y, cur_point_x - start_point_x);
617 tracking_heading)) < kMaxAngleDiff) {
622 if (insert_idx == -1) {
623 AERROR <<
"All points are behind of planning init point";
628 cut_trajectory.erase(cut_trajectory.begin(),
629 cut_trajectory.begin() + insert_idx);
630 cut_trajectory.insert(cut_trajectory.begin(), planning_start_point);
639 if (cut_trajectory.size() > 1 && cut_trajectory.front().relative_time() >=
640 cut_trajectory[1].relative_time()) {
641 AERROR <<
"planning init point relative_time["
642 << cut_trajectory.front().relative_time()
643 <<
"] larger than its next point's relative_time["
644 << cut_trajectory[1].relative_time() <<
"]";
650 double accumulated_s = 0.0;
651 for (
size_t i = 1; i < cut_trajectory.size(); ++i) {
652 const auto& pre_path_point = cut_trajectory[i - 1].path_point();
653 auto* cur_path_point = cut_trajectory[i].mutable_path_point();
654 accumulated_s += std::sqrt((cur_path_point->x() - pre_path_point.x()) *
655 (cur_path_point->x() - pre_path_point.x()) +
656 (cur_path_point->y() - pre_path_point.y()) *
657 (cur_path_point->y() - pre_path_point.y()));
658 cur_path_point->set_s(accumulated_s);
662 adjusted_trajectory->clear();
665 const double kDenseTimeResoltuion = FLAGS_trajectory_time_min_interval;
666 const double kSparseTimeResolution = FLAGS_trajectory_time_max_interval;
667 const double kDenseTimeSec = FLAGS_trajectory_time_high_density_period;
668 for (
double cur_rel_time = cut_trajectory.front().relative_time();
669 cur_rel_time <= cut_trajectory.back().relative_time();
670 cur_rel_time += (cur_rel_time < kDenseTimeSec ? kDenseTimeResoltuion
671 : kSparseTimeResolution)) {
673 cut_trajectory.
Evaluate(cur_rel_time));
691 return absl::StrCat(
"path_data:", path_data_.
DebugString(),
695bool ReferenceLineInfo::IsEgoOnRoutingLane()
const {
696 double ego_x = vehicle_state_.
x();
697 double ego_y = vehicle_state_.
y();
698 double lane_left_width = 0;
699 double lane_right_width = 0;
701 reference_line_.
XYToSL({ego_x, ego_y}, &sl_point);
704 ADEBUG <<
"s: " << sl_point.
s() <<
" l: " << sl_point.
l()
705 <<
" lane_left_width: " << lane_left_width
706 <<
" lane_right_width: " << lane_right_width;
707 if (lane_left_width >= sl_point.
l() && -lane_right_width <= sl_point.
l()) {
714void ReferenceLineInfo::SetTurnSignalBasedOnLaneTurnType(
715 common::VehicleSignal* vehicle_signal)
const {
716 CHECK_NOTNULL(vehicle_signal);
717 if (vehicle_signal->has_turn_signal() &&
734 bool is_ego_on_routing_lane = IsEgoOnRoutingLane();
735 if (path_data_.
path_label().find(
"left") != std::string::npos &&
736 is_ego_on_routing_lane) {
738 AINFO <<
"Set turn signal to left";
741 if (path_data_.
path_label().find(
"left") != std::string::npos &&
742 !is_ego_on_routing_lane) {
744 AINFO <<
"Set turn signal to right";
747 if (path_data_.
path_label().find(
"right") != std::string::npos &&
748 is_ego_on_routing_lane) {
750 AINFO <<
"Set turn signal to right";
753 if (path_data_.
path_label().find(
"right") != std::string::npos &&
754 !is_ego_on_routing_lane) {
756 AINFO <<
"Set turn signal to left";
761 double route_s = 0.0;
762 const double adc_s = adc_sl_boundary_.
end_s();
763 for (
const auto& seg :
Lanes()) {
764 if (route_s > adc_s + FLAGS_turn_signal_distance) {
767 route_s += seg.end_s - seg.start_s;
768 if (route_s < adc_s) {
771 const auto& turn = seg.lane->lane().turn();
774 AINFO <<
"Set turn signal to left";
778 AINFO <<
"Set turn signal to right";
785 seg.lane->GetSmoothPoint((seg.start_s + seg.end_s) / 2.0));
787 auto start_to_middle = middle_xy - start_xy;
788 auto start_to_end = end_xy - start_xy;
789 if (start_to_middle.CrossProd(start_to_end) < 0) {
801 vehicle_signal_.set_turn_signal(turn_signal);
805 vehicle_signal_.set_emergency_light(
true);
808void ReferenceLineInfo::ExportVehicleSignal(
810 CHECK_NOTNULL(vehicle_signal);
811 *vehicle_signal = vehicle_signal_;
812 SetTurnSignalBasedOnLaneTurnType(vehicle_signal);
818 AINFO <<
"distance_destination:" << distance_destination
819 <<
"distance_ref_end: " << distance_ref_end;
820 return distance_destination <= FLAGS_passed_destination_threshold ||
821 distance_ref_end <= FLAGS_passed_referenceline_end_threshold;
825 double res = std::numeric_limits<double>::max();
826 const auto* dest_ptr = path_decision_.
Find(FLAGS_destination_obstacle_id);
830 if (!dest_ptr->LongitudinalDecision().has_stop()) {
833 if (!reference_line_.
IsOnLane(dest_ptr->PerceptionBoundingBox().center())) {
837 dest_ptr->LongitudinalDecision().stop().distance_s();
838 AINFO <<
"stop_s: " << stop_s <<
"end_s: " << adc_sl_boundary_.
end_s();
839 return stop_s - adc_sl_boundary_.
end_s();
843 double res = std::numeric_limits<double>::max();
845 std::string ref_end_id;
847 std::string
id = obstacle->
Id();
848 if (
id.find(
"REF_END") != std::string::npos) {
850 AINFO <<
"Found reference line end id: " << ref_end_id;
855 if (!ref_end_id.empty()) {
856 AINFO <<
"REF_END: " << ref_end_id;
857 const auto* ref_end_ptr = path_decision_.
Find(ref_end_id);
859 if (!ref_end_ptr && !ref_end_ptr->LongitudinalDecision().has_stop() &&
861 ref_end_ptr->PerceptionBoundingBox().center())) {
862 const double stop_s =
863 ref_end_ptr->PerceptionSLBoundary().start_s() +
864 ref_end_ptr->LongitudinalDecision().stop().distance_s();
865 AINFO <<
"REF_END: stop_s: " << stop_s
866 <<
"end_s: " << adc_sl_boundary_.
end_s();
867 res = stop_s - adc_sl_boundary_.
end_s();
874 DecisionResult* decision_result,
PlanningContext* planning_context)
const {
875 MakeDecision(decision_result, planning_context);
876 ExportVehicleSignal(decision_result->mutable_vehicle_signal());
877 auto* main_decision = decision_result->mutable_main_decision();
878 if (main_decision->has_stop()) {
879 main_decision->mutable_stop()->set_change_lane_type(
880 Lanes().PreviousAction());
881 }
else if (main_decision->has_cruise()) {
882 main_decision->mutable_cruise()->set_change_lane_type(
883 Lanes().PreviousAction());
887void ReferenceLineInfo::MakeDecision(DecisionResult* decision_result,
889 CHECK_NOTNULL(decision_result);
890 decision_result->Clear();
893 decision_result->mutable_main_decision()->mutable_cruise();
896 int error_code = MakeMainStopDecision(decision_result);
897 if (error_code < 0) {
898 MakeEStopDecision(decision_result);
900 MakeMainMissionCompleteDecision(decision_result, planning_context);
901 SetObjectDecisions(decision_result->mutable_object_decision());
904void ReferenceLineInfo::MakeMainMissionCompleteDecision(
905 DecisionResult* decision_result, PlanningContext* planning_context)
const {
906 if (!decision_result->main_decision().has_stop()) {
909 auto main_stop = decision_result->main_decision().stop();
910 if (main_stop.reason_code() != STOP_REASON_DESTINATION &&
911 main_stop.reason_code() != STOP_REASON_PULL_OVER &&
912 main_stop.reason_code() != STOP_REASON_REFERENCE_END) {
917 if (distance_destination > FLAGS_destination_check_distance &&
918 distance_to_reference_end > FLAGS_destination_check_distance) {
922 auto mission_complete =
923 decision_result->mutable_main_decision()->mutable_mission_complete();
925 planning_context->mutable_planning_status()
926 ->mutable_destination()
927 ->set_has_passed_destination(
true);
929 mission_complete->mutable_stop_point()->CopyFrom(main_stop.stop_point());
930 mission_complete->set_stop_heading(main_stop.stop_heading());
934int ReferenceLineInfo::MakeMainStopDecision(
935 DecisionResult* decision_result)
const {
936 double min_stop_line_s = std::numeric_limits<double>::infinity();
937 const Obstacle* stop_obstacle =
nullptr;
938 const ObjectStop* stop_decision =
nullptr;
940 for (
const auto* obstacle : path_decision_.obstacles().Items()) {
942 if (!object_decision.has_stop()) {
947 common::SLPoint stop_line_sl;
948 reference_line_.
XYToSL(stop_point, &stop_line_sl);
950 double stop_line_s = stop_line_sl.s();
951 if (stop_line_s < 0 || stop_line_s > reference_line_.
Length()) {
952 AERROR <<
"Ignore object:" << obstacle->
Id() <<
" fence route_s["
953 << stop_line_s <<
"] not in range[0, " << reference_line_.
Length()
959 if (stop_line_s < min_stop_line_s) {
960 min_stop_line_s = stop_line_s;
961 stop_obstacle = obstacle;
962 stop_decision = &(object_decision.stop());
966 if (stop_obstacle !=
nullptr) {
967 MainStop* main_stop =
968 decision_result->mutable_main_decision()->mutable_stop();
969 main_stop->set_reason_code(stop_decision->reason_code());
970 main_stop->set_reason(
"stop by " + stop_obstacle->Id());
971 main_stop->mutable_stop_point()->set_x(stop_decision->stop_point().x());
972 main_stop->mutable_stop_point()->set_y(stop_decision->stop_point().y());
973 main_stop->set_stop_heading(stop_decision->stop_heading());
975 ADEBUG <<
" main stop obstacle id:" << stop_obstacle->
Id()
976 <<
" stop_line_s:" << min_stop_line_s <<
" stop_point: ("
977 << stop_decision->stop_point().x() << stop_decision->stop_point().y()
978 <<
" ) stop_heading: " << stop_decision->stop_heading();
986void ReferenceLineInfo::SetObjectDecisions(
987 ObjectDecisions* object_decisions)
const {
988 for (
const auto obstacle : path_decision_.obstacles().Items()) {
992 auto* object_decision = object_decisions->add_decision();
994 object_decision->set_id(obstacle->
Id());
995 object_decision->set_perception_id(obstacle->
PerceptionId());
997 object_decision->add_object_decision()->CopyFrom(
1002 object_decision->add_object_decision()->CopyFrom(
1011 static constexpr double kMaxAngleDiff = M_PI / 6.0;
1013 bool engage =
false;
1015 prev_advice.set_reason(
"Reference line not drivable");
1016 }
else if (!is_on_reference_line_) {
1017 const auto& scenario_type =
1026 prev_advice.set_reason(
"Not on reference line");
1036 prev_advice.set_reason(
"Vehicle heading is not aligned");
1042 Chassis::DrivingMode::Chassis_DrivingMode_COMPLETE_AUTO_DRIVE) {
1049 prev_advice.clear_reason();
1055 engage_advice->CopyFrom(prev_advice);
1058void ReferenceLineInfo::MakeEStopDecision(
1059 DecisionResult* decision_result)
const {
1060 decision_result->Clear();
1062 MainEmergencyStop* main_estop =
1063 decision_result->mutable_main_decision()->mutable_estop();
1064 main_estop->set_reason_code(MainEmergencyStop::ESTOP_REASON_INTERNAL_ERR);
1065 main_estop->set_reason(
"estop reason to be added");
1066 main_estop->mutable_cruise_to_stop();
1069 ObjectDecisions* object_decisions =
1070 decision_result->mutable_object_decision();
1071 for (
const auto obstacle : path_decision_.obstacles().Items()) {
1072 auto* object_decision = object_decisions->add_decision();
1073 object_decision->set_id(obstacle->
Id());
1074 object_decision->set_perception_id(obstacle->
PerceptionId());
1075 object_decision->add_object_decision()->mutable_avoid();
1080 const double forward_buffer = 20.0;
1081 double route_s = 0.0;
1082 for (
const auto& seg :
Lanes()) {
1083 if (route_s > s + forward_buffer) {
1086 route_s += seg.end_s - seg.start_s;
1090 const auto& turn_type = seg.lane->lane().turn();
1113 CHECK_NOTNULL(pnc_junction_overlap);
1114 const std::vector<hdmap::PathOverlap>& pnc_junction_overlaps =
1117 static constexpr double kError = 1.0;
1118 for (
const auto& overlap : pnc_junction_overlaps) {
1119 if (s >= overlap.start_s - kError && s <= overlap.end_s + kError) {
1120 *pnc_junction_overlap = overlap;
1129 CHECK_NOTNULL(junction_overlap);
1130 const std::vector<hdmap::PathOverlap>& junction_overlaps =
1133 static constexpr double kError = 1.0;
1134 for (
const auto& overlap : junction_overlaps) {
1135 if (s >= overlap.start_s - kError && s <= overlap.end_s + kError) {
1136 *junction_overlap = overlap;
1145 CHECK_NOTNULL(area_overlap);
1146 const std::vector<hdmap::PathOverlap>& area_overlaps =
1149 static constexpr double kError = 1.0;
1150 for (
const auto& overlap : area_overlaps) {
1151 if (s >= overlap.start_s - kError && s <= overlap.end_s + kError) {
1152 *area_overlap = overlap;
1160 const std::string& blocking_obstacle_id) {
1161 blocking_obstacle_ = path_decision_.
Find(blocking_obstacle_id);
1166 std::vector<common::SLPoint> result;
1167 for (
const auto* obstacle : path_decision_.
obstacles().
Items()) {
1169 if (!object_decision.has_stop()) {
1174 reference_line_.
XYToSL(stop_point, &stop_line_sl);
1175 if (stop_line_sl.
s() <= 0 || stop_line_sl.
s() >= reference_line_.
Length()) {
1178 result.push_back(stop_line_sl);
1182 if (!result.empty()) {
1183 std::sort(result.begin(), result.end(),
1185 return a.s() < b.s();
1193 const std::string& overlap_id,
const OverlapType& overlap_type)
const {
1196 const auto& traffic_light_overlaps =
1198 for (
const auto& traffic_light_overlap : traffic_light_overlaps) {
1199 if (traffic_light_overlap.object_id == overlap_id) {
1205 const auto& stop_sign_overlaps =
1207 for (
const auto& stop_sign_overlap : stop_sign_overlaps) {
1208 if (stop_sign_overlap.object_id == overlap_id) {
1214 const auto& pnc_junction_overlaps =
1216 for (
const auto& pnc_junction_overlap : pnc_junction_overlaps) {
1217 if (pnc_junction_overlap.object_id == overlap_id) {
1223 const auto& yield_sign_overlaps =
1225 for (
const auto& yield_sign_overlap : yield_sign_overlaps) {
1226 if (yield_sign_overlap.object_id == overlap_id) {
1232 const auto& junction_overlaps =
1234 for (
const auto& junction_overlap : junction_overlaps) {
1235 if (junction_overlap.object_id == overlap_id) {
1242 for (
const auto& area_overlap : area_overlaps) {
1243 if (area_overlap.object_id == overlap_id) {
1252 return &candidate_path_data_;
1256 std::vector<hdmap::PathOverlap>* path_overlaps,
double start_s,
1258 CHECK_NOTNULL(path_overlaps);
1259 const std::vector<hdmap::PathOverlap>& junction_overlaps =
1262 static constexpr double kError = 0.1;
1263 AINFO <<
"GetRangeOverlaps start_s: " << start_s <<
", end_s: " << end_s;
1264 for (
const auto& overlap : junction_overlaps) {
1265 if (start_s >= overlap.end_s - kError) {
1267 }
else if (end_s < overlap.start_s - kError) {
1270 AINFO <<
"overlap emplace_back " << overlap.start_s <<
", "
1271 << overlap.end_s <<
" ]";
1272 path_overlaps->emplace_back(overlap);
1278 return reference_line_towing_l_;
1282 return &reference_line_towing_l_;
1287 return reference_line_towing_path_boundary_;
1291 return &reference_line_towing_path_boundary_;
1295 return obs_sl_polygons_;
1299 return &obs_sl_polygons_;
1305 for (
size_t i = 0; i < lane_segments.size(); ++i) {
1306 for (
const auto& seg :
1307 lane_segments.at(i).lane->lane().left_boundary().curve().segment()) {
1308 for (
const auto& pt : seg.line_segment().point()) {
1309 print_curve.
AddPoint(std::to_string(index_) +
"_left_pt_print", pt.x(),
1313 for (
const auto& seg :
1314 lane_segments.at(i).lane->lane().right_boundary().curve().segment()) {
1315 for (
const auto& pt : seg.line_segment().point()) {
1316 print_curve.
AddPoint(std::to_string(index_) +
"_right_pt_print", pt.x(),
1320 for (
const auto& pt : lane_segments.at(i).lane->points()) {
1321 print_curve.
AddPoint(std::to_string(index_) +
"_center_pt_print", pt.x(),
@Brief This is a helper class that can load vehicle configurations.
static const VehicleConfig & GetConfig()
Get the current vehicle configuration.
Rectangular (undirected) bounding box in 2-D.
std::string DebugString() const
Gets a human-readable description of the box
Implements a class of 2-dimensional vectors.
Vec2d rotate(const double angle) const
rotate the vector by angle.
static math::Vec2d ToVec2d(const XY &xy)
static const HDMap * BaseMapPtr()
LaneInfoConstPtr GetLaneById(const Id &id) const
const std::vector< PathOverlap > & area_overlaps() const
const std::vector< PathOverlap > & junction_overlaps() const
const std::vector< PathOverlap > & signal_overlaps() const
const std::vector< PathOverlap > & yield_sign_overlaps() const
const std::vector< PathOverlap > & pnc_junction_overlaps() const
const std::vector< PathOverlap > & stop_sign_overlaps() const
const std::vector< LaneSegment > & lane_segments() const
bool IsNeighborSegment() const
void SetIsReversed(const bool flag)
virtual void AppendTrajectoryPoint(const common::TrajectoryPoint &trajectory_point)
virtual common::TrajectoryPoint Evaluate(const double relative_time) const
const std::vector< const T * > & Items() const
List all the items in the container.
This is the class that associates an Obstacle with its path properties.
std::string DebugString() const
bool IsLongitudinalIgnore() const
const ObjectDecisionType & LateralDecision() const
return the merged lateral decision Lateral decision is one of {Nudge, Ignore}
bool HasLongitudinalDecision() const
const ObjectDecisionType & LongitudinalDecision() const
return the merged longitudinal decision Longitudinal decision is one of {Stop, Yield,...
const std::string & Id() const
int32_t PerceptionId() const
bool IsCautionLevelObstacle() const
bool IsLateralIgnore() const
bool HasLateralDecision() const
bool HasNonIgnoreDecision() const
const SLBoundary & PerceptionSLBoundary() const
const common::math::Polygon2d & PerceptionPolygon() const
bool is_reverse_path() const
const std::string & path_label() const
common::PathPoint GetPathPointWithPathS(const double s) const
std::string DebugString() const
const DiscretizedPath & discretized_path() const
PathDecision represents all obstacle decisions on one path.
const Obstacle * Find(const std::string &object_id) const
const IndexedList< std::string, Obstacle > & obstacles() const
bool AddLateralDecision(const std::string &tag, const std::string &object_id, const ObjectDecisionType &decision)
bool AddLongitudinalDecision(const std::string &tag, const std::string &object_id, const ObjectDecisionType &decision)
Obstacle * AddObstacle(const Obstacle &obstacle)
const PlanningStatus & planning_status() const
void AddPoint(std::string key, double x, double y)
add point to curve key
ReferenceLineInfo holds all data for one reference line.
void SetBlockingObstacle(const std::string &blocking_obstacle_id)
std::list< hdmap::Id > TargetLaneId() const
std::vector< double > * mutable_reference_line_towing_l()
void GetRangeOverlaps(std::vector< hdmap::PathOverlap > *path_overlaps, double start_s, double end_s)
const PathBoundary & reference_line_towing_path_boundary() const
PathDecision * path_decision()
void SetCandidatePathData(std::vector< PathData > &&candidate_path_data)
void SetTrajectory(const DiscretizedTrajectory &trajectory)
const std::vector< SLPolygon > & obs_sl_polygons() const
double SDistanceToRefEnd() const
void SetLatticeStopPoint(const StopPoint &stop_point)
bool GetNeighborLaneInfo(const ReferenceLineInfo::LaneType lane_type, const double s, hdmap::Id *ptr_lane_id, double *ptr_lane_width) const
int GetJunction(const double s, hdmap::PathOverlap *junction_overlap) const
const std::vector< PathData > & GetCandidatePathData() const
void SetLatticeCruiseSpeed(double speed)
hdmap::Lane::LaneTurn GetPathTurnType(const double s) const
void SetDrivable(bool drivable)
Set if the vehicle can drive following this reference line A planner need to set this value to true i...
const SpeedData & speed_data() const
const std::vector< PathBoundary > & GetCandidatePathBoundaries() const
SpeedData * mutable_speed_data()
bool AddObstacles(const std::vector< const Obstacle * > &obstacles)
bool CombinePathAndSpeedProfile(const double relative_time, const double start_s, DiscretizedTrajectory *discretized_trajectory)
bool IsNeighborLanePath() const
Check if the current reference line is the neighbor of the vehicle current position
double GetCruiseSpeed() const
void ExportDecision(DecisionResult *decision_result, PlanningContext *planning_context) const
const RSSInfo & rss_info() const
const std::vector< double > & reference_line_towing_l() const
bool GetIntersectionRightofWayStatus(const hdmap::PathOverlap &pnc_junction_overlap) const
std::vector< SLPolygon > * mutable_obs_sl_polygons()
void LimitCruiseSpeed(double speed)
Limit the cruise speed based on the "base_cruise_speed_".
void SetTurnSignal(const common::VehicleSignal::TurnSignal &turn_signal)
PathBoundary * mutable_reference_line_towing_path_boundary()
RSSInfo * mutable_rss_info()
void SetCruiseSpeed(double speed)
bool IsStartFrom(const ReferenceLineInfo &previous_reference_line_info) const
check if current reference line is started from another reference line info line.
const hdmap::RouteSegments & Lanes() const
bool Init(const std::vector< const Obstacle * > &obstacles, double target_speed)
ADCTrajectory::RightOfWayStatus GetRightOfWayStatus() const
const ReferenceLine & reference_line() const
std::vector< common::SLPoint > GetAllStopDecisionSLPoint() const
hdmap::PathOverlap * GetOverlapOnReferenceLine(const std::string &overlap_id, const OverlapType &overlap_type) const
const PathData & path_data() const
const PathData & fallback_path_data() const
void SetCandidatePathBoundaries(std::vector< PathBoundary > &&candidate_path_boundaries)
void ExportEngageAdvice(common::EngageAdvice *engage_advice, PlanningContext *planning_context) const
const DiscretizedTrajectory & trajectory() const
double GetBaseCruiseSpeed() const
PathData * mutable_fallback_path_data()
Obstacle * AddObstacle(const Obstacle *obstacle)
double SDistanceToDestination() const
hdmap::LaneInfoConstPtr LocateLaneInfo(const double s) const
std::vector< PathData > * MutableCandidatePathData()
const SLBoundary & AdcSlBoundary() const
int GetArea(const double s, hdmap::PathOverlap *area_overlap) const
void SetJunctionRightOfWay(const double junction_s, const bool is_protected) const
bool AdjustTrajectoryWhichStartsFromCurrentPos(const common::TrajectoryPoint &planning_start_point, const std::vector< common::TrajectoryPoint > &trajectory, DiscretizedTrajectory *adjusted_trajectory)
bool IsChangeLanePath() const
Check if the current reference line is a change lane reference line, i.e., ADC's current position is ...
ReferenceLineInfo()=default
ReferenceLine * mutable_reference_line()
bool ReachedDestination() const
void PrintReferenceSegmentDebugString()
PathData * mutable_path_data()
int GetPnCJunction(const double s, hdmap::PathOverlap *pnc_junction_overlap) const
std::string PathSpeedDebugString() const
const hdmap::Path & GetMapPath() const
const hdmap::Path & map_path() const
bool IsOnLane(const common::SLPoint &sl_point) const
: check if a box/point is on lane along reference line
void AddSpeedLimit(double start_s, double end_s, double speed_limit)
ReferencePoint GetReferencePoint(const double s) const
bool GetSLBoundary(const common::math::Box2d &box, SLBoundary *const sl_boundary, double warm_start_s=-1.0) const
Get the SL Boundary of the box.
void GetLaneFromS(const double s, std::vector< hdmap::LaneInfoConstPtr > *lanes) const
bool XYToSL(const common::math::Vec2d &xy_point, common::SLPoint *const sl_point, double warm_start_s=-1.0) const
Transvert Cartesian coordinates to Frenet.
bool GetLaneWidth(const double s, double *const lane_left_width, double *const lane_right_width) const
const std::vector< ReferencePoint > & reference_points() const
virtual std::string DebugString() const
bool EvaluateByTime(const double time, common::SpeedPoint *const speed_point) const
Planning module main class.
double AngleDiff(const double from, const double to)
Calculate the difference between angle from and to
std::size_t Hash(const std::string &key)
std::shared_ptr< const LaneInfo > LaneInfoConstPtr
bool WithinOverlap(const hdmap::PathOverlap &overlap, double s)
optional double relative_time
optional PathPoint path_point
optional VehicleParam vehicle_param
optional apollo::canbus::Chassis::DrivingMode driving_mode
optional ScenarioStatus scenario
optional string scenario_type