Aikido
aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots > Class Template Reference

Utility for fitting splines given constraints on function value, derivative value, and continuity. More...

#include <aikido/common/Spline.hpp>

Public Types

using Scalar = _Scalar
 
using Index = _Index
 
using TimeVector = Eigen::Matrix< Scalar, NumKnotsAtCompileTime, 1 >
 
using OutputVector = Eigen::Matrix< Scalar, NumOutputsAtCompileTime, 1 >
 
using OutputMatrix = Eigen::Matrix< Scalar, NumCoefficientsAtCompileTime, NumOutputsAtCompileTime >
 
using CoefficientVector = Eigen::Matrix< Scalar, NumCoefficientsAtCompileTime, 1 >
 
using CoefficientMatrix = Eigen::Matrix< Scalar, NumCoefficientsAtCompileTime, NumCoefficientsAtCompileTime >
 
using ProblemMatrix = Eigen::SparseMatrix< Scalar, 0, Index >
 
using ProblemVector = Eigen::Matrix< Scalar, DimensionAtCompileTime, NumOutputsAtCompileTime >
 
using SolutionMatrix = Eigen::Matrix< Scalar, NumOutputsAtCompileTime, NumCoefficientsAtCompileTime >
 
using Spline = SplineND< Scalar, Index, _NumCoefficients, _NumOutputs, _NumKnots >
 

Public Member Functions

 SplineProblem (const TimeVector &_times)
 Constructs a spline fitting problem with the knot points at the specified times. More...
 
 SplineProblem (const TimeVector &_times, Index _numCoefficients, Index _numOutputs)
 Constructs a spline fitting problem with knot points at the specified times and the specified number of coefficients and outputs. More...
 
 SplineProblem (SplineProblem &&_other)=default
 
 SplineProblem (const SplineProblem &_other)=default
 
SplineProblemoperator= (SplineProblem &&_other)=default
 
SplineProblemoperator= (const SplineProblem &_other)=default
 
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. More...
 
void addContinuityConstraint (Index _knot, Index _derivative)
 Adds a continuity constraint on the _derivative-th order derivative at knot point _knot. More...
 
Spline fit ()
 Fit a spline given the constraints on added to this object. More...
 
Index getNumKnots () const
 Gets the number of knot points. More...
 
Index getNumOutputs () const
 Gets the number of outputs points. More...
 
Scalar getDuration () const
 Gets the duration of the spline. More...
 

Static Public Member Functions

static CoefficientVector createTimeVector (Scalar _t, Index _i, Index _n)
 Creates a vector of the form [ 1, t, t^2, ... t^_n ]. More...
 
static CoefficientMatrix createCoefficientMatrix (Index _n)
 Creates the _n by _n matrix of derivative coefficients for a polynomial with _n coefficients. More...
 

Static Public Attributes

static constexpr Index NumCoefficientsAtCompileTime = _NumCoefficients
 
static constexpr Index NumOutputsAtCompileTime = _NumOutputs
 
static constexpr Index NumKnotsAtCompileTime = _NumKnots
 
static constexpr Index NumSegmentsAtCompileTime
 
static constexpr Index DimensionAtCompileTime
 

Private Attributes

Index mNumKnots
 
Index mNumSegments
 
Index mNumCoefficients
 
Index mNumOutputs
 
Index mDimension
 
CoefficientMatrix mCoefficientMatrix
 
Index mRowIndex
 
TimeVector mTimes
 
ProblemMatrix mA
 
ProblemVector mB
 
std::vector< SolutionMatrix, Eigen::aligned_allocator< SolutionMatrix > > mSolution
 

Detailed Description

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
class aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >

Utility for fitting splines given constraints on function value, derivative value, and continuity.

This class is intended to be used by calling methods to add constraints to the spline, then calling fit() to find spline coefficients that satisfy those constraints.

The number of coefficients, outputs, and knot points may be specified either at compile time (via template parameters) or at runtime (if the template parameters are Eigen::Dynamic). We suggest setting as many of these parameters at compile time as possible for best performance.

Template Parameters
_Scalarfloating type used to represent a scalar value
_Indexintegral type used to represent an index
_NumCoefficientsnumber of polynomial coefficients, or Dynamic
_NumOutputsnumber of outputs, or Dynamic
_NumKnotsnumber of knots, or Dynamic

Member Typedef Documentation

◆ CoefficientMatrix

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
using aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::CoefficientMatrix = Eigen::Matrix< Scalar, NumCoefficientsAtCompileTime, NumCoefficientsAtCompileTime>

◆ CoefficientVector

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
using aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::CoefficientVector = Eigen::Matrix<Scalar, NumCoefficientsAtCompileTime, 1>

◆ Index

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
using aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::Index = _Index

◆ OutputMatrix

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
using aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::OutputMatrix = Eigen:: Matrix<Scalar, NumCoefficientsAtCompileTime, NumOutputsAtCompileTime>

◆ OutputVector

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
using aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::OutputVector = Eigen::Matrix<Scalar, NumOutputsAtCompileTime, 1>

◆ ProblemMatrix

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
using aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::ProblemMatrix = Eigen::SparseMatrix<Scalar, 0, Index>

◆ ProblemVector

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
using aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::ProblemVector = Eigen::Matrix<Scalar, DimensionAtCompileTime, NumOutputsAtCompileTime>

◆ Scalar

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
using aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::Scalar = _Scalar

◆ SolutionMatrix

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
using aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::SolutionMatrix = Eigen:: Matrix<Scalar, NumOutputsAtCompileTime, NumCoefficientsAtCompileTime>

◆ Spline

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
using aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::Spline = SplineND<Scalar, Index, _NumCoefficients, _NumOutputs, _NumKnots>

◆ TimeVector

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
using aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::TimeVector = Eigen::Matrix<Scalar, NumKnotsAtCompileTime, 1>

Constructor & Destructor Documentation

◆ SplineProblem() [1/4]

template<class Scalar , class Index , Index _NumCoefficients, Index _NumOutputs, Index _NumKnots>
aikido::common::SplineProblem< Scalar, Index, _NumCoefficients, _NumOutputs, _NumKnots >::SplineProblem ( const TimeVector _times)
explicit

Constructs a spline fitting problem with the knot points at the specified times.

This overload is only supported if _NumCoefficients and _NumOutputs are specified as template parameters. The length of _times must equal _NumKnots if that template parameter is specified

If _NumCoefficients or _NumOutputs is Eigen::Dynamic, you must use the other constructor overload.

Parameters
_timeslist of knot point times, must be monotone increasing

◆ SplineProblem() [2/4]

template<class Scalar , class Index , Index _NumCoefficients, Index _NumOutputs, Index _NumKnots>
aikido::common::SplineProblem< Scalar, Index, _NumCoefficients, _NumOutputs, _NumKnots >::SplineProblem ( const TimeVector _times,
Index  _numCoefficients,
Index  _numOutputs 
)

Constructs a spline fitting problem with knot points at the specified times and the specified number of coefficients and outputs.

These parameters must match _NumKnots and _NumCoefficients if they are specified at compile time. Additionally, the length of _times must match _NumKnots if that template parameter is specified.

Parameters
_timeslist of knot point times, must be monotone increasing
_numCoefficientsnumber of polynomial coefficients
_numOutputsnumber of outputs

◆ SplineProblem() [3/4]

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::SplineProblem ( SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots > &&  _other)
default

◆ SplineProblem() [4/4]

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::SplineProblem ( const SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots > &  _other)
default

Member Function Documentation

◆ addConstantConstraint()

template<class Scalar , class Index , Index _NumCoefficients, Index _NumOutputs, Index _NumKnots>
void aikido::common::SplineProblem< Scalar, Index, _NumCoefficients, _NumOutputs, _NumKnots >::addConstantConstraint ( Index  _knot,
Index  _derivative,
const OutputVector _value 
)

Adds a constraint that the _derivative-th order derivative of knot point _knot should equal _value.

This adds one constraint if the knot is an end point and two constraints for interior knots. The zero-th derivative is function value.

Parameters
_knotknot index to constraint
_derivativeorder of derivative to constraint
_valuedesired value of that knot point's derivative

◆ addContinuityConstraint()

template<class Scalar , class Index , Index _NumCoefficients, Index _NumOutputs, Index _NumKnots>
void aikido::common::SplineProblem< Scalar, Index, _NumCoefficients, _NumOutputs, _NumKnots >::addContinuityConstraint ( Index  _knot,
Index  _derivative 
)

Adds a continuity constraint on the _derivative-th order derivative at knot point _knot.

This operation is only defined for interior knot points and adds one constraint.

Parameters
_knotknot index to constraint
_derivativeorder of derivative to constraint

◆ createCoefficientMatrix()

template<class Scalar , class Index , Index _NumCoefficients, Index _NumOutputs, Index _NumKnots>
auto aikido::common::SplineProblem< Scalar, Index, _NumCoefficients, _NumOutputs, _NumKnots >::createCoefficientMatrix ( Index  _n)
static

Creates the _n by _n matrix of derivative coefficients for a polynomial with _n coefficients.

The i-th row of this matrix corresponds to coefficients for the i-th derivative. The j-th column of this matrix corresponds to the coefficient on x^j.

Parameters
_nnumber of coefficients
Returns
polynomial coefficient matrix

◆ createTimeVector()

template<class Scalar , class Index , Index _NumCoefficients, Index _NumOutputs, Index _NumKnots>
auto aikido::common::SplineProblem< Scalar, Index, _NumCoefficients, _NumOutputs, _NumKnots >::createTimeVector ( Scalar  _t,
Index  _i,
Index  _n 
)
static

Creates a vector of the form [ 1, t, t^2, ... t^_n ].

◆ fit()

template<class Scalar , class Index , Index _NumCoefficients, Index _NumOutputs, Index _NumKnots>
auto aikido::common::SplineProblem< Scalar, Index, _NumCoefficients, _NumOutputs, _NumKnots >::fit

Fit a spline given the constraints on added to this object.

The behavior of this function is undefined if the problem is over or under-constrained. To avoid this, be sure to only add (num coefficients) * (num knots - 1) constraints to this class.

Returns
spline that satisfies the constraints

◆ getDuration()

template<class Scalar , class Index , Index _NumCoefficients, Index _NumOutputs, Index _NumKnots>
Scalar aikido::common::SplineProblem< Scalar, Index, _NumCoefficients, _NumOutputs, _NumKnots >::getDuration

Gets the duration of the spline.

This is the difference between the time of the first and last knot points.

Returns
duration of the spline

◆ getNumKnots()

template<class Scalar , class Index , Index _NumCoefficients, Index _NumOutputs, Index _NumKnots>
Index aikido::common::SplineProblem< Scalar, Index, _NumCoefficients, _NumOutputs, _NumKnots >::getNumKnots

Gets the number of knot points.

Returns
number of knot points

◆ getNumOutputs()

template<class Scalar , class Index , Index _NumCoefficients, Index _NumOutputs, Index _NumKnots>
Index aikido::common::SplineProblem< Scalar, Index, _NumCoefficients, _NumOutputs, _NumKnots >::getNumOutputs

Gets the number of outputs points.

Returns
number of outputs points

◆ operator=() [1/2]

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
SplineProblem& aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::operator= ( const SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots > &  _other)
default

◆ operator=() [2/2]

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
SplineProblem& aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::operator= ( SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots > &&  _other)
default

Member Data Documentation

◆ DimensionAtCompileTime

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
constexpr Index aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::DimensionAtCompileTime
staticconstexpr
Initial value:
= (NumSegmentsAtCompileTime != Eigen::Dynamic
&& _NumCoefficients != Eigen::Dynamic)
: Eigen::Dynamic

◆ mA

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
ProblemMatrix aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::mA
private

◆ mB

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
ProblemVector aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::mB
private

◆ mCoefficientMatrix

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
CoefficientMatrix aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::mCoefficientMatrix
private

◆ mDimension

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
Index aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::mDimension
private

◆ mNumCoefficients

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
Index aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::mNumCoefficients
private

◆ mNumKnots

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
Index aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::mNumKnots
private

◆ mNumOutputs

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
Index aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::mNumOutputs
private

◆ mNumSegments

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
Index aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::mNumSegments
private

◆ mRowIndex

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
Index aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::mRowIndex
private

◆ mSolution

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
std::vector< SolutionMatrix, Eigen::aligned_allocator<SolutionMatrix> > aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::mSolution
private

◆ mTimes

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
TimeVector aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::mTimes
private

◆ NumCoefficientsAtCompileTime

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
constexpr Index aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::NumCoefficientsAtCompileTime = _NumCoefficients
staticconstexpr

◆ NumKnotsAtCompileTime

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
constexpr Index aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::NumKnotsAtCompileTime = _NumKnots
staticconstexpr

◆ NumOutputsAtCompileTime

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
constexpr Index aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::NumOutputsAtCompileTime = _NumOutputs
staticconstexpr

◆ NumSegmentsAtCompileTime

template<class _Scalar = double, class _Index = int, _Index _NumCoefficients = Eigen::Dynamic, _Index _NumOutputs = Eigen::Dynamic, _Index _NumKnots = Eigen::Dynamic>
constexpr Index aikido::common::SplineProblem< _Scalar, _Index, _NumCoefficients, _NumOutputs, _NumKnots >::NumSegmentsAtCompileTime
staticconstexpr
Initial value:
= (_NumKnots != Eigen::Dynamic) ? (NumKnotsAtCompileTime - 1)
: Eigen::Dynamic
aikido::common::SplineProblem::NumSegmentsAtCompileTime
static constexpr Index NumSegmentsAtCompileTime
Definition: Spline.hpp:201
aikido::common::SplineProblem::NumCoefficientsAtCompileTime
static constexpr Index NumCoefficientsAtCompileTime
Definition: Spline.hpp:197
aikido::common::SplineProblem::NumKnotsAtCompileTime
static constexpr Index NumKnotsAtCompileTime
Definition: Spline.hpp:199