Crocoddyl
 
Loading...
Searching...
No Matches
ConstraintModelResidualTpl< _Scalar > Class Template Reference

Residual-based constraint. More...

#include <residual.hpp>

Inheritance diagram for ConstraintModelResidualTpl< _Scalar >:
ConstraintModelAbstractTpl< _Scalar >

Public Types

typedef ConstraintModelAbstractTpl< Scalar > Base
 
typedef ConstraintDataAbstractTpl< Scalar > ConstraintDataAbstract
 
typedef ConstraintDataResidualTpl< Scalar > Data
 
typedef MathBaseTpl< Scalar > MathBase
 
typedef ResidualModelAbstractTpl< Scalar > ResidualModelAbstract
 
typedef MathBase::VectorXs VectorXs
 
- Public Types inherited from ConstraintModelAbstractTpl< _Scalar >
typedef ConstraintDataAbstractTpl< Scalar > ConstraintDataAbstract
 
typedef DataCollectorAbstractTpl< Scalar > DataCollectorAbstract
 
typedef MathBaseTpl< Scalar > MathBase
 
typedef ResidualModelAbstractTpl< Scalar > ResidualModelAbstract
 
typedef StateAbstractTpl< Scalar > StateAbstract
 
typedef MathBase::VectorXs VectorXs
 

Public Member Functions

 ConstraintModelResidualTpl (std::shared_ptr< typename Base::StateAbstract > state, std::shared_ptr< ResidualModelAbstract > residual, const bool T_act=true)
 Initialize the residual constraint model as an equality constraint.
 
 ConstraintModelResidualTpl (std::shared_ptr< typename Base::StateAbstract > state, std::shared_ptr< ResidualModelAbstract > residual, const VectorXs &lower, const VectorXs &upper, const bool T_act=true)
 Initialize the residual constraint model as an inequality constraint.
 
virtual void calc (const std::shared_ptr< ConstraintDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
 Compute the residual constraint based on state only.
 
virtual void calc (const std::shared_ptr< ConstraintDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
 Compute the residual constraint.
 
virtual void calcDiff (const std::shared_ptr< ConstraintDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
 Compute the derivatives of the residual constraint with respect to the state only.
 
virtual void calcDiff (const std::shared_ptr< ConstraintDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
 Compute the derivatives of the residual constraint.
 
virtual std::shared_ptr< ConstraintDataAbstractcreateData (DataCollectorAbstract *const data)
 Create the residual constraint data.
 
virtual void print (std::ostream &os) const
 Print relevant information of the cost-residual model.
 
- Public Member Functions inherited from ConstraintModelAbstractTpl< _Scalar >
 ConstraintModelAbstractTpl (std::shared_ptr< StateAbstract > state, const std::size_t ng, const std::size_t nh, const bool T_const=true)
 
 ConstraintModelAbstractTpl (std::shared_ptr< StateAbstract > state, const std::size_t nu, const std::size_t ng, const std::size_t nh, const bool T_const=true)
 the constraint model
 
 ConstraintModelAbstractTpl (std::shared_ptr< StateAbstract > state, std::shared_ptr< ResidualModelAbstract > residual, const std::size_t ng, const std::size_t nh)
 Initialize the constraint model.
 
const VectorXs & get_lb () const
 Return the lower bound of the constraint.
 
std::size_t get_ng () const
 Return the number of inequality constraints.
 
std::size_t get_nh () const
 Return the number of equality constraints.
 
std::size_t get_nu () const
 Return the dimension of the control input.
 
const std::shared_ptr< ResidualModelAbstract > & get_residual () const
 Return the residual model.
 
const std::shared_ptr< StateAbstract > & get_state () const
 Return the state.
 
bool get_T_constraint () const
 Return true if the constraint is imposed in terminal nodes as well.
 
ConstraintType get_type () const
 Return the type of constraint.
 
const VectorXs & get_ub () const
 Return the upper bound of the constraint.
 
void remove_bounds ()
 Remove the bounds of the constraint.
 
void update_bounds (const VectorXs &lower, const VectorXs &upper)
 Update the lower and upper bounds the upper bound of constraint.
 

Public Attributes

EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar Scalar
 
- Public Attributes inherited from ConstraintModelAbstractTpl< _Scalar >
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar Scalar
 

Protected Attributes

VectorXs lb_
 Lower bound of the constraint.
 
std::size_t ng_
 Number of inequality constraints.
 
std::size_t nh_
 Number of equality constraints.
 
std::size_t nu_
 Control dimension.
 
std::shared_ptr< ResidualModelAbstractresidual_
 Residual model.
 
std::shared_ptr< StateAbstractstate_
 State description.
 
bool T_constraint_
 
ConstraintType type_
 Type of constraint: inequality=0, equality=1, both=2.
 
VectorXs ub_
 Upper bound of the constraint.
 
VectorXs unone_
 No control vector.
 
- Protected Attributes inherited from ConstraintModelAbstractTpl< _Scalar >
VectorXs lb_
 Lower bound of the constraint.
 
std::size_t ng_
 Number of inequality constraints.
 
std::size_t nh_
 Number of equality constraints.
 
std::size_t nu_
 Control dimension.
 
std::shared_ptr< ResidualModelAbstractresidual_
 Residual model.
 
std::shared_ptr< StateAbstractstate_
 State description.
 
bool T_constraint_
 
ConstraintType type_
 Type of constraint: inequality=0, equality=1, both=2.
 
VectorXs ub_
 Upper bound of the constraint.
 
VectorXs unone_
 No control vector.
 

Detailed Description

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

Residual-based constraint.

This constraint function uses a residual model to define equality / inequality constraint as

\[ \mathbf{\underline{r}} \leq \mathbf{r}(\mathbf{x}, \mathbf{u}) \leq \mathbf{\bar{r}} \]

where \(\mathbf{r}(\cdot)\) describes the residual function, and \(\mathbf{\underline{r}}\), \(\mathbf{\bar{r}}\) are the lower and upper bounds, respectively. We can define element-wise equality constraints by defining the same value for both: lower and upper values. Additionally, if we do not define the bounds, then it is assumed that \(\mathbf{\underline{r}}=\mathbf{\bar{r}}=\mathbf{0}\).

The main computations are carring out in calc and calcDiff routines. calc computes the constraint residual and calcDiff computes the Jacobians of the constraint function. Concretely speaking, calcDiff builds a linear approximation of the constraint function with the form: \(\mathbf{g_x}\in\mathbb{R}^{ng\times ndx}\), \(\mathbf{g_u}\in\mathbb{R}^{ng\times nu}\), \(\mathbf{h_x}\in\mathbb{R}^{nh\times ndx}\) \(\mathbf{h_u}\in\mathbb{R}^{nh\times nu}\). Additionally, it is important to note that calcDiff() computes the derivatives using the latest stored values by calc(). Thus, we need to run first calc().

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

Definition at line 47 of file residual.hpp.

Member Typedef Documentation

◆ MathBase

template<typename _Scalar >
typedef MathBaseTpl<Scalar> MathBase

Definition at line 52 of file residual.hpp.

◆ Base

template<typename _Scalar >
typedef ConstraintModelAbstractTpl<Scalar> Base

Definition at line 53 of file residual.hpp.

◆ Data

template<typename _Scalar >
typedef ConstraintDataResidualTpl<Scalar> Data

Definition at line 54 of file residual.hpp.

◆ ConstraintDataAbstract

template<typename _Scalar >
typedef ConstraintDataAbstractTpl<Scalar> ConstraintDataAbstract

Definition at line 55 of file residual.hpp.

◆ ResidualModelAbstract

template<typename _Scalar >
typedef ResidualModelAbstractTpl<Scalar> ResidualModelAbstract

Definition at line 56 of file residual.hpp.

◆ VectorXs

template<typename _Scalar >
typedef MathBase::VectorXs VectorXs

Definition at line 57 of file residual.hpp.

Constructor & Destructor Documentation

◆ ConstraintModelResidualTpl() [1/2]

template<typename _Scalar >
ConstraintModelResidualTpl ( std::shared_ptr< typename Base::StateAbstract state,
std::shared_ptr< ResidualModelAbstract residual,
const VectorXs &  lower,
const VectorXs &  upper,
const bool  T_act = true 
)

Initialize the residual constraint model as an inequality constraint.

Parameters
[in]stateState of the multibody system
[in]residualResidual model
[in]lowerLower bound (dimension of the residual vector)
[in]upperUpper bound (dimension of the residual vector)
[in]T_actFalse if we want to deactivate the residual at the terminal node (default true)

◆ ConstraintModelResidualTpl() [2/2]

template<typename _Scalar >
ConstraintModelResidualTpl ( std::shared_ptr< typename Base::StateAbstract state,
std::shared_ptr< ResidualModelAbstract residual,
const bool  T_act = true 
)

Initialize the residual constraint model as an equality constraint.

Parameters
[in]stateState of the multibody system
[in]residualResidual model
[in]T_actFalse if we want to deactivate the residual at the terminal node (default true)

Member Function Documentation

◆ calc() [1/2]

template<typename _Scalar >
virtual void calc ( const std::shared_ptr< ConstraintDataAbstract > &  data,
const Eigen::Ref< const VectorXs > &  x,
const Eigen::Ref< const VectorXs > &  u 
)
virtual

Compute the residual constraint.

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

Implements ConstraintModelAbstractTpl< _Scalar >.

◆ calc() [2/2]

template<typename _Scalar >
virtual void calc ( const std::shared_ptr< ConstraintDataAbstract > &  data,
const Eigen::Ref< const VectorXs > &  x 
)
virtual

Compute the residual constraint based on state only.

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

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

Reimplemented from ConstraintModelAbstractTpl< _Scalar >.

◆ calcDiff() [1/2]

template<typename _Scalar >
virtual void calcDiff ( const std::shared_ptr< ConstraintDataAbstract > &  data,
const Eigen::Ref< const VectorXs > &  x,
const Eigen::Ref< const VectorXs > &  u 
)
virtual

Compute the derivatives of the residual constraint.

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

Implements ConstraintModelAbstractTpl< _Scalar >.

◆ calcDiff() [2/2]

template<typename _Scalar >
virtual void calcDiff ( const std::shared_ptr< ConstraintDataAbstract > &  data,
const Eigen::Ref< const VectorXs > &  x 
)
virtual

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

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

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

Reimplemented from ConstraintModelAbstractTpl< _Scalar >.

◆ createData()

template<typename _Scalar >
virtual std::shared_ptr< ConstraintDataAbstract > createData ( DataCollectorAbstract *const  data)
virtual

Create the residual constraint data.

Reimplemented from ConstraintModelAbstractTpl< _Scalar >.

◆ print()

template<typename _Scalar >
virtual void print ( std::ostream &  os) const
virtual

Print relevant information of the cost-residual model.

Parameters
[out]osOutput stream object

Reimplemented from ConstraintModelAbstractTpl< _Scalar >.

Member Data Documentation

◆ Scalar

template<typename _Scalar >
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar Scalar

Definition at line 51 of file residual.hpp.

◆ lb_

template<typename _Scalar >
VectorXs lb_
protected

Lower bound of the constraint.

Definition at line 252 of file constraint-base.hpp.

◆ ng_

template<typename _Scalar >
std::size_t ng_
protected

Number of inequality constraints.

Definition at line 255 of file constraint-base.hpp.

◆ nh_

template<typename _Scalar >
std::size_t nh_
protected

Number of equality constraints.

Definition at line 256 of file constraint-base.hpp.

◆ nu_

template<typename _Scalar >
std::size_t nu_
protected

Control dimension.

Definition at line 254 of file constraint-base.hpp.

◆ residual_

template<typename _Scalar >
std::shared_ptr<ResidualModelAbstract> residual_
protected

Residual model.

Definition at line 249 of file constraint-base.hpp.

◆ state_

template<typename _Scalar >
std::shared_ptr<StateAbstract> state_
protected

State description.

Definition at line 248 of file constraint-base.hpp.

◆ T_constraint_

template<typename _Scalar >
bool T_constraint_
protected

Label that indicates if the constraint is imposed in terminal nodes as well

Definition at line 257 of file constraint-base.hpp.

◆ type_

template<typename _Scalar >
ConstraintType type_
protected

Type of constraint: inequality=0, equality=1, both=2.

Definition at line 251 of file constraint-base.hpp.

◆ ub_

template<typename _Scalar >
VectorXs ub_
protected

Upper bound of the constraint.

Definition at line 253 of file constraint-base.hpp.

◆ unone_

template<typename _Scalar >
VectorXs unone_
protected

No control vector.

Definition at line 259 of file constraint-base.hpp.


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