39 GenerateFallbackPath(frame, reference_line_info);
41 if (reference_line_info->
speed_data().empty()) {
42 AERROR <<
"Speed fallback due to algorithm failure";
44 injector_->ego_info(), FLAGS_speed_fallback_distance);
56void TrajectoryFallbackTask::GenerateFallbackPath(
60 AERROR <<
"Path fallback due to algorithm failure";
61 GenerateFallbackPathProfile(reference_line_info,
70 if (!RetrieveLastFramePathProfile(
71 reference_line_info, frame,
73 const auto& candidate_path_data =
75 for (
const auto& path_data : candidate_path_data) {
76 if (path_data.path_label().find(
"self") != std::string::npos) {
78 AERROR <<
"Use current frame self lane path as fallback ";
86void TrajectoryFallbackTask::GenerateFallbackPathProfile(
87 const ReferenceLineInfo* reference_line_info, PathData* path_data) {
88 const double unit_s = 1.0;
89 const auto& reference_line = reference_line_info->reference_line();
91 auto adc_point =
injector_->ego_info()->start_point();
92 DCHECK(adc_point.has_path_point());
93 const auto adc_point_x = adc_point.path_point().x();
94 const auto adc_point_y = adc_point.path_point().y();
96 common::SLPoint adc_point_s_l;
97 if (!reference_line.XYToSL(adc_point.path_point(), &adc_point_s_l)) {
98 AERROR <<
"Fail to project ADC to reference line when calculating path "
99 "fallback. Straight forward path is generated";
100 const auto adc_point_heading = adc_point.path_point().theta();
101 const auto adc_point_kappa = adc_point.path_point().kappa();
102 const auto adc_point_dkappa = adc_point.path_point().dkappa();
103 std::vector<common::PathPoint> path_points;
104 double adc_traversed_x = adc_point_x;
105 double adc_traversed_y = adc_point_y;
107 const double max_s = 100.0;
108 for (
double s = 0; s < max_s; s += unit_s) {
110 adc_traversed_x, adc_traversed_y, 0.0, s, adc_point_heading,
111 adc_point_kappa, adc_point_dkappa));
112 adc_traversed_x += unit_s * std::cos(adc_point_heading);
113 adc_traversed_y += unit_s * std::sin(adc_point_heading);
115 path_data->SetDiscretizedPath(DiscretizedPath(std::move(path_points)));
120 const auto adc_s = adc_point_s_l.s();
121 const auto& adc_ref_point =
122 reference_line.GetReferencePoint(adc_point_x, adc_point_y);
123 const double dx = adc_point_x - adc_ref_point.x();
124 const double dy = adc_point_y - adc_ref_point.y();
126 std::vector<common::PathPoint> path_points;
127 const double max_s = reference_line.Length();
128 for (
double s = adc_s; s < max_s; s += unit_s) {
129 const auto& ref_point = reference_line.GetReferencePoint(s);
131 ref_point.x() + dx, ref_point.y() + dy, 0.0, s - adc_s,
132 ref_point.heading(), ref_point.kappa(), ref_point.dkappa()));
134 path_data->SetDiscretizedPath(DiscretizedPath(std::move(path_points)));
137bool TrajectoryFallbackTask::RetrieveLastFramePathProfile(
138 const ReferenceLineInfo* reference_line_info,
const Frame* frame,
139 PathData* path_data) {
140 const auto* ptr_last_frame =
injector_->frame_history()->Latest();
141 if (ptr_last_frame ==
nullptr) {
143 <<
"Last frame doesn't succeed, fail to retrieve last frame path data";
147 const auto& last_frame_discretized_path =
148 ptr_last_frame->current_frame_planned_path();
150 path_data->SetDiscretizedPath(last_frame_discretized_path);
151 const auto adc_frenet_frame_point_ =
152 reference_line_info->reference_line().GetFrenetPoint(
153 frame->PlanningStartPoint().path_point());
155 bool trim_success = path_data->LeftTrimWithRefS(adc_frenet_frame_point_);
157 AERROR <<
"Fail to trim path_data. adc_frenet_frame_point: "
158 << adc_frenet_frame_point_.ShortDebugString();
161 AERROR <<
"Use last frame good path to do speed fallback";
165void TrajectoryFallbackTask::AmendSpeedDataForControl(
166 SpeedData* speed_data_ptr) {
170 SpeedData& speed_data = *speed_data_ptr;
171 const int speed_data_num = speed_data.size();
172 int modify_index = speed_data_num - 1;
173 for (; modify_index >= 0; --modify_index) {
174 auto& data = speed_data[modify_index];
175 if (data.v() < FLAGS_near_stop_speed && data.a() <= 0.0 &&
176 data.a() > FLAGS_near_stop_deceleration) {
177 data.set_a(FLAGS_near_stop_deceleration);
182 if (modify_index < 0) {
186 double pre_s = speed_data[modify_index].s();
187 double pre_v = speed_data[modify_index].v();
190 const double unit_t = FLAGS_fallback_time_unit;
191 for (
int i = modify_index + 1; i < speed_data_num; ++i) {
193 v = std::fmax(0.0, pre_v + unit_t * FLAGS_near_stop_deceleration);
194 s = std::fmax(pre_s, pre_s + 0.5 * (pre_v + (pre_v + v)) * unit_t);
199 speed_data[i].set_v(v);
200 speed_data[i].set_s(s);
A general class to denote the return status of an API call.
static Status OK()
generate a success status.
static PathPoint ToPathPoint(const double x, const double y, const double z=0, const double s=0, const double theta=0, const double kappa=0, const double dkappa=0, const double ddkappa=0)
Frame holds all data for one planning cycle.
ReferenceLineInfo holds all data for one reference line.
void AddCost(double cost)
const std::vector< PathData > & GetCandidatePathData() const
void set_trajectory_type(const ADCTrajectory::TrajectoryType trajectory_type)
const SpeedData & speed_data() const
SpeedData * mutable_speed_data()
const PathData & path_data() const
ADCTrajectory::TrajectoryType trajectory_type() const
PathData * mutable_path_data()
std::shared_ptr< DependencyInjector > injector_
virtual common::Status Execute(Frame *frame, ReferenceLineInfo *reference_line_info)
common::Status Execute(Frame *frame, ReferenceLineInfo *reference_line_info) override
Planning module main class.
constexpr double kSpeedOptimizationFallbackCost
constexpr double kPathOptimizationFallbackCost