Template Class ActionModelAbstractTpl

Inheritance Relationships

Base Type

Derived Types

Class Documentation

template<typename _Scalar>
class ActionModelAbstractTpl : public crocoddyl::ActionModelBase

Abstract class for action model.

An action model combines dynamics, cost functions and constraints. Each node, in our optimal control problem, is described through an action model. Every time that we want describe a problem, we need to provide ways of computing the dynamics, cost functions, constraints and their derivatives. All these is described inside the action model.

Concretely speaking, the action model describes a time-discrete action model with a first-order ODE along a cost function, i.e.

  • the state \(\mathbf{z}\in\mathcal{Z}\) lies in a manifold described with a nx-tuple,

  • the state rate \(\mathbf{\dot{x}}\in T_{\mathbf{q}}\mathcal{Q}\) is the tangent vector to the state manifold with ndx dimension,

  • the control input \(\mathbf{u}\in\mathbb{R}^{nu}\) is an Euclidean vector

  • \(\mathbf{r}(\cdot)\) and \(a(\cdot)\) are the residual and activation functions (see ResidualModelAbstractTpl and ActivationModelAbstractTpl, respetively),

  • \(\mathbf{g}(\cdot)\in\mathbb{R}^{ng}\) and \(\mathbf{h}(\cdot)\in\mathbb{R}^{nh}\) are the inequality and equality vector functions, respectively.

The computation of these equations are carried out out inside calc() function. In short, this function computes the system acceleration, cost and constraints values (also called constraints violations). This procedure is equivalent to running a forward pass of the action model.

However, during numerical optimization, we also need to run backward passes of the action model. These calculations are performed by calcDiff(). In short, this method builds a linear-quadratic approximation of the action model, i.e.:

\[\begin{split} \begin{aligned} &\delta\mathbf{x}_{k+1} = \mathbf{f_x}\delta\mathbf{x}_k+\mathbf{f_u}\delta\mathbf{u}_k, &\textrm{(dynamics)}\\ &\ell(\delta\mathbf{x}_k,\delta\mathbf{u}_k) = \begin{bmatrix}1 \\ \delta\mathbf{x}_k \\ \delta\mathbf{u}_k\end{bmatrix}^T \begin{bmatrix}0 & \mathbf{\ell_x}^T & \mathbf{\ell_u}^T \\ \mathbf{\ell_x} & \mathbf{\ell_{xx}} & \mathbf{\ell_{ux}}^T \\ \mathbf{\ell_u} & \mathbf{\ell_{ux}} & \mathbf{\ell_{uu}}\end{bmatrix} \begin{bmatrix}1 \\ \delta\mathbf{x}_k \\ \delta\mathbf{u}_k\end{bmatrix}, &\textrm{(cost)}\\ &\mathbf{g}(\delta\mathbf{x}_k,\delta\mathbf{u}_k)<\mathbf{0}, &\textrm{(inequality constraint)}\\ &\mathbf{h}(\delta\mathbf{x}_k,\delta\mathbf{u}_k)=\mathbf{0}, &\textrm{(equality constraint)} \end{aligned} \end{split}\]
where
  • \(\mathbf{f_x}\in\mathbb{R}^{ndx\times ndx}\) and \(\mathbf{f_u}\in\mathbb{R}^{ndx\times nu}\) are the Jacobians of the dynamics,

  • \(\mathbf{\ell_x}\in\mathbb{R}^{ndx}\) and \(\mathbf{\ell_u}\in\mathbb{R}^{nu}\) are the Jacobians of the cost function,

  • \(\mathbf{\ell_{xx}}\in\mathbb{R}^{ndx\times ndx}\), \(\mathbf{\ell_{xu}}\in\mathbb{R}^{ndx\times nu}\) and \(\mathbf{\ell_{uu}}\in\mathbb{R}^{nu\times nu}\) are the Hessians of the cost function,

  • \(\mathbf{g_x}\in\mathbb{R}^{ng\times ndx}\) and \(\mathbf{g_u}\in\mathbb{R}^{ng\times nu}\) are the Jacobians of the inequality constraints, and

  • \(\mathbf{h_x}\in\mathbb{R}^{nh\times ndx}\) and \(\mathbf{h_u}\in\mathbb{R}^{nh\times nu}\) are the Jacobians of the equality constraints.

Additionally, it is important to note that calcDiff() computes the derivatives using the latest stored values by calc(). Thus, we need to first run calc().

Subclassed by crocoddyl::ActionModelImpulseFwdDynamicsTpl< _Scalar >, crocoddyl::ActionModelLQRTpl< _Scalar >, crocoddyl::ActionModelNumDiffTpl< _Scalar >, crocoddyl::ActionModelUnicycleTpl< _Scalar >, crocoddyl::IntegratedActionModelAbstractTpl< _Scalar >

Public Types

typedef ScalarSelector<Scalar>::type ScalarType
typedef MathBaseTpl<Scalar> MathBase
typedef ActionDataAbstractTpl<Scalar> ActionDataAbstract
typedef StateAbstractTpl<Scalar> StateAbstract
typedef MathBase::VectorXs VectorXs

Public Functions

ActionModelAbstractTpl(std::shared_ptr<StateAbstract> state, const std::size_t nu, const std::size_t nr = 0, const std::size_t ng = 0, const std::size_t nh = 0, const std::size_t ng_T = 0, const std::size_t nh_T = 0)

Initialize the action model.

Parameters:
  • state[in] State description

  • nu[in] Dimension of control vector

  • nr[in] Dimension of cost-residual vector

  • ng[in] Number of inequality constraints (default 0)

  • nh[in] Number of equality constraints (default 0)

  • ng_T[in] Number of inequality terminal constraints (default 0)

  • nh_T[in] Number of equality terminal constraints (default 0)

ActionModelAbstractTpl(const ActionModelAbstractTpl<Scalar> &other)

Copy constructor.

Parameters:

other – Action model to be copied

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

Compute the next state and cost value.

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

Compute the total cost value for nodes that depends only on the state.

It updates the total cost and the next state is not computed as it is not expected to change. This function is used in the terminal nodes of an optimal control problem.

Parameters:
  • data[in] Action data

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

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

Compute the derivatives of the dynamics and cost functions.

It computes the partial derivatives of the dynamical system and the cost function. It assumes that calc() has been run first. This function builds a linear-quadratic approximation of the action model (i.e. dynamical system and cost function).

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

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

It updates the derivatives of the cost function with respect to the state only. This function is used in the terminal nodes of an optimal control problem.

Parameters:
  • data[in] Action data

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

virtual std::shared_ptr<ActionDataAbstract> createData()

Create the action data.

Returns:

the action data

virtual bool checkData(const std::shared_ptr<ActionDataAbstract> &data)

Checks that a specific data belongs to this model.

virtual void quasiStatic(const std::shared_ptr<ActionDataAbstract> &data, Eigen::Ref<VectorXs> u, const Eigen::Ref<const VectorXs> &x, const std::size_t maxiter = 100, const Scalar tol = Scalar(1e-9))

Computes the quasic static commands.

The quasic static commands are the ones produced for a the reference posture as an equilibrium point, i.e. for \(\mathbf{f^q_x}\delta\mathbf{q}+\mathbf{f_u}\delta\mathbf{u}=\mathbf{0}\)

Parameters:
  • data[in] Action data

  • u[out] Quasic static commands

  • x[in] State point (velocity has to be zero)

  • maxiter[in] Maximum allowed number of iterations

  • tol[in] Tolerance

VectorXs quasiStatic_x(const std::shared_ptr<ActionDataAbstract> &data, const VectorXs &x, const std::size_t maxiter = 100, const Scalar tol = Scalar(1e-9))
Parameters:
  • data[in] Action data

  • x[in] State point (velocity has to be zero)

  • maxiter[in] Maximum allowed number of iterations

  • tol[in] Tolerance

Returns:

Quasic static commands

std::size_t get_nu() const

Return the dimension of the control input.

std::size_t get_nr() const

Return the dimension of the cost-residual vector.

virtual std::size_t get_ng() const

Return the number of inequality constraints.

virtual std::size_t get_nh() const

Return the number of equality constraints.

virtual std::size_t get_ng_T() const

Return the number of inequality terminal constraints.

virtual std::size_t get_nh_T() const

Return the number of equality terminal constraints.

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

Return the state.

virtual const VectorXs &get_g_lb() const

Return the lower bound of the inequality constraints.

virtual const VectorXs &get_g_ub() const

Return the upper bound of the inequality constraints.

const VectorXs &get_u_lb() const

Return the control lower bound.

const VectorXs &get_u_ub() const

Return the control upper bound.

bool get_has_control_limits() const

Indicates if there are defined control limits.

void set_g_lb(const VectorXs &g_lb)

Modify the lower bound of the inequality constraints.

void set_g_ub(const VectorXs &g_ub)

Modify the upper bound of the inequality constraints.

void set_u_lb(const VectorXs &u_lb)

Modify the control lower bounds.

void set_u_ub(const VectorXs &u_ub)

Modify the control upper bounds.

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

Print relevant information of the action model.

Parameters:

os[out] Output stream object

Public Members

EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar Scalar

Protected Functions

inline ActionModelAbstractTpl()
void update_has_control_limits()

Update the status of the control limits (i.e. if there are defined limits)

Protected Attributes

std::size_t nu_

Control dimension.

std::size_t nr_

Dimension of the cost residual.

std::size_t ng_

Number of inequality constraints.

std::size_t nh_

Number of equality constraints.

std::size_t ng_T_

Number of inequality terminal constraints.

std::size_t nh_T_

Number of equality terminal constraints.

std::shared_ptr<StateAbstract> state_

Model of the state.

VectorXs unone_

Neutral state.

VectorXs g_lb_

Lower bound of the inequality constraints.

VectorXs g_ub_

Lower bound of the inequality constraints.

VectorXs u_lb_

Lower control limits.

VectorXs u_ub_

Upper control limits.

bool has_control_limits_

Indicates whether any of the control limits is finite

Friends

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

Print information on the action model.