ACADO Toolkit  1.2.0beta
Toolkit for Automatic Control and Dynamic Optimization
Public Member Functions | Protected Attributes

Allows to work with piecewise-continous function defined over a scalar time interval. More...

#include <curve.hpp>

List of all members.

Public Member Functions

 Curve ()
 Default constructor.
 Curve (const Curve &arg)
 Copy constructor (deep copy).
 ~Curve ()
 Destructor.
Curveoperator= (const Curve &arg)
 Assignment operator (deep copy).
Curve operator() (uint idx) const
returnValue add (double tStart, double tEnd, const Vector constant)
 Adds a constant piece to the curve.
returnValue add (const VariablesGrid &sampledData, InterpolationMode mode=IM_LINEAR)
 Adds new curve pieces, which are given in a sampled form (VariablesGrid).
returnValue add (double tStart, double tEnd, const Function &parameterization_)
 Adds a new piece to the curve, which is defined on the time interval
[tStart,tEnd] to be added.
int getDim () const
 Returns the dimension of the curve.
BooleanType isEmpty () const
 Returns whether the curve is empty.
BooleanType isContinuous () const
 Returns whether the curve is continous.
int getNumIntervals () const
 Returns the number of intervals, on which the pieces of the curve
are defined.
returnValue evaluate (double t, double *result) const
 Evaluates the curve at a given time point.
returnValue evaluate (double t, Vector &result) const
 Evaluates the curve at a given time point.
returnValue evaluate (double tStart, double tEnd, VariablesGrid &result) const
 Evaluates the curve at a given time interval.
returnValue discretize (const Grid &discretizationGrid, VariablesGrid &result) const
 Evaluates the curve at specified grid points and stores the result in form of a
VariablesGrid.
returnValue getTimeDomain (double tStart, double tEnd) const
 Returns the time domain of the curve, i.e.
returnValue getTimeDomain (const uint &idx, double tStart, double tEnd) const
 Returns the time domain of a piece of the curve, i.e.
BooleanType isInTimeDomain (double t) const
 Returns the time domain of the curve, i.e.

Protected Attributes

uint nIntervals
uint dim
Function ** parameterization
Gridgrid

Detailed Description

The class Curve allows to setup and evaluate piecewise-continous functions that are defined over a scalar time interval and map into an Vectorspace of given dimension.

Author:
Boris Houska, Hans Joachim Ferreau

Constructor & Destructor Documentation

References dim, grid, nIntervals, and parameterization.

Curve::Curve ( const Curve arg)

References dim, grid, nIntervals, parameterization, and uint.

References grid, nIntervals, parameterization, and uint.


Member Function Documentation

returnValue Curve::add ( double  tStart,
double  tEnd,
const Vector  constant 
)

If other pieces of the curve have previously
been added, the start time "tStart" of the time interval [tStart,tEnd] should
contain the last time-point of the curve piece which has been added before.
The curve is not required to be continous at the boundaries of its intervals.
Note that the dimension of the constant input vector should have the same
dimensions as previously added curve pieces. If no other piece has been added
before, only tStart < tEnd is required, while the dimension of the curve will
be set to the dimension of the vector, which is added.

Parameters:
tStartstart of the time interval of the curve piece to be added.
tEndend of the time interval to be added.
constantthe constant value of the curve on the interval [tStart,tEnd].

Returns:
SUCCESSFUL_RETURN
RET_TIME_INTERVAL_NOT_VALID
RET_INPUT_DIMENSION_MISMATCH

References VectorspaceElement::getDim(), and uint.

Referenced by add(), SimulationEnvironment::init(), Process::setProcessDisturbance(), LSQTerm::setReference(), and SimulationEnvironment::step().

returnValue Curve::add ( const VariablesGrid sampledData,
InterpolationMode  mode = IM_LINEAR 
)

In
order to store the curve pieces as continous functions the sampled data will be
interpolated depending on an interpolation mode. Note that the number of
intervals, which are added, will depend on this interpolation mode. The default
interpolation mode is "IM_LINEAR", i.e. linear interpolation. In this case the
number of added intervals is coinciding with the number of intervals of the
VariablesGrid, which is passed. For the dimension of the variables grid as well
the grid's start- and endpoint the same policy as for the other "add" functions
applies, i.e. the dimension should be equal to previously added pieces and the
time intervals should fit together.

Parameters:
sampledDatathe data in sampled form to be interpolated and added.
modethe interploation mode (default: linear interpolation)

Returns:
SUCCESSFUL_RETURN
RET_TIME_INTERVAL_NOT_VALID
RET_INPUT_DIMENSION_MISMATCH

References ACADOERROR, add(), Grid::getNumPoints(), MatrixVariablesGrid::getNumRows(), Grid::getTime(), IM_CONSTANT, IM_CUBIC, IM_LINEAR, IM_QUADRATIC, RET_NOT_IMPLEMENTED_YET, SUCCESSFUL_RETURN, and uint.

returnValue Curve::add ( double  tStart,
double  tEnd,
const Function parameterization_ 
)

The function, which is passed as an argument of this
routine, should be the parameterization of the piece of curve to be added. Note
that the input function "parameterization" is only allowed to depend on the time.
If the parameterization depends e.g. on DifferentialStates, Controls etc. an
error message will be returned. As for the other "add" routines the dimension of
function as well as the time interval should fit to the previously added curve
pieces.

Parameters:
tStartstart of the interval to be added.
tEndend of the time interval to be added.
parameterization_the parameterization of the curve on this interval.

Returns:
SUCCESSFUL_RETURN (if successful)
RET_TIME_INTERVAL_NOT_VALID (if the time interval is not valid)
RET_INPUT_DIMENSION_MISMATCH (if the dimension or dependencies are wrong)

References ACADOERROR, acadoIsEqual(), acadoIsStrictlyGreater(), ASSERT, BT_FALSE, BT_TRUE, dim, Function::getDim(), getDim(), Grid::getLastTime(), Function::getNP(), Function::getNPI(), Function::getNU(), Function::getNUI(), Function::getNW(), Function::getNX(), Function::getNXA(), Grid::getTime(), grid, isEmpty(), nIntervals, parameterization, RET_INPUT_DIMENSION_MISMATCH, RET_TIME_INTERVAL_NOT_VALID, SUCCESSFUL_RETURN, and uint.

returnValue Curve::discretize ( const Grid discretizationGrid,
VariablesGrid result 
) const

Note that all time points of the grid, at which the curve should be
evaluated, must be contained in the domain of the curve. This domain can be
obtained with the routine "getTimeDomain( double tStart, double tEnd )".

Parameters:
discretizationGrid(input) the grid points at which the curve should be evaluated.
result(output) the result of the evaluation.


Returns:
SUCCESSFUL_RETURN (if the evaluation was successful.)
RET_INVALID_TIME_POINT (if at least one of the grid points is out of domain.)
RET_MEMBER_NOT_INITIALISED (if the curve is empty)

References dim, evaluate(), Grid::getNumPoints(), Grid::getTime(), VariablesGrid::init(), VariablesGrid::setVector(), SUCCESSFUL_RETURN, and uint.

Referenced by evaluate(), SimulationEnvironment::getFeedbackControl(), SimulationEnvironment::getFeedbackParameter(), and PlotWindowSubplot::PlotWindowSubplot().

returnValue Curve::evaluate ( double  t,
double *  result 
) const

This routine will store
the result of the evaluation into the double *result. Note that
this double pointer must be allocated by the user. Otherwise,
segmentation faults might occur, which can not be prevented by
this routine. For not time critical operations it is recommended to
use the routine

evaluate( const double t, const Vector &result )

instead, which will throw an error if a dimension mismatch occurs.
However, the routine based on double* is slightly more efficient.
In order to make the allocation correct, use the routines isEmpty()
and getDim() first to obtain (or check) the dimension.

Parameters:
t(input) the time at which the curve should be evaluated.
result(output) the result of the evaluation.


Returns:
SUCCESSFUL_RETURN (if the evaluation was successful.)
RET_INVALID_ARGUMENTS (if the double* result is NULL.)
RET_INVALID_TIME_POINT (if the time point t is out of range.)
RET_MEMBER_NOT_INITIALISED (if the curve is empty)

References ACADOERROR, BT_TRUE, EPS, Function::evaluate(), Grid::getFloorIndex(), Grid::getLastTime(), grid, isEmpty(), nIntervals, parameterization, RET_INVALID_ARGUMENTS, RET_INVALID_TIME_POINT, RET_MEMBER_NOT_INITIALISED, SUCCESSFUL_RETURN, and uint.

Referenced by discretize(), evaluate(), Process::init(), LSQTerm::setReference(), FeedforwardLaw::step(), SimulationEnvironment::step(), and Process::step().

returnValue Curve::evaluate ( double  t,
Vector result 
) const

This routine will store
the result of the evaluation into the Vector &result.

Parameters:
t(input) the time at which the curve should be evaluated.
result(output) the result of the evaluation.


Returns:
SUCCESSFUL_RETURN (if the evaluation was successful.)
RET_INVALID_TIME_POINT (if the time point t is out of domain.)
RET_MEMBER_NOT_INITIALISED (if the curve is empty)

References dim, evaluate(), VectorspaceElement::init(), SUCCESSFUL_RETURN, and uint.

returnValue Curve::evaluate ( double  tStart,
double  tEnd,
VariablesGrid result 
) const

This routine will store
the result of the evaluation into the VariablesGrid &result.
Returns as entries in result exactly those nodes of the curve for which the
node times are contained in the interval [tStart,tEnd]

No interpolation is used.

Parameters:
tStart(input) the start time at which the curve should be evaluated.
tEnd(input) the end time at which the curve should be evaluated.
result(output) the result of the evaluation.


Returns:
SUCCESSFUL_RETURN (if the evaluation was successful.)
RET_INVALID_TIME_POINT (if the time point t is out of domain.)
RET_MEMBER_NOT_INITIALISED (if the curve is empty)

References ACADOERROR, discretize(), Grid::getSubGrid(), grid, RET_UNKNOWN_BUG, and SUCCESSFUL_RETURN.

BEGIN_NAMESPACE_ACADO int Curve::getDim ( ) const [inline]

Please note that this routine will return
-1 for the case that the curve is empty (cf. the routine isEmpty() ).

Returns:
the dimension of the curve or -1.

References BT_TRUE, dim, and isEmpty().

Referenced by add(), FeedforwardLaw::getNU(), Process::init(), and operator()().

int Curve::getNumIntervals ( ) const [inline]



Returns:
the number if intervals.

References nIntervals.

Referenced by isEmpty().

returnValue Curve::getTimeDomain ( double  tStart,
double  tEnd 
) const

the time points tStart and tEnd between
which the curve is defined.

Returns:
SUCCESSFUL_RETURN
RET_MEMBER_NOT_INITIALISED (if the curve is empty.)

References ACADOERROR, BT_TRUE, Grid::getFirstTime(), Grid::getLastTime(), grid, isEmpty(), RET_MEMBER_NOT_INITIALISED, and SUCCESSFUL_RETURN.

returnValue Curve::getTimeDomain ( const uint idx,
double  tStart,
double  tEnd 
) const

the interrval [tStart,tEnd] on
which the piece with number "idx" is defined.

Parameters:
idx(input) the index of the curve piece for which the time domain is needed.
tStart(output) the start time of the requested interval.
tEnd(output) the end time of the requested interval.

Returns:
SUCCESSFUL_RETURN (if the domain is successfully returned.)
RET_INDEX_OUT_OF_BOUNDS (if the index "idx" is larger than getNumIntervals())
RET_MEMBER_NOT_INITIALISED (if the curve is empty.)

References ACADOERROR, BT_TRUE, Grid::getNumIntervals(), Grid::getTime(), grid, isEmpty(), RET_INDEX_OUT_OF_BOUNDS, RET_MEMBER_NOT_INITIALISED, and SUCCESSFUL_RETURN.

BooleanType Curve::isContinuous ( ) const [inline]



Returns:
BT_TRUE if the curve is continous.
BT_FALSE otherwise.

References ACADOERROR, ASSERT, BT_FALSE, BT_TRUE, isEmpty(), and RET_NOT_IMPLEMENTED_YET.

BooleanType Curve::isEmpty ( ) const [inline]



Returns:
BT_TRUE if the curve is empty.
BT_FALSE otherwise.

References BT_FALSE, BT_TRUE, and getNumIntervals().

Referenced by add(), evaluate(), getDim(), SimulationEnvironment::getFeedbackControl(), getTimeDomain(), isContinuous(), and isInTimeDomain().

BooleanType Curve::isInTimeDomain ( double  t) const

the time points tStart and tEnd between
which the curve is defined.

Returns:
SUCCESSFUL_RETURN
RET_MEMBER_NOT_INITIALISED (if the curve is empty.)

References acadoIsGreater(), acadoIsSmaller(), BT_FALSE, BT_TRUE, Grid::getFirstTime(), Grid::getLastTime(), grid, and isEmpty().

Referenced by Process::init().

Curve Curve::operator() ( uint  idx) const
Curve & Curve::operator= ( const Curve arg)

References dim, grid, nIntervals, parameterization, and uint.


Member Data Documentation

uint Curve::dim [protected]
Grid* Curve::grid [protected]
uint Curve::nIntervals [protected]

The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines