Abstract class for cost models. More...
#include <crocoddyl/core/cost-base.hpp>
Public Types | |
typedef ActivationModelAbstractTpl< Scalar > | ActivationModelAbstract |
typedef ActivationModelQuadTpl< Scalar > | ActivationModelQuad |
typedef CostDataAbstractTpl< Scalar > | CostDataAbstract |
typedef DataCollectorAbstractTpl< Scalar > | DataCollectorAbstract |
typedef MathBaseTpl< Scalar > | MathBase |
typedef MathBase::MatrixXs | MatrixXs |
typedef StateAbstractTpl< Scalar > | StateAbstract |
typedef MathBase::VectorXs | VectorXs |
Public Member Functions | |
CostModelAbstractTpl (boost::shared_ptr< StateAbstract > state, boost::shared_ptr< ActivationModelAbstract > activation, const std::size_t nu) | |
Initialize the cost model. More... | |
CostModelAbstractTpl (boost::shared_ptr< StateAbstract > state, boost::shared_ptr< ActivationModelAbstract > activation) | |
CostModelAbstractTpl (boost::shared_ptr< StateAbstract > state, const std::size_t nr, const std::size_t nu) | |
CostModelAbstractTpl (boost::shared_ptr< StateAbstract > state, const std::size_t nr) | |
virtual void | calc (const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)=0 |
Compute the cost value and its residual vector. More... | |
void | calc (const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x) |
virtual void | calcDiff (const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)=0 |
Compute the Jacobian and Hessian of cost and its residual vector. More... | |
void | calcDiff (const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x) |
virtual boost::shared_ptr< CostDataAbstract > | createData (DataCollectorAbstract *const data) |
Create the cost data. More... | |
const boost::shared_ptr< ActivationModelAbstract > & | get_activation () const |
Return the activation model. | |
std::size_t | get_nu () const |
Return the dimension of the control input. | |
template<class ReferenceType > | |
ReferenceType | get_reference () const |
Return the cost reference. | |
const boost::shared_ptr< StateAbstract > & | get_state () const |
Return the state. | |
template<class ReferenceType > | |
void | set_reference (ReferenceType ref) |
Modify the cost reference. | |
Public Attributes | |
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar | Scalar |
Protected Member Functions | |
virtual void | get_referenceImpl (const std::type_info &, void *) const |
virtual void | set_referenceImpl (const std::type_info &, const void *) |
Protected Attributes | |
boost::shared_ptr< ActivationModelAbstract > | activation_ |
Activation model. | |
std::size_t | nu_ |
Control dimension. | |
boost::shared_ptr< StateAbstract > | state_ |
State description. | |
VectorXs | unone_ |
No control vector. | |
Abstract class for cost models.
In Crocoddyl, a cost model is defined by the scalar activation function \(a(\cdot)\) and by the residual function \(\mathbf{r}(\cdot)\) as follows:
\[ cost = a(\mathbf{r}(\mathbf{x}, \mathbf{u})), \]
where the residual function depends on the state point \(\mathbf{x}\in\mathcal{X}\), which lies in the state manifold described with a nq
-tuple, its velocity \(\dot{\mathbf{x}}\in T_{\mathbf{x}}\mathcal{X}\) that belongs to the tangent space with nv
dimension, and the control input \(\mathbf{u}\in\mathbb{R}^{nu}\). The residual vector is defined by \(\mathbf{r}\in\mathbb{R}^{nr}\) where nr
describes its dimension in the Euclidean space. On the other hand, the activation function builds a cost value based on the definition of the residual vector. The residual vector has to be specialized in a derived classes.
The main computations are carring out in calc
and calcDiff
routines. calc
computes the cost (and its residual) and calcDiff
computes the derivatives of the cost function (and its residual). Concretely speaking, calcDiff
builds a linear-quadratic approximation of the cost function with the form: \(\mathbf{l_x}\in\mathbb{R}^{ndx}\), \(\mathbf{l_u}\in\mathbb{R}^{nu}\), \(\mathbf{l_{xx}}\in\mathbb{R}^{ndx\times ndx}\), \(\mathbf{l_{xu}}\in\mathbb{R}^{ndx\times nu}\), \(\mathbf{l_{uu}}\in\mathbb{R}^{nu\times nu}\) are the Jacobians and Hessians, respectively. Additionally, it is important remark that calcDiff()
computes the derivates using the latest stored values by calc()
. Thus, we need to run first calc()
.
Definition at line 47 of file cost-base.hpp.
CostModelAbstractTpl | ( | boost::shared_ptr< StateAbstract > | state, |
boost::shared_ptr< ActivationModelAbstract > | activation, | ||
const std::size_t | nu | ||
) |
Initialize the cost model.
[in] | state | State of the multibody system |
[in] | activation | Activation model |
[in] | nu | Dimension of control vector |
CostModelAbstractTpl | ( | boost::shared_ptr< StateAbstract > | state, |
boost::shared_ptr< ActivationModelAbstract > | activation | ||
) |
Initialize the cost model.
The default nu
value is obtained from StateAbstractTpl::get_nv()
.
[in] | state | State of the multibody system |
[in] | activation | Activation model |
CostModelAbstractTpl | ( | boost::shared_ptr< StateAbstract > | state, |
const std::size_t | nr, | ||
const std::size_t | nu | ||
) |
Initialize the cost model.
We use ActivationModelQuadTpl
as a default activation model (i.e. \(a=\frac{1}{2}\|\mathbf{r}\|^2\))
[in] | state | State of the multibody system |
[in] | nr | Dimension of residual vector |
[in] | nu | Dimension of control vector |
CostModelAbstractTpl | ( | boost::shared_ptr< StateAbstract > | state, |
const std::size_t | nr | ||
) |
Initialize the cost model.
We use ActivationModelQuadTpl
as a default activation model (i.e. \(a=\frac{1}{2}\|\mathbf{r}\|^2\)). Furthermore, the default nu
value is obtained from StateAbstractTpl::get_nv()
.
[in] | state | State of the multibody system |
[in] | nr | Dimension of residual vector |
[in] | nu | Dimension of control vector |
|
pure virtual |
Compute the cost value and its residual vector.
[in] | data | Cost data |
[in] | x | State point \(\mathbf{x}\in\mathbb{R}^{ndx}\) |
[in] | u | Control input \(\mathbf{u}\in\mathbb{R}^{nu}\) |
|
pure virtual |
Compute the Jacobian and Hessian of cost and its residual vector.
It computes the Jacobian and Hessian of the cost function. It assumes that calc()
has been run first.
[in] | data | Cost data |
[in] | x | State point \(\mathbf{x}\in\mathbb{R}^{ndx}\) |
[in] | u | Control input \(\mathbf{u}\in\mathbb{R}^{nu}\) |
|
virtual |
Create the cost data.
The default data contains objects to store the values of the cost, residual vector and their derivatives (first and second order derivatives). However, it is possible to specialized this function is we need to create additional data, for instance, to avoid dynamic memory allocation.
data | Data collector |
Reimplemented in CostModelStateTpl< _Scalar >, CostModelContactCoPPositionTpl< _Scalar >, CostModelContactForceTpl< _Scalar >, CostModelContactFrictionConeTpl< _Scalar >, CostModelImpulseCoPPositionTpl< _Scalar >, CostModelFrameRotationTpl< _Scalar >, CostModelContactImpulseTpl< _Scalar >, CostModelFramePlacementTpl< _Scalar >, CostModelFrameTranslationTpl< _Scalar >, CostModelFrameVelocityTpl< _Scalar >, CostModelCentroidalMomentumTpl< _Scalar >, CostModelControlGravContactTpl< _Scalar >, CostModelCoMPositionTpl< _Scalar >, CostModelControlGravTpl< _Scalar >, CostModelImpulseFrictionConeTpl< _Scalar >, CostModelImpulseCoMTpl< _Scalar >, CostModelNumDiffTpl< _Scalar >, CostModelContactWrenchConeTpl< _Scalar >, and CostModelImpulseWrenchConeTpl< _Scalar >.
void calc | ( | const boost::shared_ptr< CostDataAbstract > & | data, |
const Eigen::Ref< const VectorXs > & | x | ||
) |
Compute the cost value and its residual vector.
[in] | data | Cost data |
[in] | x | State point |
void calcDiff | ( | const boost::shared_ptr< CostDataAbstract > & | data, |
const Eigen::Ref< const VectorXs > & | x | ||
) |
Compute the Jacobian and Hessian of cost and its residual vector.
[in] | data | Cost data |
[in] | x | State point |
|
protectedvirtual |
Modify the cost reference.
Reimplemented in CostModelStateTpl< _Scalar >, CostModelContactCoPPositionTpl< _Scalar >, CostModelContactForceTpl< _Scalar >, CostModelContactFrictionConeTpl< _Scalar >, CostModelControlTpl< _Scalar >, CostModelImpulseCoPPositionTpl< _Scalar >, CostModelFrameRotationTpl< _Scalar >, CostModelContactImpulseTpl< _Scalar >, CostModelFramePlacementTpl< _Scalar >, CostModelFrameTranslationTpl< _Scalar >, CostModelFrameVelocityTpl< _Scalar >, CostModelCentroidalMomentumTpl< _Scalar >, CostModelCoMPositionTpl< _Scalar >, CostModelImpulseFrictionConeTpl< _Scalar >, CostModelContactWrenchConeTpl< _Scalar >, and CostModelImpulseWrenchConeTpl< _Scalar >.
|
protectedvirtual |
Return the cost reference.
Reimplemented in CostModelStateTpl< _Scalar >, CostModelContactCoPPositionTpl< _Scalar >, CostModelContactForceTpl< _Scalar >, CostModelContactFrictionConeTpl< _Scalar >, CostModelControlTpl< _Scalar >, CostModelImpulseCoPPositionTpl< _Scalar >, CostModelFrameRotationTpl< _Scalar >, CostModelContactImpulseTpl< _Scalar >, CostModelFramePlacementTpl< _Scalar >, CostModelFrameTranslationTpl< _Scalar >, CostModelFrameVelocityTpl< _Scalar >, CostModelCentroidalMomentumTpl< _Scalar >, CostModelCoMPositionTpl< _Scalar >, CostModelImpulseFrictionConeTpl< _Scalar >, CostModelContactWrenchConeTpl< _Scalar >, and CostModelImpulseWrenchConeTpl< _Scalar >.