crocoddyl  1.8.0
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;
47  typedef typename MathBase::VectorXs VectorXs;
48  typedef typename MathBase::MatrixXs MatrixXs;
49 
57  CostModelResidualTpl(boost::shared_ptr<typename Base::StateAbstract> state,
58  boost::shared_ptr<ActivationModelAbstract> activation,
59  boost::shared_ptr<ResidualModelAbstract> residual);
68  CostModelResidualTpl(boost::shared_ptr<typename Base::StateAbstract> state,
69  boost::shared_ptr<ResidualModelAbstract> residual);
70  virtual ~CostModelResidualTpl();
71 
79  virtual void calc(const boost::shared_ptr<CostDataAbstract>& data, const Eigen::Ref<const VectorXs>& x,
80  const Eigen::Ref<const VectorXs>& u);
81 
89  virtual void calcDiff(const boost::shared_ptr<CostDataAbstract>& data, const Eigen::Ref<const VectorXs>& x,
90  const Eigen::Ref<const VectorXs>& u);
91 
95  virtual boost::shared_ptr<CostDataAbstract> createData(DataCollectorAbstract* const data);
96 
102  virtual void print(std::ostream& os) const;
103 
104  protected:
105  using Base::activation_;
106  using Base::nu_;
107  using Base::residual_;
108  using Base::state_;
109  using Base::unone_;
110 };
111 
112 template <typename _Scalar>
113 struct CostDataResidualTpl : public CostDataAbstractTpl<_Scalar> {
114  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
115 
116  typedef _Scalar Scalar;
120  typedef typename MathBase::MatrixXs MatrixXs;
121 
122  template <template <typename Scalar> class Model>
123  CostDataResidualTpl(Model<Scalar>* const model, DataCollectorAbstract* const data)
124  : Base(model, data),
125  Arr_Rx(model->get_residual()->get_nr(), model->get_state()->get_ndx()),
126  Arr_Ru(model->get_residual()->get_nr(), model->get_nu()) {
127  Arr_Rx.setZero();
128  Arr_Ru.setZero();
129  }
130 
131  MatrixXs Arr_Rx;
132  MatrixXs Arr_Ru;
133  using Base::activation;
134  using Base::cost;
135  using Base::Lu;
136  using Base::Luu;
137  using Base::Lx;
138  using Base::Lxu;
139  using Base::Lxx;
140  using Base::residual;
141  using Base::shared;
142 };
143 
144 } // namespace crocoddyl
145 
146 /* --- Details -------------------------------------------------------------- */
147 /* --- Details -------------------------------------------------------------- */
148 /* --- Details -------------------------------------------------------------- */
149 #include "crocoddyl/core/costs/residual.hxx"
150 
151 #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