Crocoddyl
residual.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2021-2022, Heriot-Watt University, University of Edinburgh
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
8 
9 #ifndef CROCODDYL_CORE_CONSTRAINTS_RESIDUAL_CONSTRAINT_HPP_
10 #define CROCODDYL_CORE_CONSTRAINTS_RESIDUAL_CONSTRAINT_HPP_
11 
12 #include "crocoddyl/core/fwd.hpp"
13 //
14 #include "crocoddyl/core/constraint-base.hpp"
15 #include "crocoddyl/core/residual-base.hpp"
16 
17 namespace crocoddyl {
18 
46 template <typename _Scalar>
48  public:
49  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
50 
51  typedef _Scalar Scalar;
57  typedef typename MathBase::VectorXs VectorXs;
58 
68  boost::shared_ptr<typename Base::StateAbstract> state,
69  boost::shared_ptr<ResidualModelAbstract> residual, const VectorXs& lower,
70  const VectorXs& upper);
71 
79  boost::shared_ptr<typename Base::StateAbstract> state,
80  boost::shared_ptr<ResidualModelAbstract> residual);
81  virtual ~ConstraintModelResidualTpl();
82 
90  virtual void calc(const boost::shared_ptr<ConstraintDataAbstract>& data,
91  const Eigen::Ref<const VectorXs>& x,
92  const Eigen::Ref<const VectorXs>& u);
93 
103  virtual void calc(const boost::shared_ptr<ConstraintDataAbstract>& data,
104  const Eigen::Ref<const VectorXs>& x);
105 
113  virtual void calcDiff(const boost::shared_ptr<ConstraintDataAbstract>& data,
114  const Eigen::Ref<const VectorXs>& x,
115  const Eigen::Ref<const VectorXs>& u);
116 
128  virtual void calcDiff(const boost::shared_ptr<ConstraintDataAbstract>& data,
129  const Eigen::Ref<const VectorXs>& x);
130 
134  virtual boost::shared_ptr<ConstraintDataAbstract> createData(
135  DataCollectorAbstract* const data);
136 
142  virtual void print(std::ostream& os) const;
143 
144  private:
145  void updateCalc(const boost::shared_ptr<ConstraintDataAbstract>& data);
146  void updateCalcDiff(const boost::shared_ptr<ConstraintDataAbstract>& data);
147 
148  protected:
149  using Base::lb_;
150  using Base::ng_;
151  using Base::nh_;
152  using Base::nu_;
153  using Base::residual_;
154  using Base::state_;
155  using Base::type_;
156  using Base::ub_;
157  using Base::unone_;
158 };
159 
160 template <typename _Scalar>
162  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
163 
164  typedef _Scalar Scalar;
168 
169  template <template <typename Scalar> class Model>
170  ConstraintDataResidualTpl(Model<Scalar>* const model,
171  DataCollectorAbstract* const data)
172  : Base(model, data) {}
173 
174  using Base::g;
175  using Base::Gu;
176  using Base::Gx;
177  using Base::h;
178  using Base::Hu;
179  using Base::Hx;
180  using Base::residual;
181  using Base::shared;
182 };
183 
184 } // namespace crocoddyl
185 
186 /* --- Details -------------------------------------------------------------- */
187 /* --- Details -------------------------------------------------------------- */
188 /* --- Details -------------------------------------------------------------- */
189 #include "crocoddyl/core/constraints/residual.hxx"
190 
191 #endif // CROCODDYL_CORE_CONSTRAINTS_RESIDUAL_CONSTRAINT_HPP_
Abstract class for constraint models.
boost::shared_ptr< StateAbstract > state_
State description.
std::size_t nu_
Control dimension.
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.
VectorXs ub_
Upper bound of the constraint.
std::size_t ng_
Number of inequality constraints.
Residual-based constraint.
Definition: residual.hpp:47
virtual boost::shared_ptr< ConstraintDataAbstract > createData(DataCollectorAbstract *const data)
Create the residual constraint data.
virtual void calcDiff(const boost::shared_ptr< ConstraintDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the derivatives of the residual constraint with respect to the state only.
virtual void print(std::ostream &os) const
Print relevant information of the cost-residual model.
virtual void calc(const boost::shared_ptr< ConstraintDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the residual constraint based on state only.
ConstraintModelResidualTpl(boost::shared_ptr< typename Base::StateAbstract > state, boost::shared_ptr< ResidualModelAbstract > residual, const VectorXs &lower, const VectorXs &upper)
Initialize the residual constraint model as an inequality constraint.
virtual void calc(const boost::shared_ptr< ConstraintDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the residual constraint.
virtual void calcDiff(const boost::shared_ptr< ConstraintDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the derivatives of the residual constraint.
ConstraintModelResidualTpl(boost::shared_ptr< typename Base::StateAbstract > state, boost::shared_ptr< ResidualModelAbstract > residual)
Initialize the residual constraint model as an equality constraint.
Abstract class for residual models.
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.