23 #include <unordered_map> 39 const std::array<double, 3>& end,
40 const double delta_s);
43 const double dkappa0,
const double theta1,
44 const double kappa1,
const double dkappa1,
45 const double delta_s);
49 double evaluate(
const size_t order,
const size_t i,
const size_t n);
74 auto cos_theta = [
this](
const double s) {
78 return common::math::IntegrateByGaussLegendre<N>(cos_theta, 0.0, s);
82 auto sin_theta = [
this](
const double s) {
86 return common::math::IntegrateByGaussLegendre<N>(sin_theta, 0.0, s);
90 double DeriveCosTheta(
const size_t param_index,
const double r)
const;
92 double DeriveSinTheta(
const size_t param_index,
const double r)
const;
94 double DeriveThetaDerivative(
const size_t param_index,
const double r)
const;
96 std::array<std::array<double, 7>, 6> coef_deriv_;
98 std::unordered_map<size_t, double> cache_evaluate_;
100 std::unordered_map<size_t, std::pair<double, double>> cache_cartesian_deriv_;
102 std::unordered_map<size_t, double> cache_kappa_deriv_;
104 std::unordered_map<size_t, double> cache_dkappa_deriv_;
110 std::array<double, N> gauss_points_;
112 std::array<double, N> gauss_point_weights_;
117 const double x0,
const double dx0,
const double ddx0,
const double x1,
118 const double dx1,
const double ddx1,
const double s)
122 auto gauss_points = common::math::GetGaussLegendrePoints<N>();
123 gauss_points_ = gauss_points.first;
124 gauss_point_weights_ = gauss_points.second;
136 for (
size_t i = 0; i < 6; ++i) {
137 for (
size_t j = 0; j < 7; ++j) {
138 coef_deriv_[i][j] = 0.0;
144 coef_deriv_[5][0] = -6.0 / s5;
145 coef_deriv_[5][1] = -3.0 / s4;
146 coef_deriv_[5][2] = -0.5 / s3;
147 coef_deriv_[5][3] = 6.0 / s5;
148 coef_deriv_[5][4] = -3.0 / s4;
149 coef_deriv_[5][5] = 0.5 / s3;
150 coef_deriv_[5][6] = 30.0 * x0 / s6 + 12.0 * dx0 / s5 + 1.5 * ddx0 / s4 -
151 30.0 * x1 / s6 + 12.0 * dx1 / s5 - 1.5 * ddx1 / s4;
156 coef_deriv_[4][0] = 15.0 / s4;
157 coef_deriv_[4][1] = 8.0 / s3;
158 coef_deriv_[4][2] = 1.5 / s2;
159 coef_deriv_[4][3] = -15.0 / s4;
160 coef_deriv_[4][4] = 7.0 / s3;
161 coef_deriv_[4][5] = -1.0 / s2;
162 coef_deriv_[4][6] = -60.0 * x0 / s5 - 24.0 * dx0 / s4 - 3.0 * ddx0 / s3 +
163 60.0 * x1 / s5 - 21.0 * dx1 / s4 + 2.0 * ddx1 / s3;
168 coef_deriv_[3][0] = -10.0 / s3;
169 coef_deriv_[3][1] = -6.0 / s2;
170 coef_deriv_[3][2] = -1.5 / s;
171 coef_deriv_[3][3] = 10.0 / s3;
172 coef_deriv_[3][4] = -4.0 / s2;
173 coef_deriv_[3][5] = 0.5 / s;
174 coef_deriv_[3][6] = 30.0 * x0 / s4 + 12.0 * dx0 / s3 + 1.5 * ddx0 / s2 -
175 30.0 * x1 / s4 + 8.0 * dx1 / s3 - 0.5 * ddx1 / s2;
179 coef_deriv_[2][2] = 0.5;
183 coef_deriv_[1][1] = 1.0;
187 coef_deriv_[0][0] = 1.0;
192 const std::array<double, 3>& start,
const std::array<double, 3>& end,
193 const double delta_s)
195 end[1], end[2], delta_s) {}
201 auto key = order * 100 + n * 10 + i;
202 if (cache_evaluate_.find(key) != cache_evaluate_.end()) {
203 return cache_evaluate_[key];
206 Evaluate(order, static_cast<double>(i) / static_cast<double>(n) *
param_);
207 cache_evaluate_[key] = res;
212 std::pair<double, double>
214 const size_t param_index) {
215 if (cache_cartesian_deriv_.find(param_index) !=
216 cache_cartesian_deriv_.end()) {
217 return cache_cartesian_deriv_[param_index];
220 const auto& g = gauss_points_;
221 const auto& w = gauss_point_weights_;
223 std::pair<double, double> cartesian_deviation = {0.0, 0.0};
225 for (
size_t i = 0; i < N; ++i) {
226 double r = 0.5 * g[i] + 0.5;
227 cartesian_deviation.first += w[i] * DeriveCosTheta(param_index, r);
228 cartesian_deviation.second += w[i] * DeriveSinTheta(param_index, r);
231 cartesian_deviation.first *=
param_ * 0.5;
232 cartesian_deviation.second *=
param_ * 0.5;
234 for (
size_t i = 0; i < N; ++i) {
235 double r = 0.5 * g[i] + 0.5;
236 cartesian_deviation.first += w[i] * DeriveCosTheta(param_index, r);
237 cartesian_deviation.second += w[i] * DeriveSinTheta(param_index, r);
240 cartesian_deviation.first *=
param_ * 0.5;
241 cartesian_deviation.second *=
param_ * 0.5;
243 for (
size_t i = 0; i < N; ++i) {
244 double r = 0.5 * g[i] + 0.5;
247 cartesian_deviation.first += 0.5 * w[i] *
std::cos(theta);
248 cartesian_deviation.second += 0.5 * w[i] *
std::sin(theta);
251 cache_cartesian_deriv_[param_index] = cartesian_deviation;
252 return cartesian_deviation;
257 const size_t param_index,
const int i,
const int n) {
259 if (cache_kappa_deriv_.find(key) != cache_kappa_deriv_.end()) {
260 return cache_kappa_deriv_[key];
263 auto r =
static_cast<double>(i) / static_cast<double>(n);
269 double derivative = 5.0 * coef_deriv_[5][param_index] * s4 +
270 4.0 * coef_deriv_[4][param_index] * s3 +
271 3.0 * coef_deriv_[3][param_index] * s2 +
272 2.0 * coef_deriv_[2][param_index] * s +
273 coef_deriv_[1][param_index];
276 derivative += 20.0 *
coef_[5] * s3 * r + 12.0 *
coef_[4] * s2 * r +
280 cache_kappa_deriv_[key] = derivative;
286 const size_t param_index,
const int i,
const int n) {
288 if (cache_dkappa_deriv_.find(key) != cache_dkappa_deriv_.end()) {
289 return cache_dkappa_deriv_[key];
292 auto r =
static_cast<double>(i) / static_cast<double>(n);
297 double derivative = 20.0 * coef_deriv_[5][param_index] * s3 +
298 12.0 * coef_deriv_[4][param_index] * s2 +
299 6.0 * coef_deriv_[3][param_index] * s +
300 2.0 * coef_deriv_[2][param_index];
304 60.0 *
coef_[5] * s2 * r + 24.0 *
coef_[4] * s * r + 6.0 *
coef_[3] * r;
307 cache_dkappa_deriv_[key] = derivative;
313 const size_t param_index,
const double r)
const {
321 coef_deriv_[5][param_index] * s5 + coef_deriv_[4][param_index] * s4 +
322 coef_deriv_[3][param_index] * s3 + coef_deriv_[2][param_index] * s2 +
323 coef_deriv_[1][param_index] * s + coef_deriv_[0][param_index];
326 derivative +=
coef_[5] * 5.0 * s4 * r +
coef_[4] * 4.0 * s3 * r +
327 coef_[3] * 3.0 * s2 * r +
coef_[2] * 2.0 * s * r +
335 const size_t param_index,
const double r)
const {
339 double derivative = -
std::sin(theta) * DeriveThetaDerivative(param_index, r);
345 const size_t param_index,
const double r)
const {
349 double derivative =
std::cos(theta) * DeriveThetaDerivative(param_index, r);
double ComputeCartesianDeviationY() const
Definition: quintic_spiral_path_with_derivation.h:53
std::pair< double, double > DeriveCartesianDeviation(const size_t param_index)
Definition: quintic_spiral_path_with_derivation.h:213
static const size_t DKAPPA1
Definition: quintic_spiral_path_with_derivation.h:68
static const size_t KAPPA0
Definition: quintic_spiral_path_with_derivation.h:64
static const size_t DELTA_S
Definition: quintic_spiral_path_with_derivation.h:69
#define ACHECK(cond)
Definition: log.h:80
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
std::array< double, 6 > coef_
Definition: quintic_polynomial_curve1d.h:71
Planning module main class. It processes GPS and IMU as input, to generate planning info...
double Evaluate(const std::uint32_t order, const double p) const override
Definition: quintic_polynomial_curve1d.h:33
virtual ~QuinticSpiralPathWithDerivation()=default
QuinticSpiralPathWithDerivation()=default
double param_
Definition: polynomial_curve1d.h:37
static const size_t DKAPPA0
Definition: quintic_spiral_path_with_derivation.h:65
double evaluate(const size_t order, const size_t i, const size_t n)
Definition: quintic_spiral_path_with_derivation.h:198
double ComputeCartesianDeviationY(const double s) const
Definition: quintic_spiral_path_with_derivation.h:81
Definition: quintic_spiral_path_with_derivation.h:34
Functions to compute integral.
double DeriveDKappaDerivative(const size_t param_index, const int i, const int n)
Definition: quintic_spiral_path_with_derivation.h:285
double ComputeCartesianDeviationX(const double s) const
Definition: quintic_spiral_path_with_derivation.h:73
double ComputeCartesianDeviationX() const
Definition: quintic_spiral_path_with_derivation.h:51
static const size_t THETA1
Definition: quintic_spiral_path_with_derivation.h:66
static const size_t INDEX_MAX
Definition: quintic_spiral_path_with_derivation.h:71
double DeriveKappaDerivative(const size_t param_index, const int i, const int n)
Definition: quintic_spiral_path_with_derivation.h:256
static const size_t KAPPA1
Definition: quintic_spiral_path_with_derivation.h:67
static const size_t THETA0
Definition: quintic_spiral_path_with_derivation.h:63