9 #ifndef CROCODDYL_CORE_CONSTRAINT_BASE_HPP_
10 #define CROCODDYL_CORE_CONSTRAINT_BASE_HPP_
12 #include <boost/make_shared.hpp>
15 #include "crocoddyl/core/fwd.hpp"
17 #include "crocoddyl/core/data-collector-base.hpp"
18 #include "crocoddyl/core/residual-base.hpp"
19 #include "crocoddyl/core/state-base.hpp"
23 enum ConstraintType { Inequality = 0, Equality, Both };
49 template <
typename _Scalar>
52 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
54 typedef _Scalar Scalar;
60 typedef typename MathBase::VectorXs VectorXs;
71 std::shared_ptr<ResidualModelAbstract> residual,
72 const std::size_t ng,
const std::size_t nh);
86 const std::size_t nu,
const std::size_t ng,
87 const std::size_t nh,
const bool T_const =
true);
102 const std::size_t ng,
const std::size_t nh,
103 const bool T_const =
true);
113 virtual void calc(
const std::shared_ptr<ConstraintDataAbstract>& data,
114 const Eigen::Ref<const VectorXs>& x,
115 const Eigen::Ref<const VectorXs>& u) = 0;
127 virtual void calc(
const std::shared_ptr<ConstraintDataAbstract>& data,
128 const Eigen::Ref<const VectorXs>& x);
140 virtual void calcDiff(
const std::shared_ptr<ConstraintDataAbstract>& data,
141 const Eigen::Ref<const VectorXs>& x,
142 const Eigen::Ref<const VectorXs>& u) = 0;
155 virtual void calcDiff(
const std::shared_ptr<ConstraintDataAbstract>& data,
156 const Eigen::Ref<const VectorXs>& x);
185 const std::shared_ptr<StateAbstract>&
get_state()
const;
230 template <
class Scalar>
239 virtual void print(std::ostream& os)
const;
242 std::size_t ng_internal_;
244 std::size_t nh_internal_;
262 template <
typename _Scalar>
264 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
266 typedef _Scalar Scalar;
270 typedef typename MathBase::VectorXs VectorXs;
271 typedef typename MathBase::MatrixXs MatrixXs;
273 template <
template <
typename Scalar>
class Model>
277 residual(model->get_residual()->createData(data)),
279 Gx(model->get_ng(), model->get_state()->get_ndx()),
280 Gu(model->get_ng(), model->get_nu()),
282 Hx(model->get_nh(), model->get_state()->get_ndx()),
283 Hu(model->get_nh(), model->get_nu()) {
284 if (model->get_ng() == 0 && model->get_nh() == 0) {
285 throw_pretty(
"Invalid argument: " <<
"ng and nh cannot be equals to 0");
311 #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)
Initialize the constraint model.
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.