crocoddyl  1.9.0
Contact RObot COntrol by Differential DYnamic programming Library (Crocoddyl)
CostModelResidualTpl< _Scalar > Class Template Reference

Residual-based cost. More...

#include <crocoddyl/core/costs/residual.hpp>

Inheritance diagram for CostModelResidualTpl< _Scalar >:
Collaboration diagram for CostModelResidualTpl< _Scalar >:

Public Types

typedef ActivationModelAbstractTpl< Scalar > ActivationModelAbstract
 
typedef CostModelAbstractTpl< Scalar > Base
 
typedef CostDataAbstractTpl< Scalar > CostDataAbstract
 
typedef CostDataResidualTpl< Scalar > Data
 
typedef DataCollectorAbstractTpl< Scalar > DataCollectorAbstract
 
typedef MathBaseTpl< Scalar > MathBase
 
typedef MathBase::MatrixXs MatrixXs
 
typedef ResidualModelAbstractTpl< Scalar > ResidualModelAbstract
 
typedef MathBase::VectorXs VectorXs
 
- Public Types inherited from CostModelAbstractTpl< _Scalar >
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 ResidualModelAbstractTpl< Scalar > ResidualModelAbstract
 
typedef StateAbstractTpl< Scalar > StateAbstract
 
typedef MathBase::VectorXs VectorXs
 

Public Member Functions

 CostModelResidualTpl (boost::shared_ptr< typename Base::StateAbstract > state, boost::shared_ptr< ActivationModelAbstract > activation, boost::shared_ptr< ResidualModelAbstract > residual)
 Initialize the residual cost model. More...
 
 CostModelResidualTpl (boost::shared_ptr< typename Base::StateAbstract > state, boost::shared_ptr< ResidualModelAbstract > residual)
 Initialize the residual cost model. More...
 
virtual void calc (const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
 Compute the residual cost based on state only. More...
 
virtual void calc (const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
 Compute the residual cost. More...
 
virtual void calcDiff (const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
 Compute the derivatives of the residual cost with respect to the state only. More...
 
virtual void calcDiff (const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
 Compute the derivatives of the residual cost. More...
 
virtual boost::shared_ptr< CostDataAbstractcreateData (DataCollectorAbstract *const data)
 Create the residual cost data.
 
virtual void print (std::ostream &os) const
 Print relevant information of the cost-residual model. More...
 
- Public Member Functions inherited from CostModelAbstractTpl< _Scalar >
 CostModelAbstractTpl (boost::shared_ptr< StateAbstract > state, boost::shared_ptr< ActivationModelAbstract > activation)
 Initialize the cost model. More...
 
 CostModelAbstractTpl (boost::shared_ptr< StateAbstract > state, boost::shared_ptr< ActivationModelAbstract > activation, boost::shared_ptr< ResidualModelAbstract > residual)
 Initialize the cost model. More...
 
 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< ResidualModelAbstract > residual)
 Initialize the cost model. More...
 
 CostModelAbstractTpl (boost::shared_ptr< StateAbstract > state, const std::size_t nr)
 Initialize the cost model. More...
 
 CostModelAbstractTpl (boost::shared_ptr< StateAbstract > state, const std::size_t nr, const std::size_t nu)
 Initialize the cost model. 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 ()
 Return the cost reference.
 
const boost::shared_ptr< ResidualModelAbstract > & get_residual () const
 Return the residual model.
 
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
 
- Public Attributes inherited from CostModelAbstractTpl< _Scalar >
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar Scalar
 

Protected Attributes

boost::shared_ptr< ActivationModelAbstractactivation_
 Activation model.
 
std::size_t nu_
 Control dimension.
 
boost::shared_ptr< ResidualModelAbstractresidual_
 Residual model.
 
boost::shared_ptr< StateAbstractstate_
 State description.
 
VectorXs unone_
 No control vector.
 
- Protected Attributes inherited from CostModelAbstractTpl< _Scalar >
boost::shared_ptr< ActivationModelAbstractactivation_
 Activation model.
 
std::size_t nu_
 Control dimension.
 
boost::shared_ptr< ResidualModelAbstractresidual_
 Residual model.
 
boost::shared_ptr< StateAbstractstate_
 State description.
 
VectorXs unone_
 No control vector.
 

Additional Inherited Members

- Protected Member Functions inherited from CostModelAbstractTpl< _Scalar >
virtual void get_referenceImpl (const std::type_info &, void *)
 Return the cost reference.
 
virtual void set_referenceImpl (const std::type_info &, const void *)
 Modify the cost reference.
 

Detailed Description

template<typename _Scalar>
class crocoddyl::CostModelResidualTpl< _Scalar >

Residual-based cost.

This cost function uses a residual model to compute the cost, i.e.,

\[ cost = a(\mathbf{r}(\mathbf{x}, \mathbf{u})), \]

where \(\mathbf{r}(\cdot)\) and \(a(\cdot)\) define the residual and activation functions, respectively.

Note that we only compute the Jacobians of the residual function. Therefore, this cost model computes its Hessians through a Gauss-Newton approximation, e.g., \(\mathbf{l_{xu}} = \mathbf{R_x}^T \mathbf{A_{rr}} \mathbf{R_u} \), where \(\mathbf{R_x}\) and \(\mathbf{R_u}\) are the Jacobians of the residual function, and \(\mathbf{A_{rr}}\) is the Hessian of the activation model.

As described in CostModelAbstractTpl(), the cost value and its derivatives are calculated by calc and calcDiff, respectively.

See also
CostModelAbstractTpl, calc(), calcDiff(), createData()

Definition at line 36 of file residual.hpp.

Constructor & Destructor Documentation

◆ CostModelResidualTpl() [1/2]

CostModelResidualTpl ( boost::shared_ptr< typename Base::StateAbstract state,
boost::shared_ptr< ActivationModelAbstract activation,
boost::shared_ptr< ResidualModelAbstract residual 
)

Initialize the residual cost model.

Parameters
[in]stateState of the multibody system
[in]activationActivation model
[in]residualResidual model

◆ CostModelResidualTpl() [2/2]

CostModelResidualTpl ( boost::shared_ptr< typename Base::StateAbstract state,
boost::shared_ptr< ResidualModelAbstract residual 
)

Initialize the residual cost model.

We use ActivationModelQuadTpl as a default activation model (i.e. \(a=\frac{1}{2}\|\mathbf{r}\|^2\)).

Parameters
[in]stateState of the multibody system
[in]residualResidual model

Member Function Documentation

◆ calc() [1/2]

virtual void calc ( const boost::shared_ptr< CostDataAbstract > &  data,
const Eigen::Ref< const VectorXs > &  x,
const Eigen::Ref< const VectorXs > &  u 
)
virtual

Compute the residual cost.

Parameters
[in]dataResidual cost data
[in]xState point \(\mathbf{x}\in\mathbb{R}^{ndx}\)
[in]uControl input \(\mathbf{u}\in\mathbb{R}^{nu}\)

Implements CostModelAbstractTpl< _Scalar >.

◆ calc() [2/2]

virtual void calc ( const boost::shared_ptr< CostDataAbstract > &  data,
const Eigen::Ref< const VectorXs > &  x 
)
virtual

Compute the residual cost based on state only.

It updates the total cost based on the state only. This function is used in the terminal nodes of an optimal control problem.

Parameters
[in]dataResidual cost data
[in]xState point \(\mathbf{x}\in\mathbb{R}^{ndx}\)

Reimplemented from CostModelAbstractTpl< _Scalar >.

◆ calcDiff() [1/2]

virtual void calcDiff ( const boost::shared_ptr< CostDataAbstract > &  data,
const Eigen::Ref< const VectorXs > &  x,
const Eigen::Ref< const VectorXs > &  u 
)
virtual

Compute the derivatives of the residual cost.

Parameters
[in]dataResidual cost data
[in]xState point \(\mathbf{x}\in\mathbb{R}^{ndx}\)
[in]uControl input \(\mathbf{u}\in\mathbb{R}^{nu}\)

Implements CostModelAbstractTpl< _Scalar >.

Reimplemented in CostModelStateTpl< _Scalar >, and CostModelControlTpl< _Scalar >.

◆ calcDiff() [2/2]

virtual void calcDiff ( const boost::shared_ptr< CostDataAbstract > &  data,
const Eigen::Ref< const VectorXs > &  x 
)
virtual

Compute the derivatives of the residual cost with respect to the state only.

It updates the Jacobian and Hessian of the cost function based on the state only. This function is used in the terminal nodes of an optimal control problem.

Parameters
[in]dataResidual cost data
[in]xState point \(\mathbf{x}\in\mathbb{R}^{ndx}\)

Reimplemented from CostModelAbstractTpl< _Scalar >.

◆ print()

virtual void print ( std::ostream &  os) const
virtual

Print relevant information of the cost-residual model.

Parameters
[out]osOutput stream object

Reimplemented from CostModelAbstractTpl< _Scalar >.


The documentation for this class was generated from the following file: