All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
roboptim::trajectory::CubicBSpline Class Reference

Cubic B-Spline trajectory. More...

#include <roboptim/trajectory/cubic-b-spline.hh>

Inheritance diagram for roboptim::trajectory::CubicBSpline:
roboptim::trajectory::Trajectory< 3 >

Public Types

typedef Polynomial3 polynomial_t
 Polynomial type. More...
 
typedef std::vector
< polynomial_t,
Eigen::aligned_allocator
< polynomial_t > > 
basisPolynomials_t
 Basis polynomials type. More...
 
typedef std::vector
< basisPolynomials_t
basisPolynomialsVector_t
 Basis polynomials vector type. More...
 
typedef basisPolynomials_t
polynomials3vector_t 
ROBOPTIM_TRAJECTORY_DEPRECATED
 Legacy typedef. More...
 
typedef
basisPolynomialsVector_t
polynomials3vectors_t 
ROBOPTIM_TRAJECTORY_DEPRECATED
 Legacy typedef. More...
 
typedef vector_t knots_t
 Knot vector type. More...
 
- Public Types inherited from roboptim::trajectory::Trajectory< 3 >
typedef parent_t::interval_t interval_t
 Import interval type. More...
 

Public Member Functions

 CubicBSpline (interval_t timeRange, size_type dimension, const vector_t &parameters, const std::string name="cubic B-Spline", bool clamped=false)
 Instantiate a uniform cubic B-Spline from its definition. More...
 
 CubicBSpline (size_type dimension, const knots_t &knots, const vector_t &parameters, const std::string name="cubic B-Spline")
 Instantiate a cubic B-Spline from its definition. More...
 
 CubicBSpline (const CubicBSpline &spline)
 Copy constructor. More...
 
virtual ~CubicBSpline ()
 
virtual void setParameters (const_vector_ref)
 Modify spline parameters. More...
 
virtual jacobian_t variationConfigWrtParam (value_type t) const
 
virtual jacobian_t variationDerivWrtParam (value_type t, size_type order) const
 
virtual value_type singularPointAtRank (size_type rank) const
 Get singular point at given rank. More...
 
virtual vector_t derivBeforeSingularPoint (size_type rank, size_type order) const
 Get left limit value of derivative at given singular point. More...
 
virtual vector_t derivAfterSingularPoint (size_type rank, size_type order) const
 Get right limit value of derivative at given singular point. More...
 
virtual Trajectory
< derivabilityOrder > * 
resize (interval_t timeRange) const
 Clone and resize a trajectory. More...
 
virtual std::ostream & print (std::ostream &o) const
 Display the function on the specified output stream. More...
 
jacobian_t variationConfigWrtParam (StableTimePoint tp) const
 
jacobian_t variationDerivWrtParam (StableTimePoint tp, size_type order) const
 
template<typename P >
void freezeCurveStart (P &problem, size_type offset=0) const
 Add a constraint to a problem in order to freeze the B-spline at its start. More...
 
template<typename P >
void freezeCurveEnd (P &problem, size_type offset=0) const
 Add a constraint to a problem in order to freeze the B-spline at its end. More...
 
value_type Dt () const ROBOPTIM_TRAJECTORY_DEPRECATED
 Regular spacing between B-spline knots. More...
 
void translateBasisPolynomials (value_type t1)
 Translate the basis polynomials to a given time t1. More...
 
void toPolynomials (basisPolynomials_t &res) const
 Return the polynomial expression of the cubic B-spline on each time interval. More...
 
const basisPolynomialsVector_tbasisPolynomials () const
 Constant getter for the basis polynomials of the cubic B-spline. More...
 
size_type interval (value_type t) const
 Find the index of the interval in which t is. More...
 
size_type getNumberControlPoints () const
 Get the number of control points of the spline. More...
 
const knots_tknotVector () const
 Return the knot vector of the spline. More...
 
CubicBSpline operator+ (const CubicBSpline &s) const
 Add two cubic B-splines, supposing they have the same dimensions. More...
 
void operator+= (const CubicBSpline &s)
 Add a second B-spline to this B-spline. More...
 
int order () const
 Retrieve the order of the spline. More...
 
- Public Member Functions inherited from roboptim::trajectory::Trajectory< 3 >
 ROBOPTIM_NTIMES_DERIVABLE_FUNCTION_FWD_TYPEDEFS_ (NTimesDerivableFunction< DerivabilityOrder >)
 Parent type and imports. More...
 
virtual ~Trajectory ()
 
result_t operator() (StableTimePoint argument) const
 
void operator() (result_ref result, StableTimePoint argument) const
 
derivative_t derivative (StableTimePoint argument, size_type order=1) const
 
void derivative (derivative_ref derivative, StableTimePoint argument, size_type order=1) const
 
bool isValidTime (value_type t) const
 
virtual void normalizeAngles (size_type index)
 Normalize angles in parameters array. More...
 
virtual Trajectory
< DerivabilityOrder > * 
clone () const =0
 
const vector_t & parameters () const
 
interval_t timeRange () const
 
value_type length () const
 
virtual vector_t state (double t, size_type order) const
 Get state along trajectory. More...
 
virtual vector_t state (StableTimePoint t, size_type order) const
 
virtual jacobian_t variationConfigWrtParam (double t) const =0
 Get the variation of a configuration with respect to parameter vector. More...
 
virtual jacobian_t variationDerivWrtParam (double t, size_type order) const =0
 Get the variation of a derivative with respect to parameter vector. More...
 
jacobian_t variationStateWrtParam (double t, size_type order) const
 Get the variation of the state with respect to parameter vector. More...
 
jacobian_t variationStateWrtParam (StableTimePoint stp, size_type order) const
 
size_type singularPoints () const
 Get number of singular points. More...
 
void tolerance (const double &tolerance)
 
double tolerance () const
 Get tolerance for inclusion of parameter in interval of definition. More...
 

Protected Member Functions

void impl_compute (result_ref, value_type) const
 
void impl_derivative (derivative_ref g, value_type x, size_type order) const
 
void impl_derivative (derivative_ref g, StableTimePoint, size_type order) const
 
void computeBasisPolynomials ()
 Compute the basis polynomials for the cubic B-spline. More...
 
vector_t basisFunctions (value_type t, size_type order) const ROBOPTIM_TRAJECTORY_DEPRECATED
 Compute the basis functions for a given instant t. More...
 
- Protected Member Functions inherited from roboptim::trajectory::Trajectory< 3 >
virtual void normalizeAngles (size_type index, size_type offset)
 Internal version of normalizeAngles allowing an optional offset. More...
 
void impl_compute (result_ref, StableTimePoint) const
 
 Trajectory (interval_t, size_type, const vector_t &, std::string name=std::string())
 

Additional Inherited Members

- Protected Attributes inherited from roboptim::trajectory::Trajectory< 3 >
interval_t timeRange_
 
vector_t parameters_
 
size_type singularPoints_
 

Detailed Description

Cubic B-Spline trajectory.

Implement a B-Spline as a trajectory as described in doc/cubic-b-spline.tex

Examples:
spline-optimization.cc, and spline-time-optimization.cc.

Member Typedef Documentation

typedef std::vector< polynomial_t, Eigen::aligned_allocator<polynomial_t> > roboptim::trajectory::CubicBSpline::basisPolynomials_t

Basis polynomials type.

Basis polynomials vector type.

Knot vector type.

Constructor & Destructor Documentation

roboptim::trajectory::CubicBSpline::CubicBSpline ( interval_t  timeRange,
size_type  dimension,
const vector_t &  parameters,
const std::string  name = "cubic B-Spline",
bool  clamped = false 
)

Instantiate a uniform cubic B-Spline from its definition.

Parameters
timeRangespline time range: $ \([t_3,t_n]\)
dimensionspline dimension: \(n\)
parametersvector of parameters defining control points
namefunction title
clampedwhether the spline should be clamped

The number of control points is inferred from the dimension of the parameter vector.

References computeBasisPolynomials(), roboptim::trajectory::Trajectory< 3 >::parameters_, and setParameters().

Referenced by resize().

roboptim::trajectory::CubicBSpline::CubicBSpline ( size_type  dimension,
const knots_t knots,
const vector_t &  parameters,
const std::string  name = "cubic B-Spline" 
)

Instantiate a cubic B-Spline from its definition.

Parameters
dimensionspline dimension: \(n\)
knotsvector of knots,
parametersvector of parameters defining control points
namefunction title

The number of control points is inferred from the dimension of the parameter vector.

References computeBasisPolynomials(), roboptim::trajectory::Trajectory< 3 >::parameters_, and setParameters().

roboptim::trajectory::CubicBSpline::CubicBSpline ( const CubicBSpline spline)

Copy constructor.

Parameters
splinespline that will be copied

References roboptim::trajectory::Trajectory< dorder >::parameters(), roboptim::trajectory::Trajectory< 3 >::parameters_, and setParameters().

roboptim::trajectory::CubicBSpline::~CubicBSpline ( )
virtual

Member Function Documentation

CubicBSpline::vector_t roboptim::trajectory::CubicBSpline::basisFunctions ( value_type  t,
size_type  order 
) const
protected

Compute the basis functions for a given instant t.

Parameters
tinstant considered.
orderorder of the basis functions.
Returns
basis functions evaluated at t.

References Dt(), roboptim::trajectory::detail::fixTime(), interval(), roboptim::trajectory::Trajectory< 3 >::length(), roboptim::trajectory::Trajectory< 3 >::timeRange(), and roboptim::trajectory::Trajectory< 3 >::tolerance().

const basisPolynomialsVector_t& roboptim::trajectory::CubicBSpline::basisPolynomials ( ) const
inline

Constant getter for the basis polynomials of the cubic B-spline.

Returns
constant reference to the basis polynomials.

Note: computeBasisPolynomials() needs to be called beforehand (which is done in the CubicBSpline constructor).

void roboptim::trajectory::CubicBSpline::computeBasisPolynomials ( )
protected

Compute the basis polynomials for the cubic B-spline.

Referenced by CubicBSpline().

CubicBSpline::vector_t roboptim::trajectory::CubicBSpline::derivAfterSingularPoint ( size_type  rank,
size_type  order 
) const
virtual

Get right limit value of derivative at given singular point.

Parameters
rankrank of the singular points.
orderorder of derivation.
Return values
derivativeLimit of the derivative at singular point for decreasing parameter values.

Implements roboptim::trajectory::Trajectory< 3 >.

References roboptim::trajectory::Trajectory< 3 >::derivative(), and singularPointAtRank().

CubicBSpline::vector_t roboptim::trajectory::CubicBSpline::derivBeforeSingularPoint ( size_type  rank,
size_type  order 
) const
virtual

Get left limit value of derivative at given singular point.

Parameters
rankrank of the singular points.
orderorder of derivation.
Returns
Limit of the derivative at singular point for increasing parameter values.

Implements roboptim::trajectory::Trajectory< 3 >.

References roboptim::trajectory::Trajectory< 3 >::derivative(), and singularPointAtRank().

CubicBSpline::value_type roboptim::trajectory::CubicBSpline::Dt ( ) const

Regular spacing between B-spline knots.

This is only valid for uniform B-splines.

Returns
regular spacing between B-spline knots.

References roboptim::trajectory::Trajectory< 3 >::length().

Referenced by basisFunctions().

template<typename P >
void roboptim::trajectory::CubicBSpline::freezeCurveEnd ( P &  problem,
size_type  offset = 0 
) const

Add a constraint to a problem in order to freeze the B-spline at its end.

Parameters
problemproblem to which the constraint will be added.
offsetoffset of the B-spline parameters in the problem's parameter list.
Examples:
spline-optimization.cc.

References interval(), and roboptim::trajectory::Trajectory< 3 >::parameters().

template<typename P >
void roboptim::trajectory::CubicBSpline::freezeCurveStart ( P &  problem,
size_type  offset = 0 
) const

Add a constraint to a problem in order to freeze the B-spline at its start.

Parameters
problemproblem to which the constraint will be added.
offsetoffset of the B-spline parameters in the problem's parameter list.
Examples:
spline-optimization.cc.

References interval(), and roboptim::trajectory::Trajectory< 3 >::parameters().

size_type roboptim::trajectory::CubicBSpline::getNumberControlPoints ( ) const
inline

Get the number of control points of the spline.

Returns
Number of control points of the spline.

Referenced by roboptim::trajectory::visualization::matplotlib::plot_spline().

void roboptim::trajectory::CubicBSpline::impl_compute ( result_ref  ,
value_type   
) const
protected
void roboptim::trajectory::CubicBSpline::impl_derivative ( derivative_ref  g,
value_type  x,
size_type  order 
) const
protected
void roboptim::trajectory::CubicBSpline::impl_derivative ( derivative_ref  g,
StableTimePoint  stp,
size_type  order 
) const
protectedvirtual
CubicBSpline::size_type roboptim::trajectory::CubicBSpline::interval ( value_type  t) const

Find the index of the interval in which t is.

Parameters
tinstant considered.
Returns
index of the interval in which t is.

References roboptim::trajectory::detail::fixTime(), and roboptim::trajectory::Trajectory< 3 >::timeRange().

Referenced by basisFunctions(), freezeCurveEnd(), freezeCurveStart(), and impl_derivative().

const knots_t& roboptim::trajectory::CubicBSpline::knotVector ( ) const
inline

Return the knot vector of the spline.

Returns
knot vector of the spline (const).

Referenced by roboptim::trajectory::visualization::matplotlib::plot_spline().

CubicBSpline roboptim::trajectory::CubicBSpline::operator+ ( const CubicBSpline s) const

Add two cubic B-splines, supposing they have the same dimensions.

Parameters
sother B-spline with the same dimensions.
Returns
S2 = S0 + S1
Exceptions
std::runtime_errorif splines do not have the same dimensions.

References roboptim::trajectory::Trajectory< 3 >::parameters(), roboptim::trajectory::Trajectory< dorder >::parameters(), roboptim::trajectory::Trajectory< 3 >::timeRange(), and roboptim::trajectory::Trajectory< dorder >::timeRange().

void roboptim::trajectory::CubicBSpline::operator+= ( const CubicBSpline s)

Add a second B-spline to this B-spline.

Parameters
sother B-spline with the same dimensions.
Exceptions
std::runtime_errorif splines do not have the same dimensions.

References roboptim::trajectory::Trajectory< 3 >::parameters(), roboptim::trajectory::Trajectory< dorder >::parameters(), setParameters(), roboptim::trajectory::Trajectory< 3 >::timeRange(), and roboptim::trajectory::Trajectory< dorder >::timeRange().

int roboptim::trajectory::CubicBSpline::order ( ) const

Retrieve the order of the spline.

std::ostream & roboptim::trajectory::CubicBSpline::print ( std::ostream &  o) const
virtual

Display the function on the specified output stream.

Parameters
ooutput stream used for display
Returns
output stream

Reimplemented from roboptim::trajectory::Trajectory< 3 >.

References roboptim::trajectory::Trajectory< 3 >::length(), and roboptim::trajectory::Trajectory< 3 >::parameters().

virtual Trajectory<derivabilityOrder>* roboptim::trajectory::CubicBSpline::resize ( interval_t  timeRange) const
inlinevirtual
void roboptim::trajectory::CubicBSpline::setParameters ( const_vector_ref  p)
virtual
CubicBSpline::value_type roboptim::trajectory::CubicBSpline::singularPointAtRank ( size_type  rank) const
virtual
void roboptim::trajectory::CubicBSpline::toPolynomials ( basisPolynomials_t res) const

Return the polynomial expression of the cubic B-spline on each time interval.

ROBOPTIM_DO_NOT_CHECK_ALLOCATION

ROBOPTIM_DO_NOT_CHECK_ALLOCATION

References roboptim::trajectory::Trajectory< 3 >::parameters().

Referenced by roboptim::trajectory::visualization::matplotlib::plot_spline().

void roboptim::trajectory::CubicBSpline::translateBasisPolynomials ( value_type  t1)

Translate the basis polynomials to a given time t1.

Parameters
t1new center time, i.e. P = sum(a_i*(t-t1)^i, i={0,3})

This method can be useful when one needs to have all the polynomials expressed in the same basis (e.g. t1 = 0).

virtual jacobian_t roboptim::trajectory::CubicBSpline::variationConfigWrtParam ( value_type  t) const
virtual
CubicBSpline::jacobian_t roboptim::trajectory::CubicBSpline::variationConfigWrtParam ( StableTimePoint  tp) const
virtual
virtual jacobian_t roboptim::trajectory::CubicBSpline::variationDerivWrtParam ( value_type  t,
size_type  order 
) const
virtual

Referenced by variationDerivWrtParam().

CubicBSpline::jacobian_t roboptim::trajectory::CubicBSpline::variationDerivWrtParam ( StableTimePoint  tp,
size_type  order 
) const
virtual