Apollo 11.0
自动驾驶开放平台
piecewise_acceleration_trajectory1d.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 <algorithm>
24
25#include "absl/strings/str_cat.h"
26#include "absl/strings/str_join.h"
27
28#include "cyber/common/log.h"
31
32namespace apollo {
33namespace planning {
34
36 const double start_s, const double start_v) {
37 s_.push_back(start_s);
38 v_.push_back(start_v);
39 a_.push_back(0.0);
40 t_.push_back(0.0);
41}
42
44 const double t_duration) {
45 double s0 = s_.back();
46 double v0 = v_.back();
47 double t0 = t_.back();
48
49 double v1 = v0 + a * t_duration;
50 ACHECK(v1 >= -FLAGS_numerical_epsilon);
51
52 double delta_s = (v0 + v1) * t_duration * 0.5;
53 double s1 = s0 + delta_s;
54 double t1 = t0 + t_duration;
55
56 ACHECK(s1 >= s0 - FLAGS_numerical_epsilon);
57 s1 = std::max(s1, s0);
58 s_.push_back(s1);
59 v_.push_back(v1);
60 a_.push_back(a);
61 t_.push_back(t1);
62}
63
65 if (a_.size() > 0) {
66 s_.pop_back();
67 v_.pop_back();
68 a_.pop_back();
69 t_.pop_back();
70 }
71}
72
74 CHECK_GT(t_.size(), 1U);
75 return t_.back() - t_.front();
76}
77
79 return absl::StrCat(absl::StrJoin(s_, "\t"), absl::StrJoin(t_, "\t"),
80 absl::StrJoin(v_, "\t"), absl::StrJoin(a_, "\t"), "\n");
81}
82
83double PiecewiseAccelerationTrajectory1d::Evaluate(const std::uint32_t order,
84 const double param) const {
85 CHECK_GT(t_.size(), 1U);
86 ACHECK(t_.front() <= param && param <= t_.back());
87
88 switch (order) {
89 case 0:
90 return Evaluate_s(param);
91 case 1:
92 return Evaluate_v(param);
93 case 2:
94 return Evaluate_a(param);
95 case 3:
96 return Evaluate_j(param);
97 }
98 return 0.0;
99}
100
101double PiecewiseAccelerationTrajectory1d::Evaluate_s(const double t) const {
102 auto it_lower = std::lower_bound(t_.begin(), t_.end(), t);
103 auto index = std::distance(t_.begin(), it_lower);
104
105 double s0 = s_[index - 1];
106 double v0 = v_[index - 1];
107 double t0 = t_[index - 1];
108
109 double v1 = v_[index];
110 double t1 = t_[index];
111
112 double v = common::math::lerp(v0, t0, v1, t1, t);
113 double s = (v0 + v) * (t - t0) * 0.5 + s0;
114 return s;
115}
116
117double PiecewiseAccelerationTrajectory1d::Evaluate_v(const double t) const {
118 auto it_lower = std::lower_bound(t_.begin(), t_.end(), t);
119 auto index = std::distance(t_.begin(), it_lower);
120
121 double v0 = v_[index - 1];
122 double t0 = t_[index - 1];
123
124 double v1 = v_[index];
125 double t1 = t_[index];
126
127 double v = apollo::common::math::lerp(v0, t0, v1, t1, t);
128 return v;
129}
130
131double PiecewiseAccelerationTrajectory1d::Evaluate_a(const double t) const {
132 auto it_lower = std::lower_bound(t_.begin(), t_.end(), t);
133 auto index = std::distance(t_.begin(), it_lower);
134 return a_[index - 1];
135}
136
137double PiecewiseAccelerationTrajectory1d::Evaluate_j(const double t) const {
138 return 0.0;
139}
140
142 const double t) const {
143 CHECK_GT(t_.size(), 1U);
144 ACHECK(t_.front() <= t && t <= t_.back());
145
146 auto it_lower = std::lower_bound(t_.begin(), t_.end(), t);
147 auto index = std::distance(t_.begin(), it_lower);
148
149 double s0 = s_[index - 1];
150 double v0 = v_[index - 1];
151 double t0 = t_[index - 1];
152
153 double v1 = v_[index];
154 double t1 = t_[index];
155
156 double v = common::math::lerp(v0, t0, v1, t1, t);
157 double s = (v0 + v) * (t - t0) * 0.5 + s0;
158
159 double a = a_[index - 1];
160 double j = 0.0;
161
162 return {{s, v, a, j}};
163}
164
165} // namespace planning
166} // namespace apollo
double Evaluate(const std::uint32_t order, const double param) const override
PiecewiseAccelerationTrajectory1d(const double start_s, const double start_v)
Planning module main class.
Linear interpolation functions.
#define ACHECK(cond)
Definition log.h:80
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.
class register implement
Definition arena_queue.h:37