Apollo 10.0
自动驾驶开放平台
linear_interpolation.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
18
19#include <cmath>
20
21#include "cyber/common/log.h"
23
24namespace apollo {
25namespace common {
26namespace math {
27
28double slerp(const double a0, const double t0, const double a1, const double t1,
29 const double t) {
30 if (std::abs(t1 - t0) <= kMathEpsilon) {
31 ADEBUG << "input time difference is too small";
32 return NormalizeAngle(a0);
33 }
34 const double a0_n = NormalizeAngle(a0);
35 const double a1_n = NormalizeAngle(a1);
36 double d = a1_n - a0_n;
37 if (d > M_PI) {
38 d = d - 2 * M_PI;
39 } else if (d < -M_PI) {
40 d = d + 2 * M_PI;
41 }
42
43 const double r = (t - t0) / (t1 - t0);
44 const double a = a0_n + d * r;
45 return NormalizeAngle(a);
46}
47
49 const SLPoint &p1, const double w) {
50 CHECK_GE(w, 0.0);
51
52 SLPoint p;
53 p.set_s((1 - w) * p0.s() + w * p1.s());
54 p.set_l((1 - w) * p0.l() + w * p1.l());
55 return p;
56}
57
59 const PathPoint &p1,
60 const double s) {
61 double s0 = p0.s();
62 double s1 = p1.s();
63
64 PathPoint path_point;
65 double weight = (s - s0) / (s1 - s0);
66 double x = (1 - weight) * p0.x() + weight * p1.x();
67 double y = (1 - weight) * p0.y() + weight * p1.y();
68 double theta = slerp(p0.theta(), p0.s(), p1.theta(), p1.s(), s);
69 double kappa = (1 - weight) * p0.kappa() + weight * p1.kappa();
70 double dkappa = (1 - weight) * p0.dkappa() + weight * p1.dkappa();
71 double ddkappa = (1 - weight) * p0.ddkappa() + weight * p1.ddkappa();
72 path_point.set_x(x);
73 path_point.set_y(y);
74 path_point.set_theta(theta);
75 path_point.set_kappa(kappa);
76 path_point.set_dkappa(dkappa);
77 path_point.set_ddkappa(ddkappa);
78 path_point.set_s(s);
79 return path_point;
80}
81
83 const TrajectoryPoint &tp1,
84 const double t) {
85 if (!tp0.has_path_point() || !tp1.has_path_point()) {
87 p.mutable_path_point()->CopyFrom(PathPoint());
88 return p;
89 }
90 const PathPoint pp0 = tp0.path_point();
91 const PathPoint pp1 = tp1.path_point();
92 double t0 = tp0.relative_time();
93 double t1 = tp1.relative_time();
94
96 tp.set_v(lerp(tp0.v(), t0, tp1.v(), t1, t));
97 tp.set_a(lerp(tp0.a(), t0, tp1.a(), t1, t));
98 tp.set_relative_time(t);
99 tp.set_steer(slerp(tp0.steer(), t0, tp1.steer(), t1, t));
100
101 PathPoint *path_point = tp.mutable_path_point();
102 path_point->set_x(lerp(pp0.x(), t0, pp1.x(), t1, t));
103 path_point->set_y(lerp(pp0.y(), t0, pp1.y(), t1, t));
104 path_point->set_theta(slerp(pp0.theta(), t0, pp1.theta(), t1, t));
105 path_point->set_kappa(lerp(pp0.kappa(), t0, pp1.kappa(), t1, t));
106 path_point->set_dkappa(lerp(pp0.dkappa(), t0, pp1.dkappa(), t1, t));
107 path_point->set_ddkappa(lerp(pp0.ddkappa(), t0, pp1.ddkappa(), t1, t));
108 path_point->set_s(lerp(pp0.s(), t0, pp1.s(), t1, t));
109
110 return tp;
111}
112
113} // namespace math
114} // namespace common
115} // namespace apollo
Linear interpolation functions.
#define ADEBUG
Definition log.h:41
Math-related util functions.
SLPoint InterpolateUsingLinearApproximation(const SLPoint &p0, const SLPoint &p1, const double w)
T lerp(const T &x0, const double t0, const T &x1, const double t1, const double t)
Linear interpolation between two points of type T.
constexpr double kMathEpsilon
Definition vec2d.h:35
double NormalizeAngle(const double angle)
Normalize angle to [-PI, PI).
Definition math_utils.cc:53
double slerp(const double a0, const double t0, const double a1, const double t1, const double t)
Spherical linear interpolation between two angles.
class register implement
Definition arena_queue.h:37