9#ifndef CROCODDYL_CORE_CONSTRAINT_BASE_HPP_ 10#define CROCODDYL_CORE_CONSTRAINT_BASE_HPP_ 12#include "crocoddyl/core/fwd.hpp" 14#include "crocoddyl/core/data-collector-base.hpp" 15#include "crocoddyl/core/residual-base.hpp" 16#include "crocoddyl/core/state-base.hpp" 20enum ConstraintType { Inequality = 0, Equality, Both };
53template <
typename _Scalar>
56 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
58 typedef _Scalar Scalar;
64 typedef typename MathBase::VectorXs VectorXs;
75 std::shared_ptr<ResidualModelAbstract> residual,
76 const std::size_t ng,
const std::size_t nh);
90 const std::size_t nu,
const std::size_t ng,
91 const std::size_t nh,
const bool T_const =
true);
106 const std::size_t ng,
const std::size_t nh,
107 const bool T_const =
true);
117 virtual void calc(
const std::shared_ptr<ConstraintDataAbstract>& data,
118 const Eigen::Ref<const VectorXs>& x,
119 const Eigen::Ref<const VectorXs>& u) = 0;
131 virtual void calc(
const std::shared_ptr<ConstraintDataAbstract>& data,
132 const Eigen::Ref<const VectorXs>& x);
144 virtual void calcDiff(
const std::shared_ptr<ConstraintDataAbstract>& data,
145 const Eigen::Ref<const VectorXs>& x,
146 const Eigen::Ref<const VectorXs>& u) = 0;
159 virtual void calcDiff(
const std::shared_ptr<ConstraintDataAbstract>& data,
160 const Eigen::Ref<const VectorXs>& x);
174 DataCollectorAbstract*
const data);
189 const std::shared_ptr<StateAbstract>&
get_state()
const;
234 template <
class Scalar>
243 virtual void print(std::ostream& os)
const;
246 std::size_t ng_internal_;
248 std::size_t nh_internal_;
268template <
typename _Scalar>
269struct ConstraintDataAbstractTpl {
270 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
272 typedef _Scalar Scalar;
276 typedef typename MathBase::VectorXs VectorXs;
277 typedef typename MathBase::MatrixXs MatrixXs;
279 template <
template <
typename Scalar>
class Model>
280 ConstraintDataAbstractTpl(Model<Scalar>*
const model,
281 DataCollectorAbstract*
const data)
283 residual(model->get_residual()->createData(data)),
285 Gx(model->get_ng(), model->get_state()->get_ndx()),
286 Gu(model->get_ng(), model->get_nu()),
288 Hx(model->get_nh(), model->get_state()->get_ndx()),
289 Hu(model->get_nh(), model->get_nu()) {
290 if (model->get_ng() == 0 && model->get_nh() == 0) {
291 throw_pretty(
"Invalid argument: " <<
"ng and nh cannot be equals to 0");
300 virtual ~ConstraintDataAbstractTpl() =
default;
317#include "crocoddyl/core/constraint-base.hxx" Abstract class for constraint models.
void remove_bounds()
Remove the bounds of the constraint.
const VectorXs & get_ub() const
Return the upper bound of the constraint.
virtual void calcDiff(const std::shared_ptr< ConstraintDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)=0
Compute the Jacobian of the constraint.
std::shared_ptr< StateAbstract > state_
std::size_t get_ng() const
Return the number of inequality constraints.
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
virtual void calc(const std::shared_ptr< ConstraintDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the constraint value for nodes that depends only on the state.
virtual void print(std::ostream &os) const
Print relevant information of the constraint model.
virtual void calcDiff(const std::shared_ptr< ConstraintDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the Jacobian of the constraint with respect to the state only.
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_nh() const
Return the number of equality constraints.
friend std::ostream & operator<<(std::ostream &os, const CostModelAbstractTpl< Scalar > &model)
Print information on the constraint model.
const std::shared_ptr< ResidualModelAbstract > & get_residual() const
Return the residual model.
ConstraintType get_type() const
Return the type of constraint.
bool get_T_constraint() const
Return true if the constraint is imposed in terminal nodes as well.
ConstraintModelAbstractTpl(std::shared_ptr< StateAbstract > state, const std::size_t ng, const std::size_t nh, const bool T_const=true)
Initialize the constraint model.
const std::shared_ptr< StateAbstract > & get_state() const
Return the state.
void update_bounds(const VectorXs &lower, const VectorXs &upper)
Update the lower and upper bounds the upper bound of constraint.
std::shared_ptr< ResidualModelAbstract > residual_
virtual std::shared_ptr< ConstraintDataAbstract > createData(DataCollectorAbstract *const data)
Create the constraint data.
virtual void calc(const std::shared_ptr< ConstraintDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)=0
Compute the constraint value.
std::size_t get_nu() const
Return the dimension of the control input.
Abstract class for cost models.
Abstract class for residual models.
Abstract class for the state representation.
MatrixXs Gx
Jacobian of the inequality constraint.
VectorXs h
Equality constraint values.
VectorXs g
Inequality constraint values.
MatrixXs Hx
Jacobian of the equality constraint.
std::shared_ptr< ResidualDataAbstract > residual
Residual data.
MatrixXs Hu
Jacobian of the equality constraint.
DataCollectorAbstract * shared
Shared data.
MatrixXs Gu
Jacobian of the inequality constraint.