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"
20 enum ConstraintType { Inequality = 0, Equality, Both };
53 template <
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);
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_;
268 template <
typename _Scalar>
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>
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");
317 #include "crocoddyl/core/constraint-base.hxx"
Abstract class for constraint models.
void remove_bounds()
Remove the bounds of the constraint.
virtual std::shared_ptr< ConstraintDataAbstract > createData(DataCollectorAbstract *const data)
Create the constraint data.
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_
State description.
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.
friend std::ostream & operator<<(std::ostream &os, const CostModelAbstractTpl< Scalar > &model)
Print information on the constraint model.
const VectorXs & get_lb() const
Return the lower bound of the constraint.
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_ub() const
Return the upper bound of the constraint.
std::size_t get_nh() const
Return the number of equality constraints.
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.
const std::shared_ptr< StateAbstract > & get_state() const
Return the state.
std::size_t nu_
Control dimension.
VectorXs unone_
No control vector.
const std::shared_ptr< ResidualModelAbstract > & get_residual() const
Return the residual model.
ConstraintModelAbstractTpl(std::shared_ptr< StateAbstract > state, const std::size_t ng, const std::size_t nh, const bool T_const=true)
std::size_t nh_
Number of equality constraints.
VectorXs lb_
Lower bound of the constraint.
ConstraintType type_
Type of constraint: inequality=0, equality=1, both=2.
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_
Residual model.
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.
VectorXs ub_
Upper bound of the constraint.
std::size_t ng_
Number of inequality constraints.
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.