Apollo 11.0
自动驾驶开放平台
cubic_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 double end, const double param)
33 : CubicPolynomialCurve1d(start[0], start[1], start[2], end, param) {}
34
36 const double dx0,
37 const double ddx0,
38 const double x1,
39 const double param) {
40 ComputeCoefficients(x0, dx0, ddx0, x1, param);
41 param_ = param;
42 start_condition_[0] = x0;
43 start_condition_[1] = dx0;
44 start_condition_[2] = ddx0;
45 end_condition_ = x1;
46}
47
49 const PolynomialCurve1d& other) {
50 CHECK_EQ(other.Order(), 4U);
51 param_ = other.ParamLength();
52 for (size_t i = 1; i < 5; ++i) {
53 coef_[i - 1] = other.Coef(i) * static_cast<double>(i);
54 }
55}
56
57double CubicPolynomialCurve1d::Evaluate(const std::uint32_t order,
58 const double p) const {
59 switch (order) {
60 case 0: {
61 return ((coef_[3] * p + coef_[2]) * p + coef_[1]) * p + coef_[0];
62 }
63 case 1: {
64 return (3.0 * coef_[3] * p + 2.0 * coef_[2]) * p + coef_[1];
65 }
66 case 2: {
67 return 6.0 * coef_[3] * p + 2.0 * coef_[2];
68 }
69 case 3: {
70 return 6.0 * coef_[3];
71 }
72 default:
73 return 0.0;
74 }
75}
76
78 return absl::StrCat(absl::StrJoin(coef_, "\t"), param_, "\n");
79}
80
81void CubicPolynomialCurve1d::ComputeCoefficients(const double x0,
82 const double dx0,
83 const double ddx0,
84 const double x1,
85 const double param) {
86 DCHECK(param > 0.0);
87 const double p2 = param * param;
88 const double p3 = param * p2;
89 coef_[0] = x0;
90 coef_[1] = dx0;
91 coef_[2] = 0.5 * ddx0;
92 coef_[3] = (x1 - x0 - dx0 * param - coef_[2] * p2) / p3;
93}
94
95double CubicPolynomialCurve1d::Coef(const size_t order) const {
96 CHECK_GT(4U, order);
97 return coef_[order];
98}
99
100} // namespace planning
101} // namespace apollo
double Coef(const size_t order) const override
void DerivedFromQuarticCurve(const PolynomialCurve1d &other)
double Evaluate(const std::uint32_t order, const double p) const override
virtual double ParamLength() const =0
virtual size_t Order() const =0
virtual double Coef(const size_t order) const =0
Planning module main class.
class register implement
Definition arena_queue.h:37