Go to the documentation of this file.
   12     Index _NumCoefficients,
 
   19         Eigen::aligned_allocator<SolutionMatrix> >& _solution)
 
   20   : mTimes(_times), mSolution(_solution)
 
   23     throw std::invalid_argument(
"Mismatch in argument length.");
 
   26     throw std::invalid_argument(
"Times are not monotonically increasing.");
 
   32     Index _NumCoefficients,
 
   44     Index _NumCoefficients,
 
   56     Index _NumCoefficients,
 
   68     Index _NumCoefficients,
 
   80     Index _NumCoefficients,
 
   92     Index _NumCoefficients,
 
  104     Index _NumCoefficients,
 
  110   if (!mSolution.empty())
 
  111     return mSolution.front().rows();
 
  112   else if (NumOutputsAtCompileTime != Eigen::Dynamic)
 
  113     return NumOutputsAtCompileTime;
 
  121     Index _NumCoefficients,
 
  127   if (!mSolution.empty())
 
  128     return mSolution.front().cols();
 
  129   else if (NumCoefficientsAtCompileTime != Eigen::Dynamic)
 
  130     return NumCoefficientsAtCompileTime;
 
  138     Index _NumCoefficients,
 
  144   return getNumCoefficients() - 1;
 
  150     Index _NumCoefficients,
 
  157   if (mTimes.size() > 0)
 
  158     return mTimes[mTimes.size() - 1];
 
  166     Index _NumCoefficients,
 
  172   const Index numKnots = getNumKnots();
 
  178   else if (_t >= mTimes[numKnots - 1])
 
  185         = std::lower_bound(mTimes.data(), mTimes.data() + mTimes.size(), _t);
 
  186     return it - mTimes.data() - 1;
 
  193     Index _NumCoefficients,
 
  202   const Index numOutputs = getNumOutputs();
 
  203   const Index numCoeffs = getNumCoefficients();
 
  206   if (_derivative >= numCoeffs)
 
  208     return OutputVector::Zero(numOutputs);
 
  218       = derivativeVector.cwiseProduct(timeVector);
 
  219   const Index segmentIndex = getSegmentIndex(_t);
 
  224   for (
Index ioutput = 0; ioutput < numOutputs; ++ioutput)
 
  227     output[ioutput] = evaluationVector.dot(solutionVector);
 
  238     Index _NumCoefficients,
 
  243   : 
SplineProblem(_times, NumCoefficientsAtCompileTime, NumOutputsAtCompileTime)
 
  247       "NumCoefficientsAtCompileTime must be static to use this constructor.");
 
  250       "NumOutputsAtCompileTime must be static to use this constructor.");
 
  256     Index _NumCoefficients,
 
  262   : mNumKnots(_times.size())
 
  263   , mNumSegments(std::max<
Index>(mNumKnots - 1, 0))
 
  264   , mNumCoefficients(_numCoefficients)
 
  265   , mNumOutputs(_numOutputs)
 
  266   , mDimension(mNumSegments * _numCoefficients)
 
  267   , mCoefficientMatrix(createCoefficientMatrix(mNumCoefficients))
 
  270   , mA(mDimension, mDimension)
 
  271   , mB(mDimension, _numOutputs)
 
  272   , mSolution(mNumSegments, 
SolutionMatrix(_numOutputs, _numCoefficients))
 
  279     throw std::invalid_argument(
"Times are not monotonically increasing.");
 
  286     Index _NumCoefficients,
 
  293   assert(0 <= _knot && _knot < mNumKnots);
 
  294   assert(0 <= _derivative && _derivative < mNumCoefficients);
 
  295   assert(_value.size() == mNumOutputs);
 
  298       = createTimeVector(mTimes[_knot], _derivative, mNumCoefficients);
 
  300       = mCoefficientMatrix.row(_derivative);
 
  302       = derivativeVector.cwiseProduct(timeVector);
 
  307     assert(mRowIndex < mDimension);
 
  309     Index const colOffset = (_knot - 1) * mNumCoefficients;
 
  310     for (
Index i = 0; i < mNumCoefficients; ++i)
 
  312       mA.coeffRef(mRowIndex, colOffset + i) = coeffVector[i];
 
  315     mB.row(mRowIndex) = _value.transpose();
 
  321   if (_knot + 1 < mNumKnots)
 
  323     assert(mRowIndex < mDimension);
 
  325     Index const colOffset = _knot * mNumCoefficients;
 
  326     for (
Index i = 0; i < mNumCoefficients; ++i)
 
  328       mA.coeffRef(mRowIndex, colOffset + i) = coeffVector[i];
 
  331     mB.row(mRowIndex) = _value.transpose();
 
  340     Index _NumCoefficients,
 
  346   assert(0 <= _knot && _knot < mNumKnots);
 
  347   assert(_knot != 0 && _knot + 1 != mNumKnots);
 
  348   assert(0 <= _derivative && _derivative < mNumCoefficients);
 
  349   assert(mRowIndex < mDimension);
 
  352       = mCoefficientMatrix.row(_derivative);
 
  354       = createTimeVector(mTimes[_knot], _derivative, mNumCoefficients);
 
  356       = derivativeVector.cwiseProduct(timeVector);
 
  358   const Index colOffset1 = (_knot - 1) * mNumCoefficients;
 
  359   for (
Index i = 0; i < mNumCoefficients; ++i)
 
  361     mA.coeffRef(mRowIndex, colOffset1 + i) = coeffVector[i];
 
  364   const Index colOffset2 = _knot * mNumCoefficients;
 
  365   for (
Index i = 0; i < mNumCoefficients; ++i)
 
  367     mA.coeffRef(mRowIndex, colOffset2 + i) = -coeffVector[i];
 
  370   mB.row(mRowIndex).setZero();
 
  378     Index _NumCoefficients,
 
  386   for (
Index j = 0; j < _n; ++j)
 
  390       exponents[j] = std::pow(_t, j - _i);
 
  408     Index _NumCoefficients,
 
  414   assert(mRowIndex == mDimension);
 
  421   Eigen::SparseQR<ProblemMatrix, Eigen::COLAMDOrdering<Index> > solver(mA);
 
  423   for (
Index ioutput = 0; ioutput < mNumOutputs; ++ioutput)
 
  430     Eigen::Matrix<Scalar, Eigen::Dynamic, 1> solutionVector
 
  431         = solver.solve(mB.col(ioutput));
 
  434     for (
Index isegment = 0; isegment < mNumSegments; ++isegment)
 
  437       solutionMatrix.row(ioutput) = solutionVector.segment(
 
  438           isegment * mNumCoefficients, mNumCoefficients);
 
  442   return Spline(mTimes, mSolution);
 
  448     Index _NumCoefficients,
 
  455   coefficients.setZero();
 
  459     coefficients.row(0).setOnes();
 
  462   for (
Index i = 1; i < _n; ++i)
 
  464     for (
Index j = i; j < _n; ++j)
 
  466       coefficients(i, j) = (j - i + 1) * coefficients(i - 1, j);
 
  475     Index _NumCoefficients,
 
  487     Index _NumCoefficients,
 
  499     Index _NumCoefficients,
 
  505   if (mTimes.size() > 0)
 
  507     return mTimes[mTimes.size() - 1];
 
  
 
const SolutionMatrices & getCoefficients() const
Gets polynomial coefficients for all segments.
Definition: Spline-impl.hpp:84
 
ProblemVector mB
Definition: Spline.hpp:323
 
static CoefficientVector createTimeVector(Scalar _t, Index _i, Index _n)
Creates a vector of the form [ 1, t, t^2, ... t^_n ].
Definition: Spline-impl.hpp:382
 
Eigen::Matrix< Scalar, NumCoefficientsAtCompileTime, 1 > CoefficientVector
Definition: Spline.hpp:157
 
Eigen::Matrix< Scalar, NumOutputsAtCompileTime, 1 > OutputVector
Definition: Spline.hpp:59
 
Spline fit()
Fit a spline given the constraints on added to this object.
Definition: Spline-impl.hpp:412
 
Eigen::Matrix< Scalar, NumKnotsAtCompileTime, 1 > TimeVector
Definition: Spline.hpp:209
 
Scalar getDuration() const
Gets the duration of the spline.
Definition: Spline-impl.hpp:154
 
Index getNumCoefficients() const
Gets the number of polynomial coefficients in each segment.
Definition: Spline-impl.hpp:125
 
SplineND()=default
Constructs an empty spline.
 
Eigen::Matrix< Scalar, NumCoefficientsAtCompileTime, 1 > CoefficientVector
Definition: Spline.hpp:214
 
Format of serialized trajectory in YAML.
Definition: algorithm.hpp:4
 
Eigen::Matrix< Scalar, NumKnotsAtCompileTime, 1 > TimeVector
Definition: Spline.hpp:56
 
SplineProblem(const TimeVector &_times)
Constructs a spline fitting problem with the knot points at the specified times.
Definition: Spline-impl.hpp:242
 
static constexpr Index NumOutputsAtCompileTime
Definition: Spline.hpp:198
 
void setTimes(TimeVector &&_t)
Sets the times of all knot points.
Definition: Spline-impl.hpp:48
 
_Index Index
Definition: Spline.hpp:195
 
Scalar getDuration() const
Gets the duration of the spline.
Definition: Spline-impl.hpp:503
 
_Scalar Scalar
Definition: Spline.hpp:194
 
_Index Index
Definition: Spline.hpp:42
 
Index getNumKnots() const
Gets the number of knot points.
Definition: Spline-impl.hpp:96
 
void addConstantConstraint(Index _knot, Index _derivative, const OutputVector &_value)
Adds a constraint that the _derivative-th order derivative of knot point _knot should equal _value.
Definition: Spline-impl.hpp:290
 
Eigen::Matrix< Scalar, NumCoefficientsAtCompileTime, NumCoefficientsAtCompileTime > CoefficientMatrix
Definition: Spline.hpp:161
 
Index getNumKnots() const
Gets the number of knot points.
Definition: Spline-impl.hpp:479
 
Eigen::Matrix< Scalar, NumOutputsAtCompileTime, NumCoefficientsAtCompileTime > SolutionMatrix
Definition: Spline.hpp:58
 
Eigen::Matrix< Scalar, NumOutputsAtCompileTime, NumCoefficientsAtCompileTime > SolutionMatrix
Definition: Spline.hpp:223
 
SolutionMatrices mSolution
Definition: Spline.hpp:164
 
TimeVector mTimes
Definition: Spline.hpp:321
 
Index getNumDerivatives() const
Gets an upperbound on the number of non-zero derivatives.
Definition: Spline-impl.hpp:142
 
Eigen::Matrix< Scalar, NumOutputsAtCompileTime, 1 > OutputVector
Definition: Spline.hpp:210
 
void setTime(Index _index, Scalar _t)
Sets the time of the _index-th knot point.
Definition: Spline-impl.hpp:35
 
static constexpr Index NumCoefficientsAtCompileTime
Definition: Spline.hpp:197
 
static CoefficientMatrix createCoefficientMatrix(Index _n)
Creates the _n by _n matrix of derivative coefficients for a polynomial with _n coefficients.
Definition: Spline-impl.hpp:452
 
Index getSegmentIndex(Scalar _t) const
Gets the index of the segment that contains time _t.
Definition: Spline-impl.hpp:170
 
An arbitrary dimensional polynomial spline.
Definition: Spline.hpp:38
 
void addContinuityConstraint(Index _knot, Index _derivative)
Adds a continuity constraint on the _derivative-th order derivative at knot point _knot.
Definition: Spline-impl.hpp:344
 
std::vector< SolutionMatrix, Eigen::aligned_allocator< SolutionMatrix > > SolutionMatrices
Definition: Spline.hpp:61
 
Index getNumOutputs() const
Gets the number of outputs points.
Definition: Spline-impl.hpp:491
 
Utility for fitting splines given constraints on function value, derivative value,...
Definition: Spline.hpp:191
 
OutputVector evaluate(Scalar _t, Index _derivative=0) const
Evaluate the _derivative-th order of the spline at time _t.
Definition: Spline-impl.hpp:197
 
Eigen::Matrix< Scalar, NumCoefficientsAtCompileTime, NumCoefficientsAtCompileTime > CoefficientMatrix
Definition: Spline.hpp:218
 
const TimeVector & getTimes() const
Gets times of all knot points.
Definition: Spline-impl.hpp:72
 
_Scalar Scalar
Definition: Spline.hpp:41
 
Index getNumOutputs() const
Gets the number of outputs points.
Definition: Spline-impl.hpp:108
 
TimeVector mTimes
Definition: Spline.hpp:163
 
ProblemMatrix mA
Definition: Spline.hpp:322