ACADO Toolkit
1.2.0beta
Toolkit for Automatic Control and Dynamic Optimization
|
Allows to work with piecewise-continous function defined over a scalar time interval. More...
#include <curve.hpp>
Public Member Functions | |
Curve () | |
Default constructor. | |
Curve (const Curve &arg) | |
Copy constructor (deep copy). | |
~Curve () | |
Destructor. | |
Curve & | operator= (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 ¶meterization_) |
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 |
Grid * | grid |
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.
References dim, grid, nIntervals, and parameterization.
Curve::Curve | ( | const Curve & | arg | ) |
References dim, grid, nIntervals, parameterization, and uint.
Curve::~Curve | ( | ) |
References grid, nIntervals, parameterization, and uint.
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.
tStart | start of the time interval of the curve piece to be added. |
tEnd | end of the time interval to be added. |
constant | the constant value of the curve on the interval [tStart,tEnd]. |
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.
sampledData | the data in sampled form to be interpolated and added. |
mode | the interploation mode (default: linear interpolation) |
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.
tStart | start of the interval to be added. |
tEnd | end of the time interval to be added. |
parameterization_ | the parameterization of the curve on this interval. |
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 )".
discretizationGrid | (input) the grid points at which the curve should be evaluated. |
result | (output) the result of the evaluation. |
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.
t | (input) the time at which the curve should be evaluated. |
result | (output) the result of the evaluation. |
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.
t | (input) the time at which the curve should be evaluated. |
result | (output) the result of the evaluation. |
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.
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. |
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() ).
References BT_TRUE, dim, and isEmpty().
Referenced by add(), FeedforwardLaw::getNU(), Process::init(), and operator()().
int Curve::getNumIntervals | ( | ) | const [inline] |
returnValue Curve::getTimeDomain | ( | double | tStart, |
double | tEnd | ||
) | const |
the time points tStart and tEnd between
which the curve is defined.
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.
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. |
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] |
References ACADOERROR, ASSERT, BT_FALSE, BT_TRUE, isEmpty(), and RET_NOT_IMPLEMENTED_YET.
BooleanType Curve::isEmpty | ( | ) | const [inline] |
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.
References acadoIsGreater(), acadoIsSmaller(), BT_FALSE, BT_TRUE, Grid::getFirstTime(), Grid::getLastTime(), grid, and isEmpty().
Referenced by Process::init().
References ACADOERROR, dim, getDim(), grid, nIntervals, parameterization, RET_INDEX_OUT_OF_BOUNDS, and uint.
References dim, grid, nIntervals, parameterization, and uint.
uint Curve::dim [protected] |
Referenced by add(), Curve(), discretize(), evaluate(), getDim(), operator()(), and operator=().
Grid* Curve::grid [protected] |
Referenced by add(), Curve(), evaluate(), getTimeDomain(), isInTimeDomain(), operator()(), operator=(), and ~Curve().
uint Curve::nIntervals [protected] |
Referenced by add(), Curve(), evaluate(), getNumIntervals(), operator()(), operator=(), and ~Curve().
Function** Curve::parameterization [protected] |
Referenced by add(), Curve(), evaluate(), operator()(), operator=(), and ~Curve().