Template Class ConstraintModelResidualTpl

Inheritance Relationships

Base Type

Class Documentation

template<typename _Scalar>
class ConstraintModelResidualTpl : public crocoddyl::ConstraintModelAbstractTpl<_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().

Public Types

typedef MathBaseTpl<Scalar> MathBase
typedef ConstraintModelAbstractTpl<Scalar> Base
typedef ConstraintDataResidualTpl<Scalar> Data
typedef ConstraintDataAbstractTpl<Scalar> ConstraintDataAbstract
typedef ResidualModelAbstractTpl<Scalar> ResidualModelAbstract
typedef DataCollectorAbstractTpl<Scalar> DataCollectorAbstract
typedef MathBase::VectorXs VectorXs

Public Functions

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:
  • state[in] State of the multibody system

  • residual[in] Residual model

  • lower[in] Lower bound (dimension of the residual vector)

  • upper[in] Upper bound (dimension of the residual vector)

  • T_act[in] False if we want to deactivate the residual at the terminal node (default true)

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:
  • state[in] State of the multibody system

  • residual[in] Residual model

  • T_act[in] False if we want to deactivate the residual at the terminal node (default true)

virtual ~ConstraintModelResidualTpl() = default
virtual void calc(const std::shared_ptr<ConstraintDataAbstract> &data, const Eigen::Ref<const VectorXs> &x, const Eigen::Ref<const VectorXs> &u) override

Compute the residual constraint.

Parameters:
  • data[in] Residual constraint data

  • x[in] State point \(\mathbf{x}\in\mathbb{R}^{ndx}\)

  • u[in] Control input \(\mathbf{u}\in\mathbb{R}^{nu}\)

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

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:
  • data[in] Residual constraint data

  • x[in] State point \(\mathbf{x}\in\mathbb{R}^{ndx}\)

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

Compute the derivatives of the residual constraint.

Parameters:
  • data[in] Residual constraint data

  • x[in] State point \(\mathbf{x}\in\mathbb{R}^{ndx}\)

  • u[in] Control input \(\mathbf{u}\in\mathbb{R}^{nu}\)

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

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:
  • data[in] Residual constraint data

  • x[in] State point \(\mathbf{x}\in\mathbb{R}^{ndx}\)

virtual std::shared_ptr<ConstraintDataAbstract> createData(DataCollectorAbstract *const data) override

Create the residual constraint data.

template<typename NewScalar>
ConstraintModelResidualTpl<NewScalar> cast() const

Cast the residual constraint model to a different scalar type.

It is useful for operations requiring different precision or scalar types.

Template Parameters:

NewScalar – The new scalar type to cast to.

Returns:

ConstraintModelResidualTpl<NewScalar> A constraint model with the new scalar type.

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

Print relevant information of the cost-residual model.

Parameters:

os[out] Output stream object

Public Members

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<ResidualModelAbstract> residual_

Residual model.

std::shared_ptr<StateAbstract> state_

State description.

bool T_constraint_

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

ConstraintType type_

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

VectorXs ub_

Upper bound of the constraint.

VectorXs unone_

No control vector.