Apollo 11.0
自动驾驶开放平台
quintic_polynomial_curve1d.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
23#include "absl/strings/str_cat.h"
24#include "absl/strings/str_join.h"
25
26#include "cyber/common/log.h"
27
28namespace apollo {
29namespace planning {
30
32 const std::array<double, 3>& start, const std::array<double, 3>& end,
33 const double param)
34 : QuinticPolynomialCurve1d(start[0], start[1], start[2], end[0], end[1],
35 end[2], param) {}
36
38 const double x0, const double dx0, const double ddx0, const double x1,
39 const double dx1, const double ddx1, const double param) {
40 ComputeCoefficients(x0, dx0, ddx0, x1, dx1, ddx1, param);
41 start_condition_[0] = x0;
42 start_condition_[1] = dx0;
43 start_condition_[2] = ddx0;
44 end_condition_[0] = x1;
45 end_condition_[1] = dx1;
46 end_condition_[2] = ddx1;
47 param_ = param;
48}
49
55
56double QuinticPolynomialCurve1d::Evaluate(const uint32_t order,
57 const double p) const {
58 switch (order) {
59 case 0: {
60 return ((((coef_[5] * p + coef_[4]) * p + coef_[3]) * p + coef_[2]) * p +
61 coef_[1]) *
62 p +
63 coef_[0];
64 }
65 case 1: {
66 return (((5.0 * coef_[5] * p + 4.0 * coef_[4]) * p + 3.0 * coef_[3]) * p +
67 2.0 * coef_[2]) *
68 p +
69 coef_[1];
70 }
71 case 2: {
72 return (((20.0 * coef_[5] * p + 12.0 * coef_[4]) * p) + 6.0 * coef_[3]) *
73 p +
74 2.0 * coef_[2];
75 }
76 case 3: {
77 return (60.0 * coef_[5] * p + 24.0 * coef_[4]) * p + 6.0 * coef_[3];
78 }
79 case 4: {
80 return 120.0 * coef_[5] * p + 24.0 * coef_[4];
81 }
82 case 5: {
83 return 120.0 * coef_[5];
84 }
85 default:
86 return 0.0;
87 }
88}
89
90void QuinticPolynomialCurve1d::SetParam(const double x0, const double dx0,
91 const double ddx0, const double x1,
92 const double dx1, const double ddx1,
93 const double param) {
94 ComputeCoefficients(x0, dx0, ddx0, x1, dx1, ddx1, param);
95 param_ = param;
96}
97
99 const PolynomialCurve1d& other, const double init_value) {
100 CHECK_EQ(other.Order(), 4U);
101 param_ = other.ParamLength();
102 coef_[0] = init_value;
103 for (size_t i = 0; i < 5; ++i) {
104 coef_[i + 1] = other.Coef(i) / (static_cast<double>(i) + 1);
105 }
106}
107
109 const double x0, const double dx0, const double ddx0, const double x1,
110 const double dx1, const double ddx1, const double p) {
111 CHECK_GT(p, 0.0);
112
113 coef_[0] = x0;
114 coef_[1] = dx0;
115 coef_[2] = ddx0 / 2.0;
116
117 const double p2 = p * p;
118 const double p3 = p * p2;
119
120 // the direct analytical method is at least 6 times faster than using matrix
121 // inversion.
122 const double c0 = (x1 - 0.5 * p2 * ddx0 - dx0 * p - x0) / p3;
123 const double c1 = (dx1 - ddx0 * p - dx0) / p2;
124 const double c2 = (ddx1 - ddx0) / p;
125
126 coef_[3] = 0.5 * (20.0 * c0 - 8.0 * c1 + c2);
127 coef_[4] = (-15.0 * c0 + 7.0 * c1 - c2) / p;
128 coef_[5] = (6.0 * c0 - 3.0 * c1 + 0.5 * c2) / p2;
129}
130
132 return absl::StrCat(absl::StrJoin(coef_, "\t"), param_, "\n");
133}
134
135double QuinticPolynomialCurve1d::Coef(const size_t order) const {
136 CHECK_GT(6U, order);
137 return coef_[order];
138}
139} // namespace planning
140} // namespace apollo
virtual double ParamLength() const =0
virtual size_t Order() const =0
virtual double Coef(const size_t order) const =0
double Evaluate(const std::uint32_t order, const double p) const override
void ComputeCoefficients(const double x0, const double dx0, const double ddx0, const double x1, const double dx1, const double ddx1, const double param)
double Coef(const size_t order) const override
void IntegratedFromQuarticCurve(const PolynomialCurve1d &other, const double init_value)
void SetParam(const double x0, const double dx0, const double ddx0, const double x1, const double dx1, const double ddx1, const double param)
Planning module main class.
class register implement
Definition arena_queue.h:37