crocoddyl  1.8.1
Contact RObot COntrol by Differential DYnamic programming Library (Crocoddyl)
residual.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2021, University of Edinburgh
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/fwd.hpp"
13 #include "crocoddyl/core/cost-base.hpp"
14 #include "crocoddyl/core/residual-base.hpp"
15 
16 namespace crocoddyl {
17 
35 template <typename _Scalar>
36 class CostModelResidualTpl : public CostModelAbstractTpl<_Scalar> {
37  public:
38  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
39 
40  typedef _Scalar Scalar;
48  typedef typename MathBase::VectorXs VectorXs;
49  typedef typename MathBase::MatrixXs MatrixXs;
50 
58  CostModelResidualTpl(boost::shared_ptr<typename Base::StateAbstract> state,
59  boost::shared_ptr<ActivationModelAbstract> activation,
60  boost::shared_ptr<ResidualModelAbstract> residual);
69  CostModelResidualTpl(boost::shared_ptr<typename Base::StateAbstract> state,
70  boost::shared_ptr<ResidualModelAbstract> residual);
71  virtual ~CostModelResidualTpl();
72 
80  virtual void calc(const boost::shared_ptr<CostDataAbstract>& data, const Eigen::Ref<const VectorXs>& x,
81  const Eigen::Ref<const VectorXs>& u);
82 
90  virtual void calcDiff(const boost::shared_ptr<CostDataAbstract>& data, const Eigen::Ref<const VectorXs>& x,
91  const Eigen::Ref<const VectorXs>& u);
92 
96  virtual boost::shared_ptr<CostDataAbstract> createData(DataCollectorAbstract* const data);
97 
103  virtual void print(std::ostream& os) const;
104 
105  protected:
106  using Base::activation_;
107  using Base::nu_;
108  using Base::residual_;
109  using Base::state_;
110  using Base::unone_;
111 };
112 
113 template <typename _Scalar>
114 struct CostDataResidualTpl : public CostDataAbstractTpl<_Scalar> {
115  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
116 
117  typedef _Scalar Scalar;
121  typedef typename MathBase::MatrixXs MatrixXs;
122 
123  template <template <typename Scalar> class Model>
124  CostDataResidualTpl(Model<Scalar>* const model, DataCollectorAbstract* const data)
125  : Base(model, data),
126  Arr_Rx(model->get_residual()->get_nr(), model->get_state()->get_ndx()),
127  Arr_Ru(model->get_residual()->get_nr(), model->get_nu()) {
128  Arr_Rx.setZero();
129  Arr_Ru.setZero();
130  }
131 
132  MatrixXs Arr_Rx;
133  MatrixXs Arr_Ru;
134  using Base::activation;
135  using Base::cost;
136  using Base::Lu;
137  using Base::Luu;
138  using Base::Lx;
139  using Base::Lxu;
140  using Base::Lxx;
141  using Base::residual;
142  using Base::shared;
143 };
144 
145 } // namespace crocoddyl
146 
147 /* --- Details -------------------------------------------------------------- */
148 /* --- Details -------------------------------------------------------------- */
149 /* --- Details -------------------------------------------------------------- */
150 #include "crocoddyl/core/costs/residual.hxx"
151 
152 #endif // CROCODDYL_CORE_COSTS_RESIDUAL_COST_HPP_
boost::shared_ptr< ResidualModelAbstract > residual_
Residual model.
Definition: cost-base.hpp:236
Abstract class for cost models.
Definition: cost-base.hpp:49
Residual-based cost.
Definition: residual.hpp:36
virtual void print(std::ostream &os) const
Print relevant information of the cost-residual model.
CostModelResidualTpl(boost::shared_ptr< typename Base::StateAbstract > state, boost::shared_ptr< ActivationModelAbstract > activation, boost::shared_ptr< ResidualModelAbstract > residual)
Initialize the residual cost model.
virtual boost::shared_ptr< CostDataAbstract > createData(DataCollectorAbstract *const data)
Create the residual cost data.
boost::shared_ptr< ActivationModelAbstract > activation_
Activation model.
Definition: cost-base.hpp:235
Abstract class for residual models.
Definition: fwd.hpp:57
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.
VectorXs unone_
No control vector.
Definition: cost-base.hpp:238
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.
std::size_t nu_
Control dimension.
Definition: cost-base.hpp:237
boost::shared_ptr< StateAbstract > state_
State description.
Definition: cost-base.hpp:234