Apollo 11.0
自动驾驶开放平台
quartic_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, 2>& end,
33 const double param)
34 : QuarticPolynomialCurve1d(start[0], start[1], start[2], end[0], end[1],
35 param) {}
36
38 const double x0, const double dx0, const double ddx0, const double dx1,
39 const double ddx1, const double param) {
40 param_ = param;
41 start_condition_[0] = x0;
42 start_condition_[1] = dx0;
43 start_condition_[2] = ddx0;
44 end_condition_[0] = dx1;
45 end_condition_[1] = ddx1;
46 ComputeCoefficients(x0, dx0, ddx0, dx1, ddx1, param);
47}
48
50 const QuarticPolynomialCurve1d& other) {
51 param_ = other.param_;
52 coef_ = other.coef_;
53}
54
55double QuarticPolynomialCurve1d::Evaluate(const std::uint32_t order,
56 const double p) const {
57 switch (order) {
58 case 0: {
59 return (((coef_[4] * p + coef_[3]) * p + coef_[2]) * p + coef_[1]) * p +
60 coef_[0];
61 }
62 case 1: {
63 return ((4.0 * coef_[4] * p + 3.0 * coef_[3]) * p + 2.0 * coef_[2]) * p +
64 coef_[1];
65 }
66 case 2: {
67 return (12.0 * coef_[4] * p + 6.0 * coef_[3]) * p + 2.0 * coef_[2];
68 }
69 case 3: {
70 return 24.0 * coef_[4] * p + 6.0 * coef_[3];
71 }
72 case 4: {
73 return 24.0 * coef_[4];
74 }
75 default:
76 return 0.0;
77 }
78}
79
81 const double x0, const double dx0, const double ddx0, const double x1,
82 const double dx1, const double p) {
83 CHECK_GT(p, 0.0);
84
85 param_ = p;
86
87 coef_[0] = x0;
88
89 coef_[1] = dx0;
90
91 coef_[2] = 0.5 * ddx0;
92
93 double p2 = p * p;
94 double p3 = p2 * p;
95 double p4 = p3 * p;
96
97 double b0 = x1 - coef_[0] - coef_[1] * p - coef_[2] * p2;
98 double b1 = dx1 - dx0 - ddx0 * p;
99
100 coef_[4] = (b1 * p - 3 * b0) / p4;
101 coef_[3] = (4 * b0 - b1 * p) / p3;
102 return *this;
103}
104
106 const double x0, const double dx0, const double x1, const double dx1,
107 const double ddx1, const double p) {
108 CHECK_GT(p, 0.0);
109
110 param_ = p;
111
112 coef_[0] = x0;
113
114 coef_[1] = dx0;
115
116 double p2 = p * p;
117 double p3 = p2 * p;
118 double p4 = p3 * p;
119
120 double b0 = x1 - coef_[0] - coef_[1] * p;
121 double b1 = dx1 - coef_[1];
122 double c1 = b1 * p;
123 double c2 = ddx1 * p2;
124
125 coef_[2] = (0.5 * c2 - 3 * c1 + 6 * b0) / p2;
126 coef_[3] = (-c2 + 5 * c1 - 8 * b0) / p3;
127 coef_[4] = (0.5 * c2 - 2 * c1 + 3 * b0) / p4;
128
129 return *this;
130}
131
133 const PolynomialCurve1d& other, const double init_value) {
134 CHECK_EQ(other.Order(), 3U);
135 param_ = other.ParamLength();
136 coef_[0] = init_value;
137 for (size_t i = 0; i < 4; ++i) {
138 coef_[i + 1] = other.Coef(i) / (static_cast<double>(i) + 1);
139 }
140 return *this;
141}
142
144 const PolynomialCurve1d& other) {
145 CHECK_EQ(other.Order(), 5U);
146 param_ = other.ParamLength();
147 for (size_t i = 1; i < 6; ++i) {
148 coef_[i - 1] = other.Coef(i) * static_cast<double>(i);
149 }
150 return *this;
151}
152
153void QuarticPolynomialCurve1d::ComputeCoefficients(
154 const double x0, const double dx0, const double ddx0, const double dx1,
155 const double ddx1, const double p) {
156 CHECK_GT(p, 0.0);
157
158 coef_[0] = x0;
159 coef_[1] = dx0;
160 coef_[2] = 0.5 * ddx0;
161
162 double b0 = dx1 - ddx0 * p - dx0;
163 double b1 = ddx1 - ddx0;
164
165 double p2 = p * p;
166 double p3 = p2 * p;
167
168 coef_[3] = (3 * b0 - b1 * p) / (3 * p2);
169 coef_[4] = (-2 * b0 + b1 * p) / (4 * p3);
170}
171
173 return absl::StrCat(absl::StrJoin(coef_, "\t"), param_, "\n");
174}
175
176double QuarticPolynomialCurve1d::Coef(const size_t order) const {
177 CHECK_GT(5U, order);
178 return coef_[order];
179}
180
181} // namespace planning
182} // namespace apollo
virtual double ParamLength() const =0
virtual size_t Order() const =0
virtual double Coef(const size_t order) const =0
QuarticPolynomialCurve1d & IntegratedFromCubicCurve(const PolynomialCurve1d &other, const double init_value)
double Coef(const size_t order) const override
QuarticPolynomialCurve1d & FitWithEndPointSecondOrder(const double x0, const double dx0, const double x1, const double dx1, const double ddx1, const double param)
Interface with refine quartic polynomial by meets end point second order and start point first order ...
double Evaluate(const std::uint32_t order, const double p) const override
QuarticPolynomialCurve1d & DerivedFromQuinticCurve(const PolynomialCurve1d &other)
QuarticPolynomialCurve1d & FitWithEndPointFirstOrder(const double x0, const double dx0, const double ddx0, const double x1, const double dx1, const double param)
Interface with refine quartic polynomial by meets end first order and start second order boundary con...
Planning module main class.
class register implement
Definition arena_queue.h:37