45 const double& x_target,
46 const double& v_max,
const double& accel,
48 : x_initial_(x_initial),
53 distance_(x_target - x_initial) {
54 direction_ = distance_ > 0 ? 1 : -1;
55 dist_accel_ = 0.5 * (v_max_ * v_max_) / accel_;
56 dist_decel_ = 0.5 * (v_max_ * v_max_) / decel_;
57 dist_full_ = dist_accel_ + dist_decel_;
59 if (std::abs(distance_) > dist_full_) {
62 time_accel_ = v_max_ / accel_;
63 time_decel_ = v_max_ / decel_;
64 dist_cruise_ = std::abs(distance_) - dist_full_;
65 time_cruise_ = dist_cruise_ / v_max_;
66 time_total_ = time_accel_ + time_cruise_ + time_decel_;
70 v_peak_ = sqrt((2 * std::abs(distance_) * accel_ * decel_) /
72 time_accel_ = v_peak_ / accel_;
73 time_decel_ = v_peak_ / decel_;
75 time_total_ = time_accel_ + time_decel_;
90 }
else if (t > time_total_) {
99 if (t < time_accel_) {
100 pos_local = 0.5 * accel_ * (t * t);
101 vel_local = accel_ * t;
104 }
else if (!triangular_ && (t < time_accel_ + time_cruise_)) {
105 pos_local = dist_accel_ + v_max_ * (t - time_accel_);
112 time_deceled = t - time_accel_;
113 pos_local = (0.5 * accel_ * (time_accel_ * time_accel_)) +
114 (v_peak_ * time_deceled) -
115 (0.5 * decel_ * (time_deceled * time_deceled));
116 vel_local = v_peak_ - (decel_ * time_deceled);
119 time_deceled = t - (time_accel_ + time_cruise_);
120 pos_local = dist_accel_ +
121 (v_max_ * (time_cruise_ + time_deceled)) -
122 (0.5 * decel_ * (time_deceled * time_deceled));
123 vel_local = v_max_ - (decel_ * time_deceled);
128 double pos = x_initial_ + (direction_ * pos_local);
129 double vel = direction_ * vel_local;
130 double acc = direction_ * acc_local;
131 return motion_t{pos, vel, acc};
TrapezoidProfile(const double &x_initial, const double &x_target, const double &v_max, const double &accel, const double &decel)
Definition trapezoid_profile.cpp:14