40 : max_vel_(fabs(max_vel))
41 , max_acc_(fabs(max_acc))
42 , max_dec_(fabs(max_dec))
67 if (start_pos_ == end_pos_)
76 double s = ((end_pos_ - start_pos_) > 0.0) - ((end_pos_ - start_pos_) < 0.0);
78 double dis = fabs(end_pos_ - start_pos_);
79 double min_dis_max_vel = 0.5 * max_vel_ * max_vel_ / max_acc_ + 0.5 * max_vel_ * max_vel_ / max_dec_;
82 if (dis > min_dis_max_vel)
87 a3_ = s * max_acc_ / 2.0;
88 t_a_ = max_vel_ / max_acc_;
91 b1_ = a1_ + a3_ * t_a_ * t_a_;
94 t_b_ = (dis - min_dis_max_vel) / max_vel_;
97 c1_ = b1_ + b2_ * (t_b_);
99 c3_ = -s * max_dec_ / 2.0;
100 t_c_ = max_vel_ / max_dec_;
106 double new_vel = s * sqrt(2.0 * dis * max_acc_ * max_dec_ / (max_acc_ + max_dec_));
111 a3_ = s * max_acc_ / 2.0;
112 t_a_ = fabs(new_vel) / max_acc_;
115 b1_ = a1_ + a3_ * t_a_ * t_a_;
123 c3_ = -s * max_dec_ / 2.0;
124 t_c_ = fabs(new_vel) / max_dec_;
140 double ratio =
Duration() / duration;
142 a3_ *= ratio * ratio;
144 b3_ *= ratio * ratio;
146 c3_ *= ratio * ratio;
158 assert(duration1 > 0);
159 assert(duration3 > 0);
162 if (
Duration() - (duration1 + duration2 + duration3) > KDL::epsilon)
168 double s = ((end_pos_ - start_pos_) > 0.0) - ((end_pos_ - start_pos_) < 0.0);
170 double dis = fabs(end_pos_ - start_pos_);
171 double new_vel = s * dis / (duration2 + duration1 / 2.0 + duration3 / 2.0);
172 double new_acc = new_vel / duration1;
173 double new_dec = -new_vel / duration3;
174 if ((fabs(new_vel) - max_vel_ > KDL::epsilon) || (fabs(new_acc) - max_acc_ > KDL::epsilon) ||
175 (fabs(new_dec) - max_dec_ > KDL::epsilon))
192 b1_ = a1_ + a3_ * t_a_ * t_a_;
198 c1_ = b1_ + b2_ * (t_b_);
216 double s = ((pos2 - pos1) > 0.0) - ((pos2 - pos1) < 0.0);
229 double min_brake_dis = 0.5 * vel1 * vel1 / max_dec_;
231 double min_dis_max_vel =
232 0.5 * (max_vel_ - start_vel_) * (max_vel_ + start_vel_) / max_acc_ + 0.5 * max_vel_ * max_vel_ / max_dec_;
233 double dis = fabs(end_pos_ - start_pos_);
236 if (dis <= min_brake_dis)
239 t_a_ = fabs(start_vel_ / max_dec_);
242 a3_ = -0.5 * s * max_dec_;
245 double new_vel = -s * sqrt(2.0 * fabs(min_brake_dis - dis) * max_acc_ * max_dec_ / (max_acc_ + max_dec_));
248 t_b_ = fabs(new_vel / max_acc_);
249 b1_ = a1_ + a2_ * t_a_ + a3_ * t_a_ * t_a_;
251 b3_ = -s * 0.5 * max_acc_;
254 t_c_ = fabs(new_vel / max_dec_);
255 c1_ = b1_ + b2_ * t_b_ + b3_ * t_b_ * t_b_;
257 c3_ = 0.5 * s * max_dec_;
259 else if (dis <= min_dis_max_vel)
263 s * sqrt((dis + 0.5 * start_vel_ * start_vel_ / max_acc_) * 2.0 * max_acc_ * max_dec_ / (max_acc_ + max_dec_));
266 t_a_ = fabs(new_vel - start_vel_) / max_acc_;
269 a3_ = 0.5 * s * max_acc_;
273 b1_ = a1_ + a2_ * t_a_ + a3_ * t_a_ * t_a_;
278 t_c_ = fabs(new_vel / max_dec_);
281 c3_ = -0.5 * s * max_dec_;
286 t_a_ = fabs(max_vel_ - start_vel_) / max_acc_;
289 a3_ = 0.5 * s * max_acc_;
292 t_b_ = (dis - min_dis_max_vel) / max_vel_;
293 b1_ = a1_ + a2_ * t_a_ + a3_ * t_a_ * t_a_;
298 t_c_ = max_vel_ / max_dec_;
299 c1_ = b1_ + b2_ * t_b_ + b3_ * t_b_ * t_b_;
301 c3_ = -0.5 * s * max_dec_;
309 return t_a_ + t_b_ + t_c_;
318 else if (time < t_a_)
320 return a1_ + time * (a2_ + a3_ * time);
322 else if (time < (t_a_ + t_b_))
324 return b1_ + (time - t_a_) * (b2_ + b3_ * (time - t_a_));
326 else if (time <= (t_a_ + t_b_ + t_c_))
328 return c1_ + (time - t_a_ - t_b_) * (c2_ + c3_ * (time - t_a_ - t_b_));
342 else if (time < t_a_)
344 return a2_ + 2 * a3_ * time;
346 else if (time < (t_a_ + t_b_))
348 return b2_ + 2 * b3_ * (time - t_a_);
350 else if (time <= (t_a_ + t_b_ + t_c_))
352 return c2_ + 2 * c3_ * (time - t_a_ - t_b_);
366 else if (time <= t_a_)
370 else if (time <= (t_a_ + t_b_))
374 else if (time <= (t_a_ + t_b_ + t_c_))
399 os <<
"Asymmetric Trapezoid " <<
'\n'
400 <<
"maximal velocity: " <<
p.max_vel_ <<
'\n'
401 <<
"maximal acceleration: " <<
p.max_acc_ <<
'\n'
402 <<
"maximal deceleration: " <<
p.max_dec_ <<
'\n'
403 <<
"start position: " <<
p.start_pos_ <<
'\n'
404 <<
"end position: " <<
p.end_pos_ <<
'\n'
405 <<
"start velocity: " <<
p.start_vel_ <<
'\n'
406 <<
"a1: " <<
p.a1_ <<
'\n'
407 <<
"a2: " <<
p.a2_ <<
'\n'
408 <<
"a3: " <<
p.a3_ <<
'\n'
409 <<
"b1: " <<
p.b1_ <<
'\n'
410 <<
"b2: " <<
p.b2_ <<
'\n'
411 <<
"b3: " <<
p.b3_ <<
'\n'
412 <<
"c1: " <<
p.c1_ <<
'\n'
413 <<
"c2: " <<
p.c2_ <<
'\n'
414 <<
"c3: " <<
p.c3_ <<
'\n'
415 <<
"firstPhaseDuration " <<
p.firstPhaseDuration() <<
'\n'
416 <<
"secondPhaseDuration " <<
p.secondPhaseDuration() <<
'\n'
417 <<
"thirdPhaseDuration " <<
p.thirdPhaseDuration() <<
'\n';
424 return (max_vel_ == other.max_vel_ && max_acc_ == other.max_acc_ && max_dec_ == other.max_dec_ &&
425 start_pos_ == other.start_pos_ && end_pos_ == other.end_pos_ && start_vel_ == other.start_vel_ &&
426 a1_ == other.a1_ && a2_ == other.a2_ && a3_ == other.a3_ && b1_ == other.b1_ && b2_ == other.b2_ &&
427 b3_ == other.b3_ && c1_ == other.c1_ && c2_ == other.c2_ && c3_ == other.c3_ && t_a_ == other.t_a_ &&
428 t_b_ == other.t_b_ && t_c_ == other.t_c_);
435 void VelocityProfileATrap::setEmptyProfile()
A PTP Trajectory Generator of Asymmetric Trapezoidal Velocity Profile. Differences to VelocityProfile...
double Vel(double time) const override
Get velocity at given time.
double Pos(double time) const override
Get position at given time.
VelocityProfileATrap(double max_vel=0, double max_acc=0, double max_dec=0)
Constructor.
void SetProfile(double pos1, double pos2) override
compute the fastest profile Algorithm:
bool setProfileStartVelocity(double pos1, double pos2, double vel1)
Profile with start velocity Note: This function is not general and is currently only used for live co...
double Duration() const override
Duration.
void SetProfileDuration(double pos1, double pos2, double duration) override
Profile scaled by the total duration.
KDL::VelocityProfile * Clone() const override
returns copy of current VelocityProfile object
bool setProfileAllDurations(double pos1, double pos2, double duration1, double duration2, double duration3)
Profile with given acceleration/constant/deceleration durations. Each duration must obey the maximal ...
bool operator==(const VelocityProfileATrap &other) const
Compares two Asymmetric Trapezoidal Velocity Profiles.
void Write(std::ostream &os) const override
Write basic information.
double Acc(double time) const override
Get given acceleration/deceleration at given time.
~VelocityProfileATrap() override
std::ostream & operator<<(std::ostream &os, const VelocityProfileATrap &p)