Crocoddyl
residual.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2021-2023, University of Edinburgh, Heriot-Watt University
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
8 
9 #ifndef CROCODDYL_CORE_COSTS_RESIDUAL_COST_HPP_
10 #define CROCODDYL_CORE_COSTS_RESIDUAL_COST_HPP_
11 
12 #include "crocoddyl/core/cost-base.hpp"
13 #include "crocoddyl/core/fwd.hpp"
14 #include "crocoddyl/core/residual-base.hpp"
15 
16 namespace crocoddyl {
17 
38 template <typename _Scalar>
39 class CostModelResidualTpl : public CostModelAbstractTpl<_Scalar> {
40  public:
41  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
42 
43  typedef _Scalar Scalar;
51  typedef typename MathBase::VectorXs VectorXs;
52  typedef typename MathBase::MatrixXs MatrixXs;
53 
61  CostModelResidualTpl(boost::shared_ptr<typename Base::StateAbstract> state,
62  boost::shared_ptr<ActivationModelAbstract> activation,
63  boost::shared_ptr<ResidualModelAbstract> residual);
73  CostModelResidualTpl(boost::shared_ptr<typename Base::StateAbstract> state,
74  boost::shared_ptr<ResidualModelAbstract> residual);
75  virtual ~CostModelResidualTpl();
76 
84  virtual void calc(const boost::shared_ptr<CostDataAbstract>& data,
85  const Eigen::Ref<const VectorXs>& x,
86  const Eigen::Ref<const VectorXs>& u);
87 
97  virtual void calc(const boost::shared_ptr<CostDataAbstract>& data,
98  const Eigen::Ref<const VectorXs>& x);
99 
107  virtual void calcDiff(const boost::shared_ptr<CostDataAbstract>& data,
108  const Eigen::Ref<const VectorXs>& x,
109  const Eigen::Ref<const VectorXs>& u);
110 
122  virtual void calcDiff(const boost::shared_ptr<CostDataAbstract>& data,
123  const Eigen::Ref<const VectorXs>& x);
124 
128  virtual boost::shared_ptr<CostDataAbstract> createData(
129  DataCollectorAbstract* const data);
130 
136  virtual void print(std::ostream& os) const;
137 
138  protected:
139  using Base::activation_;
140  using Base::nu_;
141  using Base::residual_;
142  using Base::state_;
143  using Base::unone_;
144 };
145 
146 template <typename _Scalar>
147 struct CostDataResidualTpl : public CostDataAbstractTpl<_Scalar> {
148  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
149 
150  typedef _Scalar Scalar;
154 
155  template <template <typename Scalar> class Model>
156  CostDataResidualTpl(Model<Scalar>* const model,
157  DataCollectorAbstract* const data)
158  : Base(model, data) {}
159 
160  using Base::activation;
161  using Base::cost;
162  using Base::Lu;
163  using Base::Luu;
164  using Base::Lx;
165  using Base::Lxu;
166  using Base::Lxx;
167  using Base::residual;
168  using Base::shared;
169 };
170 
171 } // namespace crocoddyl
172 
173 /* --- Details -------------------------------------------------------------- */
174 /* --- Details -------------------------------------------------------------- */
175 /* --- Details -------------------------------------------------------------- */
176 #include "crocoddyl/core/costs/residual.hxx"
177 
178 #endif // CROCODDYL_CORE_COSTS_RESIDUAL_COST_HPP_
Abstract class for cost models.
Definition: cost-base.hpp:59
boost::shared_ptr< ActivationModelAbstract > activation_
Activation model.
Definition: cost-base.hpp:271
boost::shared_ptr< StateAbstract > state_
State description.
Definition: cost-base.hpp:270
std::size_t nu_
Control dimension.
Definition: cost-base.hpp:273
VectorXs unone_
No control vector.
Definition: cost-base.hpp:274
boost::shared_ptr< ResidualModelAbstract > residual_
Residual model.
Definition: cost-base.hpp:272
Residual-based cost.
Definition: residual.hpp:39
virtual boost::shared_ptr< CostDataAbstract > createData(DataCollectorAbstract *const data)
Create the residual cost data.
CostModelResidualTpl(boost::shared_ptr< typename Base::StateAbstract > state, boost::shared_ptr< ResidualModelAbstract > residual)
Initialize the residual cost model.
virtual void calcDiff(const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the derivatives of the residual cost 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< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the residual cost.
virtual void calcDiff(const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the derivatives of the residual cost.
CostModelResidualTpl(boost::shared_ptr< typename Base::StateAbstract > state, boost::shared_ptr< ActivationModelAbstract > activation, boost::shared_ptr< ResidualModelAbstract > residual)
Initialize the residual cost model.
virtual void calc(const boost::shared_ptr< CostDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Compute the residual cost based on state only.
Abstract class for residual models.