25#include "absl/strings/str_cat.h"
26#include "absl/strings/str_join.h"
36 const double start_s,
const double start_v) {
37 s_.push_back(start_s);
38 v_.push_back(start_v);
44 const double t_duration) {
45 double s0 = s_.back();
46 double v0 = v_.back();
47 double t0 = t_.back();
49 double v1 = v0 + a * t_duration;
50 ACHECK(v1 >= -FLAGS_numerical_epsilon);
52 double delta_s = (v0 + v1) * t_duration * 0.5;
53 double s1 = s0 + delta_s;
54 double t1 = t0 + t_duration;
56 ACHECK(s1 >= s0 - FLAGS_numerical_epsilon);
57 s1 = std::max(s1, s0);
74 CHECK_GT(t_.size(), 1U);
75 return t_.back() - t_.front();
79 return absl::StrCat(absl::StrJoin(s_,
"\t"), absl::StrJoin(t_,
"\t"),
80 absl::StrJoin(v_,
"\t"), absl::StrJoin(a_,
"\t"),
"\n");
84 const double param)
const {
85 CHECK_GT(t_.size(), 1U);
86 ACHECK(t_.front() <= param && param <= t_.back());
90 return Evaluate_s(param);
92 return Evaluate_v(param);
94 return Evaluate_a(param);
96 return Evaluate_j(param);
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);
105 double s0 = s_[index - 1];
106 double v0 = v_[index - 1];
107 double t0 = t_[index - 1];
109 double v1 = v_[index];
110 double t1 = t_[index];
113 double s = (v0 + v) * (t - t0) * 0.5 + s0;
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);
121 double v0 = v_[index - 1];
122 double t0 = t_[index - 1];
124 double v1 = v_[index];
125 double t1 = t_[index];
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];
137double PiecewiseAccelerationTrajectory1d::Evaluate_j(
const double t)
const {
142 const double t)
const {
143 CHECK_GT(t_.size(), 1U);
144 ACHECK(t_.front() <= t && t <= t_.back());
146 auto it_lower = std::lower_bound(t_.begin(), t_.end(), t);
147 auto index = std::distance(t_.begin(), it_lower);
149 double s0 = s_[index - 1];
150 double v0 = v_[index - 1];
151 double t0 = t_[index - 1];
153 double v1 = v_[index];
154 double t1 = t_[index];
157 double s = (v0 + v) * (t - t0) * 0.5 + s0;
159 double a = a_[index - 1];
162 return {{s, v, a, j}};
double Evaluate(const std::uint32_t order, const double param) const override
double ParamLength() const override
PiecewiseAccelerationTrajectory1d(const double start_s, const double start_v)
void AppendSegment(const double a, const double t_duration)
std::string ToString() const override
Planning module main class.
Linear interpolation functions.
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.