Apollo 11.0
自动驾驶开放平台
quintic_spiral_path.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 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
22
23namespace apollo {
24namespace planning {
25
26QuinticSpiralPath::QuinticSpiralPath(const double x0, const double dx0,
27 const double ddx0, const double x1,
28 const double dx1, const double ddx1,
29 const double p)
30 : QuinticPolynomialCurve1d(x0, dx0, ddx0, x1, dx1, ddx1, p) {
31 ACHECK(p > 0.0);
32
33 double p2 = p * p;
34 double p3 = p2 * p;
35 double p4 = p3 * p;
36 double p5 = p2 * p3;
37 double p6 = p3 * p3;
38
39 // derive a
40 // double a = -6.0 * x0 / p5 - 3.0 * dx0 / p4 - 0.5 * ddx0 / p3 + 6.0 * x1 /
41 // p5 - 3.0 * dx1 / p4 + 0.5 * ddx1 / p3;
42 coef_deriv_[5][0] = -6.0 / p5;
43
44 coef_deriv_[5][1] = -3.0 / p4;
45
46 coef_deriv_[5][2] = -0.5 / p3;
47
48 coef_deriv_[5][3] = 6.0 / p5;
49
50 coef_deriv_[5][4] = -3.0 / p4;
51
52 coef_deriv_[5][5] = 0.5 / p3;
53
54 coef_deriv_[5][6] = 30.0 * x0 / p6 + 12.0 * dx0 / p5 + 1.5 * ddx0 / p4 -
55 30.0 * x1 / p6 + 12.0 * dx1 / p5 - 1.5 * ddx1 / p4;
56
57 // derive b
58 // double b = 15.0 * x0 / p4 + 8.0 * dx0 / p3 + 1.5 * ddx0 / p2 - 15.0 * x1 /
59 // p4 + 7.0 * dx1 / p3 - ddx1 / p2;
60 coef_deriv_[4][0] = 15.0 / p4;
61
62 coef_deriv_[4][1] = 8.0 / p3;
63
64 coef_deriv_[4][2] = 1.5 / p2;
65
66 coef_deriv_[4][3] = -15.0 / p4;
67
68 coef_deriv_[4][4] = 7.0 / p3;
69
70 coef_deriv_[4][5] = -1.0 / p2;
71
72 coef_deriv_[4][6] = -60.0 * x0 / p5 - 24.0 * dx0 / p4 - 3.0 * ddx0 / p3 +
73 60.0 * x1 / p5 - 21.0 * dx1 / p4 + 2.0 * ddx1 / p3;
74
75 // derive c
76 // double c = -10.0 * x0 / p3 - 6.0 * dx0 / p2 - 1.5 * ddx0 / p + 10.0 * x1 /
77 // p3 - 4.0 * dx1 / p2 + 0.5 * ddx1 / p;
78 coef_deriv_[3][0] = -10.0 / p3;
79
80 coef_deriv_[3][1] = -6.0 / p2;
81
82 coef_deriv_[3][2] = -1.5 / p;
83
84 coef_deriv_[3][3] = 10.0 / p3;
85
86 coef_deriv_[3][4] = -4.0 / p2;
87
88 coef_deriv_[3][5] = 0.5 / p;
89
90 coef_deriv_[3][6] = 30.0 * x0 / p4 + 12.0 * dx0 / p3 + 1.5 * ddx0 / p2 -
91 30.0 * x1 / p4 + 8.0 * dx1 / p3 - 0.5 * ddx1 / p2;
92
93 // derive d
94 // double d = 0.5 * ddx0;
95 coef_deriv_[2][0] = 0.0;
96
97 coef_deriv_[2][1] = 0.0;
98
99 coef_deriv_[2][2] = 0.5;
100
101 coef_deriv_[2][3] = 0.0;
102
103 coef_deriv_[2][4] = 0.0;
104
105 coef_deriv_[2][5] = 0.0;
106
107 coef_deriv_[2][6] = 0.0;
108
109 // derive e
110 // double e = dx0;
111 coef_deriv_[1][0] = 0.0;
112
113 coef_deriv_[1][1] = 1.0;
114
115 coef_deriv_[1][2] = 0.0;
116
117 coef_deriv_[1][3] = 0.0;
118
119 coef_deriv_[1][4] = 0.0;
120
121 coef_deriv_[1][5] = 0.0;
122
123 coef_deriv_[1][6] = 0.0;
124
125 // derive f
126 // double f = x0;
127 coef_deriv_[0][0] = 1.0;
128
129 coef_deriv_[0][1] = 0.0;
130
131 coef_deriv_[0][2] = 0.0;
132
133 coef_deriv_[0][3] = 0.0;
134
135 coef_deriv_[0][4] = 0.0;
136
137 coef_deriv_[0][5] = 0.0;
138
139 coef_deriv_[0][6] = 0.0;
140}
141
142QuinticSpiralPath::QuinticSpiralPath(const std::array<double, 3>& start,
143 const std::array<double, 3>& end,
144 const double delta_s)
145 : QuinticSpiralPath(start[0], start[1], start[2], end[0], end[1], end[2],
146 delta_s) {}
147
148double QuinticSpiralPath::DeriveTheta(const size_t param_index,
149 const double r) const {
150 double s = param_ * r;
151 double s2 = s * s;
152 double s3 = s2 * s;
153 double s4 = s2 * s2;
154 double s5 = s3 * s2;
155
156 double derivative =
157 coef_deriv_[5][param_index] * s5 + coef_deriv_[4][param_index] * s4 +
158 coef_deriv_[3][param_index] * s3 + coef_deriv_[2][param_index] * s2 +
159 coef_deriv_[1][param_index] * s + coef_deriv_[0][param_index];
160
161 if (param_index == DELTA_S) {
162 derivative += coef_[5] * 5.0 * s4 * r + coef_[4] * 4.0 * s3 * r +
163 coef_[3] * 3.0 * s2 * r + coef_[2] * 2.0 * s * r +
164 coef_[1] * r;
165 }
166 return derivative;
167}
168
169double QuinticSpiralPath::DeriveKappaDerivative(const size_t param_index,
170 const double r) const {
171 double s = param_ * r;
172 double s2 = s * s;
173 double s3 = s2 * s;
174 double s4 = s2 * s2;
175
176 double derivative = 5.0 * coef_deriv_[5][param_index] * s4 +
177 4.0 * coef_deriv_[4][param_index] * s3 +
178 3.0 * coef_deriv_[3][param_index] * s2 +
179 2.0 * coef_deriv_[2][param_index] * s +
180 coef_deriv_[1][param_index];
181
182 if (param_index == DELTA_S) {
183 derivative += 5.0 * coef_[5] * 4.0 * s3 * r +
184 4.0 * coef_[4] * 3.0 * s2 * r + 3.0 * coef_[3] * 2.0 * s * r +
185 2.0 * coef_[2] * r;
186 }
187 return derivative;
188}
189
190double QuinticSpiralPath::DeriveDKappaDerivative(const size_t param_index,
191 const double r) const {
192 double s = param_ * r;
193 double s2 = s * s;
194 double s3 = s2 * s;
195
196 double derivative = 20.0 * coef_deriv_[5][param_index] * s3 +
197 12.0 * coef_deriv_[4][param_index] * s2 +
198 6.0 * coef_deriv_[3][param_index] * s +
199 2.0 * coef_deriv_[2][param_index];
200
201 if (param_index == DELTA_S) {
202 derivative += 20.0 * coef_[5] * 3.0 * s2 * r +
203 12.0 * coef_[4] * 2.0 * s * r + 6.0 * coef_[3] * r;
204 }
205 return derivative;
206}
207
208double QuinticSpiralPath::DeriveD2KappaDerivative(const size_t param_index,
209 const double r) const {
210 double s = param_ * r;
211 double s2 = s * s;
212
213 double derivative = 60.0 * coef_deriv_[5][param_index] * s2 +
214 24.0 * coef_deriv_[4][param_index] * s +
215 6.0 * coef_deriv_[3][param_index];
216
217 if (param_index == DELTA_S) {
218 derivative += 60.0 * coef_[5] * 2.0 * s * r + 24.0 * coef_[4] * r;
219 }
220 return derivative;
221}
222
223} // namespace planning
224} // namespace apollo
Describe a quintic spiral path Map (theta0, kappa0, dkappa0) --— delta_s --—> (theta1,...
double DeriveKappaDerivative(const size_t param_index, const double ratio) const
double DeriveD2KappaDerivative(const size_t param_index, const double r) const
double DeriveDKappaDerivative(const size_t param_index, const double ratio) const
Planning module main class.
#define ACHECK(cond)
Definition log.h:80
class register implement
Definition arena_queue.h:37