Template Class DifferentialActionModelContactFwdDynamicsTpl

Inheritance Relationships

Base Type

Class Documentation

template<typename _Scalar>
class DifferentialActionModelContactFwdDynamicsTpl : public crocoddyl::DifferentialActionModelAbstractTpl<_Scalar>

Differential action model for contact forward dynamics in multibody systems.

This class implements contact forward dynamics given a stack of rigid-contacts described in ContactModelMultipleTpl, i.e.,

\[\begin{split} \left[\begin{matrix}\dot{\mathbf{v}} \\ -\boldsymbol{\lambda}\end{matrix}\right] = \left[\begin{matrix}\mathbf{M} & \mathbf{J}^{\top}_c \\ {\mathbf{J}_{c}} & \mathbf{0} \end{matrix}\right]^{-1} \left[\begin{matrix}\boldsymbol{\tau}_b \\ -\mathbf{a}_0 \\\end{matrix}\right], \end{split}\]
where \(\mathbf{q}\in Q\), \(\mathbf{v}\in\mathbb{R}^{nv}\) are the configuration point and generalized velocity (its tangent vector), respectively; \(\boldsymbol{\tau}_b=\boldsymbol{\tau} - \mathbf{h}(\mathbf{q},\mathbf{v})\) is the bias forces that depends on the torque inputs \(\boldsymbol{\tau}\) and the Coriolis effect and gravity field \(\mathbf{h}(\mathbf{q},\mathbf{v})\); \(\mathbf{J}_c\in\mathbb{R}^{nc\times nv}\) is the contact Jacobian expressed in the local frame; and \(\mathbf{a}_0\in\mathbb{R}^{nc}\) is the desired acceleration in the constraint space. To improve stability in the numerical integration, we define PD gains that are similar in spirit to Baumgarte stabilization:
\[ \mathbf{a}_0 = \mathbf{a}_{\lambda(c)} - \alpha \,^oM^{ref}_{\lambda(c)}\ominus\,^oM_{\lambda(c)} - \beta\mathbf{v}_{\lambda(c)}, \]
where \(\mathbf{v}_{\lambda(c)}\), \(\mathbf{a}_{\lambda(c)}\) are the spatial velocity and acceleration at the parent body of the contact \(\lambda(c)\), respectively; \(\alpha\) and \(\beta\) are the stabilization gains; \(\,^oM^{ref}_{\lambda(c)}\ominus\,^oM_{\lambda(c)}\) is the \(\mathbb{SE}(3)\) inverse composition between the reference contact placement and the current one.

The derivatives of the system acceleration and contact forces are computed efficiently based on the analytical derivatives of Recursive Newton Euler Algorithm (RNEA) as described in mastalli-icra20. Note that the algorithm for computing the RNEA derivatives is described in carpentier-rss18.

The stack of cost and constraint functions are implemented in CostModelSumTpl and ConstraintModelAbstractTpl, respectively. The computation of the contact dynamics and its derivatives are carrying out inside calc() and calcDiff() functions, respectively. It is also important to remark that calcDiff() computes the derivatives using the latest stored values by calc(). Thus, we need to run calc() first.

Public Types

typedef DifferentialActionModelAbstractTpl<Scalar> Base
typedef DifferentialActionDataContactFwdDynamicsTpl<Scalar> Data
typedef MathBaseTpl<Scalar> MathBase
typedef StateMultibodyTpl<Scalar> StateMultibody
typedef CostModelSumTpl<Scalar> CostModelSum
typedef ConstraintModelManagerTpl<Scalar> ConstraintModelManager
typedef ContactModelMultipleTpl<Scalar> ContactModelMultiple
typedef ActuationModelAbstractTpl<Scalar> ActuationModelAbstract
typedef DifferentialActionDataAbstractTpl<Scalar> DifferentialActionDataAbstract
typedef MathBase::VectorXs VectorXs
typedef MathBase::MatrixXs MatrixXs

Public Functions

EIGEN_MAKE_ALIGNED_OPERATOR_NEW CROCODDYL_DERIVED_CAST (DifferentialActionModelBase, DifferentialActionModelContactFwdDynamicsTpl) typedef _Scalar Scalar
DifferentialActionModelContactFwdDynamicsTpl(std::shared_ptr<StateMultibody> state, std::shared_ptr<ActuationModelAbstract> actuation, std::shared_ptr<ContactModelMultiple> contacts, std::shared_ptr<CostModelSum> costs, const Scalar JMinvJt_damping = Scalar(0.), const bool enable_force = false)

Initialize the contact forward-dynamics action model.

It describes the dynamics evolution of a multibody system under rigid-contact constraints defined by ContactModelMultipleTpl. It computes the cost described in CostModelSumTpl.

Parameters:
  • state[in] State of the multibody system

  • actuation[in] Actuation model

  • contacts[in] Stack of rigid contact

  • costs[in] Stack of cost functions

  • JMinvJt_damping[in] Damping term used in operational space inertia matrix (default 0.)

  • enable_force[in] Enable the computation of the contact force derivatives (default false)

DifferentialActionModelContactFwdDynamicsTpl(std::shared_ptr<StateMultibody> state, std::shared_ptr<ActuationModelAbstract> actuation, std::shared_ptr<ContactModelMultiple> contacts, std::shared_ptr<CostModelSum> costs, std::shared_ptr<ConstraintModelManager> constraints, const Scalar JMinvJt_damping = Scalar(0.), const bool enable_force = false)

Initialize the contact forward-dynamics action model.

It describes the dynamics evolution of a multibody system under rigid-contact constraints defined by ContactModelMultipleTpl. It computes the cost described in CostModelSumTpl.

Parameters:
  • state[in] State of the multibody system

  • actuation[in] Actuation model

  • contacts[in] Stack of rigid contact

  • costs[in] Stack of cost functions

  • constraints[in] Stack of constraints

  • JMinvJt_damping[in] Damping term used in operational space inertia matrix (default 0.)

  • enable_force[in] Enable the computation of the contact force derivatives (default false)

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

Compute the system acceleration, and cost value.

It computes the system acceleration using the contact dynamics.

Parameters:
  • data[in] Contact forward-dynamics 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<DifferentialActionDataAbstract> &data, const Eigen::Ref<const VectorXs> &x) override

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

It updates the total cost and the system acceleration is not updated as it is expected to be zero. Additionally, it does not update the contact forces. This function is used in the terminal nodes of an optimal control problem.

Parameters:
  • data[in] Contact forward-dynamics data

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

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

Compute the derivatives of the contact dynamics, and cost function.

Parameters:
  • data[in] Contact forward-dynamics 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<DifferentialActionDataAbstract> &data, const Eigen::Ref<const VectorXs> &x) override

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. Additionally, it does not update the contact forces derivatives. This function is used in the terminal nodes of an optimal control problem.

Parameters:
  • data[in] Contact forward-dynamics data

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

virtual std::shared_ptr<DifferentialActionDataAbstract> createData() override

Create the contact forward-dynamics data.

Returns:

contact forward-dynamics data

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

Cast the contact-fwddyn 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:

DifferentialActionModelContactFwdDynamicsTpl<NewScalar> A differential-action model with the new scalar type.

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

Check that the given data belongs to the contact forward-dynamics data.

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

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}(\mathbf{q},\mathbf{v}=\mathbf{0},\mathbf{u})=\mathbf{0}\)

Parameters:
  • data[in] Differential 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

virtual std::size_t get_ng() const override

Return the number of inequality constraints.

virtual std::size_t get_nh() const override

Return the number of equality constraints.

virtual std::size_t get_ng_T() const override

Return the number of equality terminal constraints.

virtual std::size_t get_nh_T() const override

Return the number of equality terminal constraints.

virtual const VectorXs &get_g_lb() const override

Return the lower bound of the inequality constraints.

virtual const VectorXs &get_g_ub() const override

Return the upper bound of the inequality constraints.

const std::shared_ptr<ActuationModelAbstract> &get_actuation() const

Return the actuation model.

const std::shared_ptr<ContactModelMultiple> &get_contacts() const

Return the contact model.

const std::shared_ptr<CostModelSum> &get_costs() const

Return the cost model.

const std::shared_ptr<ConstraintModelManager> &get_constraints() const

Return the constraint model manager.

pinocchio::ModelTpl<Scalar> &get_pinocchio() const

Return the Pinocchio model.

const VectorXs &get_armature() const

Return the armature vector.

const Scalar get_damping_factor() const

Return the damping factor used in operational space inertia matrix.

void set_armature(const VectorXs &armature)

Modify the armature vector.

void set_damping_factor(const Scalar damping)

Modify the damping factor used in operational space inertia matrix.

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

Print relevant information of the contact forward-dynamics model.

Parameters:

os[out] Output stream object

Protected Attributes

VectorXs g_lb_

Lower bound of the inequality constraints.

VectorXs g_ub_

< Lower bound of the inequality constraints

std::size_t nu_

< Upper bound of the inequality constraints

std::shared_ptr<StateAbstract> state_

< Control dimension