30 #include <Eigen/Dense>
41 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
48 virtual T
pos(
double t)
const = 0;
55 virtual T
vel(
double t)
const = 0;
62 virtual T
accel(
double t)
const = 0;
93 double arcLength(
double t_start,
double t_end)
const
95 struct GaussLengendreCoefficient
100 static constexpr GaussLengendreCoefficient coeffs[] = {{0.0, 128. / 225.},
101 {-0.53846931010568311, 0.47862867049936647},
102 {+0.53846931010568311, 0.47862867049936647},
103 {-0.90617984593866396, 0.23692688505618908},
104 {+0.90617984593866396, 0.23692688505618908}};
105 double a = (t_end - t_start) / 2.;
106 double b = (t_end + t_start) / 2.;
108 for(
auto coeff : coeffs)
110 length += coeff.w * this->
vel(a * coeff.t + b).norm();
130 constexpr
double PRECISION = 1e-3;
133 t_guess = t_start + 1.;
135 double l_guess =
arcLength(t_start, t_guess);
136 if(std::abs(l_guess - length) < PRECISION)
140 else if(l_guess < length)
157 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
189 return C1_ + t * (2 *
C2_ + 3 * t *
C3_);
199 return 2 *
C2_ + 6 * t *
C3_;
212 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
231 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
253 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
276 reset(initPos, initVel, targetPos, targetVel);
290 void reset(
const T & initPos,
const T & initVel,
const T & targetPos,
const T & targetVel)
306 void reset(
const T & initPos,
const T & targetPos)
342 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
356 double Delta_v0 = Delta.dot(this->
initVel_);
357 double Delta_v1 = Delta.dot(this->
targetVel_);
361 double houbaInitVelScaling =
362 6. * (3. * Delta_v0 * v1_v1 - 2. * Delta_v1 * v0_v1) / (9. * v0_v0 * v1_v1 - 4. * v0_v1 * v0_v1);
363 if(houbaInitVelScaling < 0.)
365 houbaInitVelScaling *= -1.;
367 double houbaTargetVelScaling =
368 6. * (-2. * Delta_v0 * v0_v1 + 3. * Delta_v1 * v0_v0) / (9. * v0_v0 * v1_v1 - 4. * v0_v1 * v0_v1);
369 if(houbaTargetVelScaling < 0.)
371 houbaTargetVelScaling *= -1.;
373 this->
initVel_ *= houbaInitVelScaling;
423 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
462 return C1_ + t * (2 *
C2_ + t * (3 *
C3_ + t * (4 *
C4_ + t * 5 *
C5_)));
472 return 2 *
C2_ + t * (6 *
C3_ + t * (12 *
C4_ + t * 20 *
C5_));
490 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
512 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
534 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
557 reset(initPos, initVel, targetPos, targetVel);
580 const T & targetAccel)
602 void reset(
const T & initPos,
const T & initVel,
const T & targetPos,
const T & targetVel)
620 void reset(
const T & initPos,
const T & targetPos)
643 this->
C3_ = 10 * Delta - 4 * Sigma + Gamma - 2 * kappa;
644 this->
C4_ = -15 * Delta + 7 * Sigma - 2 * Gamma + kappa;
645 this->
C5_ = 6 * Delta - 3 * Sigma + Gamma;
661 template<
template<
class>
class Polynomial,
typename T>
664 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
700 poly_.reset(initPos, targetPos);
716 void reset(
const T & initPos,
const T & initVel,
const T & targetPos,
const T & targetVel,
double duration)
744 const T & targetAccel,
750 duration2 * targetAccel);
756 double s(
double t)
const
765 double sd(
double t)
const
797 return std::pow(
sd(t), 2) *
poly_.accel(
s(t));
Utility functions and classes.
Cubic Hermite polynomial.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW CubicHermitePolynomial()
Empty constructor.
CubicHermitePolynomial(const T &initPos, const T &initVel, const T &targetPos, const T &targetVel)
Build a new cubic Hermite polynomial.
void reset(const T &initPos, const T &initVel, const T &targetPos, const T &targetVel)
Reset boundaries.
virtual void reset()
Reset underlying cubic polynomial coefficients.
void reset(const T &initPos, const T &targetPos)
Reset boundaries with zero tangents.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW double zero()
Zero function used for double specialization.
CubicPolynomial()
Empty constructor.
T pos(double t) const
Get the value of the polynomial at time t.
T accel(double t) const
Get the value of the second-order derivative (acceleration) at time t.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW CubicPolynomialBase(const T &C0, const T &C1, const T &C2, const T &C3)
Build a new curve from its monomial vector coefficients.
T vel(double t) const
Get the value of the first-order derivative (velocity) at time t.
CubicPolynomial()
Empty constructor.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW T zero()
Return T's zero.
Hermite polynomial with Overall Uniformly-Bounded Accelerations (HOUBA).
void extraTargetVelScaling(double scaling)
Add extra target velocity scaling to the HOUBA one.
double extraTargetVelScaling_
double extraInitVelScaling()
Get extra initial velocity scaling.
void reset() override
Rescale boundary velocities, then reset as Hermite polynomial.
void extraInitVelScaling(double scaling)
Add extra initial velocity scaling to the HOUBA one.
double extraTargetVelScaling()
Get extra target velocity scaling.
double extraInitVelScaling_
T tangent(double t) const
Get the value of the tangent vector at time t.
virtual T accel(double t) const =0
Get the value of the second-order derivative (acceleration) at time t.
double arcLengthInverse(double t_start, double length, double t_guess=-1.) const
Inverse of the arc length function.
double arcLength(double t_start, double t_end) const
Compute the arc length between two points of the polynomial curve.
virtual EIGEN_MAKE_ALIGNED_OPERATOR_NEW T pos(double t) const =0
Get the value of the polynomial at time t.
virtual T vel(double t) const =0
Get the value of the first-order derivative (velocity) at time t.
Quintic polynomial with zero velocity and zero acceleration at 0 and 1.
void reset()
Reset underlying cubic polynomial coefficients.
void reset(const T &initPos, const T &initVel, const T &initAccel, const T &targetPos, const T &targetVel, const T &targetAccel)
Reset boundary values.
QuinticHermitePolynomial(const T &initPos, const T &initVel, const T &targetPos, const T &targetVel)
Build a new cubic Hermite polynomial.
void reset(const T &initPos, const T &initVel, const T &targetPos, const T &targetVel)
Reset boundaries with zero boundary velocities.
void reset(const T &initPos, const T &targetPos)
Reset boundaries with zero tangents.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW QuinticHermitePolynomial()
Empty constructor.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW double zero()
Zero function used for double specialization.
QuinticPolynomial()
Empty constructor.
T pos(double t) const
Get the value of the polynomial at time t.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW QuinticPolynomialBase(const T &C0, const T &C1, const T &C2, const T &C3, const T &C4, const T &C5)
Build a new curve from its monomial vector coefficients.
T vel(double t) const
Get the value of the first-order derivative (velocity) at time t.
T accel(double t) const
Get the value of the second-order derivative (acceleration) at time t.
Quintic polynomial over vectors.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW T zero()
Return T's zero.
QuinticPolynomial()
Empty constructor.
Polynomial whose argument is retimed to by .
T accel(double t) const
Acceleration along the retimed trajectory.
void reset(const T &initPos, const T &targetPos, double duration)
Reset duration and boundary positions.
void reset(const T &initPos, const T &initVel, const T &initAccel, const T &targetPos, const T &targetVel, const T &targetAccel, double duration)
Reset duration and boundary positions, velocities and accelerations.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW RetimedPolynomial()
Empty constructor.
RetimedPolynomial(Polynomial< T > poly, double duration)
Constructor.
double duration() const
Get trajectory duration.
double sd(double t) const
Mapping from to .
void reset(const T &initPos, const T &initVel, const T &targetPos, const T &targetVel, double duration)
Reset duration and boundary positions and velocities.
double s(double t) const
Mapping from to .
T pos(double t) const
Position along the retimed trajectory.
T vel(double t) const
Velocity along the retimed trajectory.