Template Class ResidualModelAbstractTpl

Inheritance Relationships

Base Type

Derived Types

Class Documentation

template<typename _Scalar>
class ResidualModelAbstractTpl : public crocoddyl::ResidualModelBase

Abstract class for residual models.

A residual model defines a vector function \(\mathbf{r}(\mathbf{x}, \mathbf{u})\mathbb{R}^{nr}\) where nr describes its dimension in the Euclidean space. This 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 function can used across cost and constraint models.

The main computations are carring out in calc and calcDiff routines. calc computes the residual vector and calcDiff computes the Jacobians of the residual function. Additionally, it is important to note that calcDiff() computes the Jacobians using the latest stored values by calc(). Thus, we need to first run calc().

Subclassed by crocoddyl::DifferentialActionModelContactInvDynamicsTpl< _Scalar >::ResidualModelActuation, crocoddyl::DifferentialActionModelContactInvDynamicsTpl< _Scalar >::ResidualModelContact, crocoddyl::DifferentialActionModelFreeInvDynamicsTpl< _Scalar >::ResidualModelActuation, crocoddyl::ResidualModelCentroidalMomentumTpl< _Scalar >, crocoddyl::ResidualModelCoMPositionTpl< _Scalar >, crocoddyl::ResidualModelContactCoPPositionTpl< _Scalar >, crocoddyl::ResidualModelContactControlGravTpl< _Scalar >, crocoddyl::ResidualModelContactForceTpl< _Scalar >, crocoddyl::ResidualModelContactFrictionConeTpl< _Scalar >, crocoddyl::ResidualModelContactWrenchConeTpl< _Scalar >, crocoddyl::ResidualModelControlGravTpl< _Scalar >, crocoddyl::ResidualModelControlTpl< _Scalar >, crocoddyl::ResidualModelFramePlacementTpl< _Scalar >, crocoddyl::ResidualModelFrameRotationTpl< _Scalar >, crocoddyl::ResidualModelFrameTranslationTpl< _Scalar >, crocoddyl::ResidualModelFrameVelocityTpl< _Scalar >, crocoddyl::ResidualModelImpulseCoMTpl< _Scalar >, crocoddyl::ResidualModelJointAccelerationTpl< _Scalar >, crocoddyl::ResidualModelJointEffortTpl< _Scalar >, crocoddyl::ResidualModelNumDiffTpl< _Scalar >, crocoddyl::ResidualModelStateTpl< _Scalar >

Public Types

typedef MathBaseTpl<Scalar> MathBase
typedef ResidualDataAbstractTpl<Scalar> ResidualDataAbstract
typedef CostDataAbstractTpl<Scalar> CostDataAbstract
typedef ActivationDataAbstractTpl<Scalar> ActivationDataAbstract
typedef StateAbstractTpl<Scalar> StateAbstract
typedef DataCollectorAbstractTpl<Scalar> DataCollectorAbstract
typedef MathBase::VectorXs VectorXs
typedef MathBase::MatrixXs MatrixXs
typedef MathBase::DiagonalMatrixXs DiagonalMatrixXs

Public Functions

ResidualModelAbstractTpl(std::shared_ptr<StateAbstract> state, const std::size_t nr, const std::size_t nu, const bool q_dependent = true, const bool v_dependent = true, const bool u_dependent = true)

Initialize the residual model.

Parameters:
  • state[in] State of the system

  • nr[in] Dimension of residual vector

  • nu[in] Dimension of control vector

  • q_dependent[in] Define if the residual function depends on q (default true)

  • v_dependent[in] Define if the residual function depends on v (default true)

  • u_dependent[in] Define if the residual function depends on u (default true)

ResidualModelAbstractTpl(std::shared_ptr<StateAbstract> state, const std::size_t nr, const bool q_dependent = true, const bool v_dependent = true, const bool u_dependent = true)

The default nu value is obtained from StateAbstractTpl::get_nv().

Parameters:
  • state[in] State of the system

  • nr[in] Dimension of residual vector

  • q_dependent[in] Define if the residual function depends on q (default true)

  • v_dependent[in] Define if the residual function depends on v (default true)

  • u_dependent[in] Define if the residual function depends on u (default true)

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

Compute the residual vector.

Parameters:
  • data[in] Residual 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<ResidualDataAbstract> &data, const Eigen::Ref<const VectorXs> &x)

Compute the residual vector for nodes that depends only on the state.

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

Parameters:
  • data[in] Residual data

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

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

Compute the Jacobian of the residual vector.

It computes the Jacobian the residual function. It assumes that calc() has been run first.

Parameters:
  • data[in] Residual 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<ResidualDataAbstract> &data, const Eigen::Ref<const VectorXs> &x)

Compute the Jacobian of the residual functions with respect to the state only.

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

Parameters:
  • data[in] Residual data

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

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

Create the residual data.

The default data contains objects to store the values of the residual vector and their Jacobians. However, it is possible to specialize this function if we need to create additional data, for instance, to avoid dynamic memory allocation.

Parameters:

data – Data collector

Returns:

the residual data

virtual void calcCostDiff(const std::shared_ptr<CostDataAbstract> &cdata, const std::shared_ptr<ResidualDataAbstract> &rdata, const std::shared_ptr<ActivationDataAbstract> &adata, const bool update_u = true)

Compute the derivative of the cost function.

This function assumes that the derivatives of the activation and residual are computed via calcDiff functions.

Parameters:
  • cdata – Cost data

  • rdata – Residual data

  • adata – Activation data

  • update_u – Update the derivative of the cost function w.r.t. to the control if True.

const std::shared_ptr<StateAbstract> &get_state() const

Return the state.

std::size_t get_nr() const

Return the dimension of the residual vector.

std::size_t get_nu() const

Return the dimension of the control input.

bool get_q_dependent() const

Return true if the residual function depends on q.

bool get_v_dependent() const

Return true if the residual function depends on v.

bool get_u_dependent() const

Return true if the residual function depends on u.

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

Print relevant information of the residual model.

Parameters:

os[out] Output stream object

Public Members

EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar Scalar

Protected Functions

inline ResidualModelAbstractTpl()

Protected Attributes

std::shared_ptr<StateAbstract> state_

State description.

std::size_t nr_

Residual vector dimension.

std::size_t nu_

Control dimension.

VectorXs unone_

No control vector.

bool q_dependent_

Label that indicates if the residual function depends on q

bool v_dependent_

Label that indicates if the residual function depends on v

bool u_dependent_

Label that indicates if the residual function depends on u

Friends

template<class Scalar>
friend std::ostream &operator<<(std::ostream &os, const ResidualModelAbstractTpl<Scalar> &model)

Print information on the residual model.