9 #ifndef CROCODDYL_CORE_CONSTRAINT_BASE_HPP_
10 #define CROCODDYL_CORE_CONSTRAINT_BASE_HPP_
12 #include <boost/make_shared.hpp>
13 #include <boost/shared_ptr.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 boost::shared_ptr<ResidualModelAbstract> residual,
72 const std::size_t ng,
const std::size_t nh);
83 const std::size_t nu,
const std::size_t ng,
84 const std::size_t nh);
96 const std::size_t ng,
const std::size_t nh);
106 virtual void calc(
const boost::shared_ptr<ConstraintDataAbstract>& data,
107 const Eigen::Ref<const VectorXs>& x,
108 const Eigen::Ref<const VectorXs>& u) = 0;
120 virtual void calc(
const boost::shared_ptr<ConstraintDataAbstract>& data,
121 const Eigen::Ref<const VectorXs>& x);
133 virtual void calcDiff(
const boost::shared_ptr<ConstraintDataAbstract>& data,
134 const Eigen::Ref<const VectorXs>& x,
135 const Eigen::Ref<const VectorXs>& u) = 0;
148 virtual void calcDiff(
const boost::shared_ptr<ConstraintDataAbstract>& data,
149 const Eigen::Ref<const VectorXs>& x);
162 virtual boost::shared_ptr<ConstraintDataAbstract>
createData(
178 const boost::shared_ptr<StateAbstract>&
get_state()
const;
218 template <
class Scalar>
227 virtual void print(std::ostream& os)
const;
230 std::size_t ng_internal_;
232 std::size_t nh_internal_;
248 template <
typename _Scalar>
250 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
252 typedef _Scalar Scalar;
256 typedef typename MathBase::VectorXs VectorXs;
257 typedef typename MathBase::MatrixXs MatrixXs;
259 template <
template <
typename Scalar>
class Model>
263 residual(model->get_residual()->createData(data)),
265 Gx(model->get_ng(), model->get_state()->get_ndx()),
266 Gu(model->get_ng(), model->get_nu()),
268 Hx(model->get_nh(), model->get_state()->get_ndx()),
269 Hu(model->get_nh(), model->get_nu()) {
270 if (model->get_ng() == 0 && model->get_nh() == 0) {
271 throw_pretty(
"Invalid argument: "
272 <<
"ng and nh cannot be equals to 0");
298 #include "crocoddyl/core/constraint-base.hxx"
Abstract class for constraint models.
void remove_bounds()
Remove the bounds of the constraint.
virtual boost::shared_ptr< ConstraintDataAbstract > createData(DataCollectorAbstract *const data)
Create the constraint data.
ConstraintModelAbstractTpl(boost::shared_ptr< StateAbstract > state, const std::size_t nu, const std::size_t ng, const std::size_t nh)
the constraint model
std::size_t get_ng() const
Return the number of inequality constraints.
const boost::shared_ptr< StateAbstract > & get_state() const
Return the state.
virtual void calcDiff(const boost::shared_ptr< ConstraintDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the Jacobian of the constraint with respect to the state only.
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 calc(const boost::shared_ptr< ConstraintDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the constraint value for nodes that depends only on the state.
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.
ConstraintModelAbstractTpl(boost::shared_ptr< StateAbstract > state, const std::size_t ng, const std::size_t nh)
Initialize the constraint model.
virtual void calcDiff(const boost::shared_ptr< ConstraintDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)=0
Compute the Jacobian of the constraint.
boost::shared_ptr< StateAbstract > state_
State description.
std::size_t nu_
Control dimension.
VectorXs unone_
No control vector.
std::size_t nh_
Number of equality constraints.
boost::shared_ptr< ResidualModelAbstract > residual_
Residual model.
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.
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.
ConstraintModelAbstractTpl(boost::shared_ptr< StateAbstract > state, boost::shared_ptr< ResidualModelAbstract > residual, const std::size_t ng, const std::size_t nh)
Initialize the constraint model.
virtual void calc(const boost::shared_ptr< ConstraintDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)=0
Compute the constraint value.
const boost::shared_ptr< ResidualModelAbstract > & get_residual() const
Return the residual model.
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.
boost::shared_ptr< ResidualDataAbstract > residual
Residual data.
VectorXs g
Inequality constraint values.
MatrixXs Hx
Jacobian of the equality constraint.
MatrixXs Hu
Jacobian of the equality constraint.
DataCollectorAbstract * shared
Shared data.
MatrixXs Gu
Jacobian of the inequality constraint.