- 3.0.2 optimal control module.
|
An interface for a term, supporting both analytical and auto-diff terms. More...
#include <TermBase.hpp>
Public Types | |
typedef Eigen::Matrix< SCALAR_EVAL, STATE_DIM, STATE_DIM > | state_matrix_t |
typedef Eigen::Matrix< SCALAR_EVAL, CONTROL_DIM, CONTROL_DIM > | control_matrix_t |
typedef Eigen::Matrix< SCALAR_EVAL, CONTROL_DIM, STATE_DIM > | control_state_matrix_t |
typedef Eigen::Matrix< SCALAR_EVAL, STATE_DIM, STATE_DIM > | state_matrix_double_t |
typedef Eigen::Matrix< SCALAR_EVAL, CONTROL_DIM, CONTROL_DIM > | control_matrix_double_t |
typedef Eigen::Matrix< SCALAR_EVAL, CONTROL_DIM, STATE_DIM > | control_state_matrix_double_t |
Public Member Functions | |
TermBase (std::string name="Unnamed") | |
Default constructor. More... | |
TermBase (const TermBase &arg) | |
Copy Cunstructor. More... | |
virtual TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR > * | clone () const =0 |
Deep-copy term. More... | |
virtual | ~TermBase () |
Destructor. More... | |
virtual SCALAR | evaluate (const Eigen::Matrix< SCALAR, STATE_DIM, 1 > &x, const Eigen::Matrix< SCALAR, CONTROL_DIM, 1 > &u, const SCALAR &t)=0 |
Evaluates the term at x, u, t. More... | |
SCALAR_EVAL | eval (const Eigen::Matrix< SCALAR_EVAL, STATE_DIM, 1 > &x, const Eigen::Matrix< SCALAR_EVAL, CONTROL_DIM, 1 > &u, const SCALAR_EVAL &t) |
Gets called by the analytical costfunction. Adds time dependent activations on top of the term. More... | |
virtual bool | isActiveAtTime (SCALAR_EVAL t) |
Returns if term is non-zero at a specific time By default, all terms are evaluated at all times. However, if a term is not active at a certain time, you can overload this function to spare evaluations of the term and its derivatives. More... | |
SCALAR_EVAL | computeActivation (SCALAR_EVAL t) |
compute time activation More... | |
virtual core::StateVector< STATE_DIM, SCALAR_EVAL > | stateDerivative (const core::StateVector< STATE_DIM, SCALAR_EVAL > &x, const core::ControlVector< CONTROL_DIM, SCALAR_EVAL > &u, const SCALAR_EVAL &t) |
compute derivative of this cost term w.r.t. the state More... | |
virtual state_matrix_t | stateSecondDerivative (const core::StateVector< STATE_DIM, SCALAR_EVAL > &x, const core::ControlVector< CONTROL_DIM, SCALAR_EVAL > &u, const SCALAR_EVAL &t) |
compute second order derivative of this cost term w.r.t. the state More... | |
virtual core::ControlVector< CONTROL_DIM, SCALAR_EVAL > | controlDerivative (const core::StateVector< STATE_DIM, SCALAR_EVAL > &x, const core::ControlVector< CONTROL_DIM, SCALAR_EVAL > &u, const SCALAR_EVAL &t) |
compute derivative of this cost term w.r.t. the control input More... | |
virtual control_matrix_t | controlSecondDerivative (const core::StateVector< STATE_DIM, SCALAR_EVAL > &x, const core::ControlVector< CONTROL_DIM, SCALAR_EVAL > &u, const SCALAR_EVAL &t) |
compute second order derivative of this cost term w.r.t. the control input More... | |
virtual control_state_matrix_t | stateControlDerivative (const core::StateVector< STATE_DIM, SCALAR_EVAL > &x, const core::ControlVector< CONTROL_DIM, SCALAR_EVAL > &u, const SCALAR_EVAL &t) |
compute the cross-term derivative (state-control) of this cost function term More... | |
virtual void | loadConfigFile (const std::string &filename, const std::string &termName, bool verbose=false) |
load this term from a configuration file More... | |
void | setTimeActivation (std::shared_ptr< ct::core::tpl::ActivationBase< SCALAR_EVAL >> c_i, bool verbose=false) |
set the time activation functions for this term More... | |
void | loadTimeActivation (const std::string &filename, const std::string &termName, bool verbose=false) |
load the time activation functions for this term from file More... | |
const std::string & | getName () const |
Returns the name of the term. More... | |
void | setName (const std::string &termName) |
Sets the name of the term. More... | |
virtual void | updateReferenceState (const Eigen::Matrix< SCALAR_EVAL, STATE_DIM, 1 > &newRefState) |
updates the reference state for this term More... | |
virtual void | updateReferenceControl (const Eigen::Matrix< SCALAR_EVAL, CONTROL_DIM, 1 > &newRefControl) |
updates the reference control for this term More... | |
virtual Eigen::Matrix< SCALAR_EVAL, STATE_DIM, 1 > | getReferenceState () const |
retrieve this term's current reference state More... | |
Protected Attributes | |
std::string | name_ |
a name identifier for this term More... | |
std::shared_ptr< ct::core::tpl::ActivationBase< SCALAR_EVAL > > | c_i_ |
time activations for this term More... | |
An interface for a term, supporting both analytical and auto-diff terms.
Derive from this term to implement your own term. You only have to implement evaluateCppadCg() if you want to use auto-diff. Otherwise, you need to implement evaluate() as well as the derivatives. In case you want to go for the most general implementation, you can implement a local, templated evalLocal() method in derived terms, which gets called by evaluate() and evaluateCppadCg(), see e.g. TermLinear.
An example for an implementation of a custom term is given in TermQuadratic.hpp
typedef Eigen::Matrix<SCALAR_EVAL, STATE_DIM, STATE_DIM> ct::optcon::TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::state_matrix_t |
typedef Eigen::Matrix<SCALAR_EVAL, CONTROL_DIM, CONTROL_DIM> ct::optcon::TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::control_matrix_t |
typedef Eigen::Matrix<SCALAR_EVAL, CONTROL_DIM, STATE_DIM> ct::optcon::TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::control_state_matrix_t |
typedef Eigen::Matrix<SCALAR_EVAL, STATE_DIM, STATE_DIM> ct::optcon::TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::state_matrix_double_t |
typedef Eigen::Matrix<SCALAR_EVAL, CONTROL_DIM, CONTROL_DIM> ct::optcon::TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::control_matrix_double_t |
typedef Eigen::Matrix<SCALAR_EVAL, CONTROL_DIM, STATE_DIM> ct::optcon::TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::control_state_matrix_double_t |
TermBase::TermBase | ( | std::string | name = "Unnamed" | ) |
Default constructor.
name | Name of the term |
TermBase::TermBase | ( | const TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR > & | arg | ) |
Copy Cunstructor.
arg | The term to copy |
|
virtual |
Destructor.
|
pure virtual |
Deep-copy term.
Implemented in ct::optcon::example::TestTerm< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermQuadMult< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermQuadratic< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermStateBarrier< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermMixed< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermSmoothAbs< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermQuadTracking< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, and ct::optcon::TermLinear< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >.
|
pure virtual |
Evaluates the term at x, u, t.
[in] | x | The current state |
[in] | u | The current control |
[in] | t | The current time |
Implemented in ct::optcon::example::TestTerm< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermQuadratic< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermQuadMult< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermMixed< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermQuadTracking< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermSmoothAbs< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermStateBarrier< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, and ct::optcon::TermLinear< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >.
Referenced by ct::optcon::TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::eval().
SCALAR_EVAL TermBase::eval | ( | const Eigen::Matrix< SCALAR_EVAL, STATE_DIM, 1 > & | x, |
const Eigen::Matrix< SCALAR_EVAL, CONTROL_DIM, 1 > & | u, | ||
const SCALAR_EVAL & | t | ||
) |
Gets called by the analytical costfunction. Adds time dependent activations on top of the term.
[in] | x | The current state |
[in] | u | The current control |
[in] | t | The current time |
References ct::optcon::TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::computeActivation(), ct::optcon::TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::evaluate(), ct::optcon::TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::name_, t, u, and x.
|
virtual |
Returns if term is non-zero at a specific time By default, all terms are evaluated at all times. However, if a term is not active at a certain time, you can overload this function to spare evaluations of the term and its derivatives.
t | time |
References ct::optcon::TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::c_i_.
SCALAR_EVAL TermBase::computeActivation | ( | SCALAR_EVAL | t | ) |
|
virtual |
compute derivative of this cost term w.r.t. the state
Reimplemented in ct::optcon::TermQuadratic< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermQuadMult< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermMixed< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermSmoothAbs< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermQuadTracking< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, and ct::optcon::TermLinear< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >.
|
virtual |
compute second order derivative of this cost term w.r.t. the state
Reimplemented in ct::optcon::TermQuadratic< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermQuadMult< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermMixed< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermSmoothAbs< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermQuadTracking< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, and ct::optcon::TermLinear< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >.
|
virtual |
compute derivative of this cost term w.r.t. the control input
Reimplemented in ct::optcon::TermQuadratic< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermQuadMult< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermMixed< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermSmoothAbs< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermQuadTracking< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, and ct::optcon::TermLinear< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >.
|
virtual |
compute second order derivative of this cost term w.r.t. the control input
Reimplemented in ct::optcon::TermQuadratic< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermQuadMult< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermMixed< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermSmoothAbs< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermQuadTracking< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, and ct::optcon::TermLinear< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >.
|
virtual |
compute the cross-term derivative (state-control) of this cost function term
Reimplemented in ct::optcon::TermQuadratic< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermQuadMult< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermMixed< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermSmoothAbs< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermQuadTracking< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, and ct::optcon::TermLinear< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >.
|
virtual |
load this term from a configuration file
Reimplemented in ct::optcon::TermQuadratic< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermQuadMult< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermMixed< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermSmoothAbs< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermQuadTracking< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, ct::optcon::TermLinear< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, and ct::optcon::TermStateBarrier< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >.
void TermBase::setTimeActivation | ( | std::shared_ptr< ct::core::tpl::ActivationBase< SCALAR_EVAL >> | c_i, |
bool | verbose = false |
||
) |
set the time activation functions for this term
References ct::optcon::TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::c_i_.
void TermBase::loadTimeActivation | ( | const std::string & | filename, |
const std::string & | termName, | ||
bool | verbose = false |
||
) |
load the time activation functions for this term from file
References ct::optcon::TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::c_i_, and CT_LOADABLE_ACTIVATIONS.
const std::string & TermBase::getName | ( | ) | const |
Returns the name of the term.
termName | name of the term |
References ct::optcon::TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::name_.
void TermBase::setName | ( | const std::string & | termName | ) |
Sets the name of the term.
termName |
References ct::optcon::TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::name_.
|
virtual |
updates the reference state for this term
Reimplemented in ct::optcon::TermQuadratic< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >, and ct::optcon::TermMixed< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >.
|
virtual |
updates the reference control for this term
Reimplemented in ct::optcon::TermQuadratic< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >.
|
virtual |
retrieve this term's current reference state
Reimplemented in ct::optcon::TermQuadratic< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >.
|
protected |
a name identifier for this term
Referenced by ct::optcon::TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::eval(), ct::optcon::TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::getName(), ct::optcon::TermMixed< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::loadConfigFile(), ct::optcon::TermQuadratic< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::loadConfigFile(), and ct::optcon::TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::setName().
|
protected |
time activations for this term
Referenced by ct::optcon::TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::computeActivation(), ct::optcon::TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::isActiveAtTime(), ct::optcon::TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::loadTimeActivation(), and ct::optcon::TermBase< STATE_DIM, CONTROL_DIM, SCALAR_EVAL, SCALAR >::setTimeActivation().