Crocoddyl
residual.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2021-2024, 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 
70  boost::shared_ptr<typename Base::StateAbstract> state,
71  boost::shared_ptr<ResidualModelAbstract> residual, const VectorXs& lower,
72  const VectorXs& upper, const bool T_act = true);
73 
83  boost::shared_ptr<typename Base::StateAbstract> state,
84  boost::shared_ptr<ResidualModelAbstract> residual,
85  const bool T_act = true);
86  virtual ~ConstraintModelResidualTpl();
87 
95  virtual void calc(const boost::shared_ptr<ConstraintDataAbstract>& data,
96  const Eigen::Ref<const VectorXs>& x,
97  const Eigen::Ref<const VectorXs>& u);
98 
108  virtual void calc(const boost::shared_ptr<ConstraintDataAbstract>& data,
109  const Eigen::Ref<const VectorXs>& x);
110 
118  virtual void calcDiff(const boost::shared_ptr<ConstraintDataAbstract>& data,
119  const Eigen::Ref<const VectorXs>& x,
120  const Eigen::Ref<const VectorXs>& u);
121 
133  virtual void calcDiff(const boost::shared_ptr<ConstraintDataAbstract>& data,
134  const Eigen::Ref<const VectorXs>& x);
135 
139  virtual boost::shared_ptr<ConstraintDataAbstract> createData(
140  DataCollectorAbstract* const data);
141 
147  virtual void print(std::ostream& os) const;
148 
149  private:
150  void updateCalc(const boost::shared_ptr<ConstraintDataAbstract>& data);
151  void updateCalcDiff(const boost::shared_ptr<ConstraintDataAbstract>& data);
152 
153  protected:
154  using Base::lb_;
155  using Base::ng_;
156  using Base::nh_;
157  using Base::nu_;
158  using Base::residual_;
159  using Base::state_;
160  using Base::T_constraint_;
161  using Base::type_;
162  using Base::ub_;
163  using Base::unone_;
164 };
165 
166 template <typename _Scalar>
168  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
169 
170  typedef _Scalar Scalar;
174 
175  template <template <typename Scalar> class Model>
176  ConstraintDataResidualTpl(Model<Scalar>* const model,
177  DataCollectorAbstract* const data)
178  : Base(model, data) {}
179 
180  using Base::g;
181  using Base::Gu;
182  using Base::Gx;
183  using Base::h;
184  using Base::Hu;
185  using Base::Hx;
186  using Base::residual;
187  using Base::shared;
188 };
189 
190 } // namespace crocoddyl
191 
192 /* --- Details -------------------------------------------------------------- */
193 /* --- Details -------------------------------------------------------------- */
194 /* --- Details -------------------------------------------------------------- */
195 #include "crocoddyl/core/constraints/residual.hxx"
196 
197 #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.
ConstraintModelResidualTpl(boost::shared_ptr< typename Base::StateAbstract > state, boost::shared_ptr< ResidualModelAbstract > residual, const bool T_act=true)
Initialize the residual constraint model as an equality constraint.
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.
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, const VectorXs &lower, const VectorXs &upper, const bool T_act=true)
Initialize the residual constraint model as an inequality 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.