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));
EIGEN_MAKE_ALIGNED_OPERATOR_NEW CubicHermitePolynomial()
CubicHermitePolynomial(const T &initPos, const T &initVel, const T &targetPos, const T &targetVel)
void reset(const T &initPos, const T &initVel, const T &targetPos, const T &targetVel)
void reset(const T &initPos, const T &targetPos)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW CubicPolynomialBase(const T &C0, const T &C1, const T &C2, const T &C3)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW double zero()
EIGEN_MAKE_ALIGNED_OPERATOR_NEW T zero()
void extraTargetVelScaling(double scaling)
double extraTargetVelScaling_
double extraInitVelScaling()
void extraInitVelScaling(double scaling)
double extraTargetVelScaling()
double extraInitVelScaling_
T tangent(double t) const
virtual T accel(double t) const =0
double arcLengthInverse(double t_start, double length, double t_guess=-1.) const
double arcLength(double t_start, double t_end) const
virtual EIGEN_MAKE_ALIGNED_OPERATOR_NEW T pos(double t) const =0
virtual T vel(double t) const =0
void reset(const T &initPos, const T &initVel, const T &initAccel, const T &targetPos, const T &targetVel, const T &targetAccel)
QuinticHermitePolynomial(const T &initPos, const T &initVel, const T &targetPos, const T &targetVel)
void reset(const T &initPos, const T &initVel, const T &targetPos, const T &targetVel)
void reset(const T &initPos, const T &targetPos)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW QuinticHermitePolynomial()
EIGEN_MAKE_ALIGNED_OPERATOR_NEW QuinticPolynomialBase(const T &C0, const T &C1, const T &C2, const T &C3, const T &C4, const T &C5)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW double zero()
EIGEN_MAKE_ALIGNED_OPERATOR_NEW T zero()
void reset(const T &initPos, const T &targetPos, double duration)
void reset(const T &initPos, const T &initVel, const T &initAccel, const T &targetPos, const T &targetVel, const T &targetAccel, double duration)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW RetimedPolynomial()
RetimedPolynomial(Polynomial< T > poly, double duration)
double sd(double t) const
void reset(const T &initPos, const T &initVel, const T &targetPos, const T &targetVel, double duration)