Apollo 11.0
自动驾驶开放平台
fast_stop_trajectory_fallback.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
18
19#include <utility>
20#include <vector>
21
24
25namespace apollo {
26namespace planning {
27
28SpeedData FastStopTrajectoryFallback::GenerateFallbackSpeed(
29 const EgoInfo* ego_info, const double stop_distance) {
30 AERROR << "Fallback using piecewise jerk speed!";
31 const double init_v = ego_info->start_point().v();
32 const double init_a = ego_info->start_point().a();
33 AWARN << "init_v = " << init_v << ", init_a = " << init_a;
34 const auto& veh_param =
36
37 // if already stopped
38 if (init_v <= 0.0 && init_a <= 0.0) {
39 AWARN << "Already stopped! Nothing to do in GenerateFallbackSpeed()";
40 SpeedData speed_data;
41 speed_data.AppendSpeedPoint(0.0, 0.0, 0.0, 0.0, 0.0);
43 return speed_data;
44 }
45
46 std::array<double, 3> init_s = {0.0, init_v, init_a};
47
48 // TODO(all): dt is too small;
49 double delta_t = FLAGS_fallback_time_unit;
50 double total_time = FLAGS_fallback_total_time;
51 const size_t num_of_knots = static_cast<size_t>(total_time / delta_t) + 1;
52
53 PiecewiseJerkSpeedProblem piecewise_jerk_problem(num_of_knots, delta_t,
54 init_s);
55
56 std::vector<double> end_state_ref(num_of_knots, stop_distance);
57 piecewise_jerk_problem.set_x_ref(1.0, std::move(end_state_ref));
58
59 piecewise_jerk_problem.set_scale_factor({1.0, 10.0, 100.0});
60
61 piecewise_jerk_problem.set_x_bounds(0.0, std::fmin(stop_distance, 100.0));
62 piecewise_jerk_problem.set_dx_bounds(
63 0.0, std::fmin(FLAGS_planning_upper_speed_limit, init_v));
64 piecewise_jerk_problem.set_ddx_bounds(veh_param.max_deceleration(), 0.0);
65 piecewise_jerk_problem.set_dddx_bound(FLAGS_longitudinal_jerk_lower_bound,
66 0.0);
67
68 // Solve the problem
69 if (!piecewise_jerk_problem.Optimize()) {
70 AERROR << "Piecewise jerk fallback speed optimizer failed!";
71 return GenerateStopProfile(init_v, init_a);
72 }
73
74 // Extract output
75 const std::vector<double>& s = piecewise_jerk_problem.opt_x();
76 const std::vector<double>& ds = piecewise_jerk_problem.opt_dx();
77 const std::vector<double>& dds = piecewise_jerk_problem.opt_ddx();
78
79 for (size_t i = 0; i < num_of_knots; ++i) {
80 ADEBUG << "For[" << delta_t * static_cast<double>(i) << "], s = " << s[i]
81 << ", v = " << ds[i] << ", a = " << dds[i];
82 }
83
84 SpeedData speed_data;
85 speed_data.AppendSpeedPoint(s[0], 0.0, ds[0], dds[0], 0.0);
86 for (size_t i = 1; i < num_of_knots; ++i) {
87 // Avoid the very last points when already stopped
88 if (s[i] - s[i - 1] <= 0.0 || ds[i] <= 0.0) {
89 break;
90 }
91 speed_data.AppendSpeedPoint(s[i], delta_t * static_cast<double>(i), ds[i],
92 dds[i], (dds[i] - dds[i - 1]) / delta_t);
93 }
95 return speed_data;
96}
97
98SpeedData FastStopTrajectoryFallback::GenerateStopProfile(
99 const double init_speed, const double init_acc) {
100 AERROR << "Slowing down the car within a constant deceleration with fallback "
101 "stopping profile.";
102 SpeedData speed_data;
103
104 const double max_t = FLAGS_fallback_total_time;
105 const double unit_t = FLAGS_fallback_time_unit;
106
107 double pre_s = 0.0;
108 double pre_v = init_speed;
109 double s = 0.0;
110 double v = 0.0;
111 double acc = FLAGS_slowdown_profile_deceleration;
112 speed_data.AppendSpeedPoint(0.0, 0.0, init_speed, init_acc, 0.0);
113 for (double t = unit_t; t < max_t; t += unit_t) {
114 v = std::fmax(0.0, pre_v + unit_t * acc);
115 s = std::fmax(pre_s, pre_s + 0.5 * (pre_v + (pre_v + v)) * unit_t);
116 speed_data.AppendSpeedPoint(s, t, v, acc, 0.0);
117 pre_s = s;
118 pre_v = v;
119 }
121 return speed_data;
122}
123
124} // namespace planning
125} // namespace apollo
static const VehicleConfig & GetConfig()
Get the current vehicle configuration.
static void FillEnoughSpeedPoints(SpeedData *const speed_data)
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AWARN
Definition log.h:43
class register implement
Definition arena_queue.h:37
optional VehicleParam vehicle_param