26#include "modules/common_msgs/basic_msgs/pnc_point.pb.h"
38 const std::shared_ptr<DependencyInjector>& injector) {
43 return TrafficRule::LoadConfig<ReroutingConfig>(&config_);
46bool Rerouting::ChangeLaneFailRerouting() {
47 static constexpr double kRerouteThresholdToEnd = 20.0;
48 for (
const auto& ref_line_info : frame_->reference_line_info()) {
49 if (ref_line_info.ReachedDestination() ||
50 ref_line_info.SDistanceToDestination() < kRerouteThresholdToEnd) {
54 const auto& segments = reference_line_info_->
Lanes();
62 if (!segments.IsOnSegment()) {
67 if (segments.CanExit()) {
73 if (!route_end_waypoint.lane) {
76 auto point = route_end_waypoint.
lane->GetSmoothPoint(route_end_waypoint.s);
77 const auto& reference_line = reference_line_info_->
reference_line();
78 common::SLPoint sl_point;
79 if (!reference_line.XYToSL(point, &sl_point)) {
80 AERROR <<
"Failed to project point: " << point.ShortDebugString();
83 if (!reference_line.IsOnLane(sl_point)) {
89 const auto vehicle_state =
injector_->vehicle_state();
90 double speed = vehicle_state->linear_velocity();
92 const double prepare_distance = speed * prepare_rerouting_time;
93 if (sl_point.s() > adc_s + prepare_distance) {
94 ADEBUG <<
"No need rerouting now because still can drive for time: "
95 << prepare_rerouting_time <<
" seconds";
99 auto* rerouting =
injector_->planning_context()
100 ->mutable_planning_status()
101 ->mutable_rerouting();
102 if (rerouting ==
nullptr) {
103 AERROR <<
"rerouting is nullptr.";
107 if (rerouting->has_last_rerouting_time() &&
108 (current_time - rerouting->last_rerouting_time() <
110 ADEBUG <<
"Skip rerouting and wait for previous rerouting result";
114 AERROR <<
"Failed to send rerouting request";
119 rerouting->set_last_rerouting_time(current_time);
126 reference_line_info_ = reference_line_info;
127 if (!ChangeLaneFailRerouting()) {
129 "In un-successful lane change case, rerouting failed");
A general class to denote the return status of an API call.
static Status OK()
generate a success status.
a singleton clock that can be used to get the current timestamp.
static double NowInSeconds()
gets the current time in second.
const LaneWaypoint & RouteEndWaypoint() const
Frame holds all data for one planning cycle.
bool Rerouting(PlanningContext *planning_context)
ReferenceLineInfo holds all data for one reference line.
const hdmap::RouteSegments & Lanes() const
const ReferenceLine & reference_line() const
const SLBoundary & AdcSlBoundary() const
common::Status ApplyRule(Frame *const frame, ReferenceLineInfo *const reference_line_info)
bool Init(const std::string &name, const std::shared_ptr< DependencyInjector > &injector) override
virtual bool Init(const std::string &name, const std::shared_ptr< DependencyInjector > &injector)
std::shared_ptr< DependencyInjector > injector_
Planning module main class.
optional double prepare_rerouting_time
optional double cooldown_time