crocoddyl  1.8.1
Contact RObot COntrol by Differential DYnamic programming Library (Crocoddyl)
diff-lqr.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2021, LAAS-CNRS, University of Edinburgh
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
8 
9 #ifndef CROCODDYL_CORE_ACTIONS_DIFF_LQR_HPP_
10 #define CROCODDYL_CORE_ACTIONS_DIFF_LQR_HPP_
11 
12 #include <stdexcept>
13 
14 #include "crocoddyl/core/fwd.hpp"
15 #include "crocoddyl/core/diff-action-base.hpp"
16 #include "crocoddyl/core/states/euclidean.hpp"
17 
18 namespace crocoddyl {
19 
20 template <typename _Scalar>
22  public:
23  typedef _Scalar Scalar;
29  typedef typename MathBase::VectorXs VectorXs;
30  typedef typename MathBase::MatrixXs MatrixXs;
31 
32  DifferentialActionModelLQRTpl(const std::size_t nq, const std::size_t nu, const bool drift_free = true);
34 
35  virtual void calc(const boost::shared_ptr<DifferentialActionDataAbstract>& data, const Eigen::Ref<const VectorXs>& x,
36  const Eigen::Ref<const VectorXs>& u);
37  virtual void calcDiff(const boost::shared_ptr<DifferentialActionDataAbstract>& data,
38  const Eigen::Ref<const VectorXs>& x, const Eigen::Ref<const VectorXs>& u);
39  virtual boost::shared_ptr<DifferentialActionDataAbstract> createData();
40  virtual bool checkData(const boost::shared_ptr<DifferentialActionDataAbstract>& data);
41 
42  const MatrixXs& get_Fq() const;
43  const MatrixXs& get_Fv() const;
44  const MatrixXs& get_Fu() const;
45  const VectorXs& get_f0() const;
46  const VectorXs& get_lx() const;
47  const VectorXs& get_lu() const;
48  const MatrixXs& get_Lxx() const;
49  const MatrixXs& get_Lxu() const;
50  const MatrixXs& get_Luu() const;
51 
52  void set_Fq(const MatrixXs& Fq);
53  void set_Fv(const MatrixXs& Fv);
54  void set_Fu(const MatrixXs& Fu);
55  void set_f0(const VectorXs& f0);
56  void set_lx(const VectorXs& lx);
57  void set_lu(const VectorXs& lu);
58  void set_Lxx(const MatrixXs& Lxx);
59  void set_Lxu(const MatrixXs& Lxu);
60  void set_Luu(const MatrixXs& Luu);
61 
67  virtual void print(std::ostream& os) const;
68 
69  protected:
70  using Base::nu_;
71  using Base::state_;
72 
73  private:
74  bool drift_free_;
75  MatrixXs Fq_;
76  MatrixXs Fv_;
77  MatrixXs Fu_;
78  VectorXs f0_;
79  MatrixXs Lxx_;
80  MatrixXs Lxu_;
81  MatrixXs Luu_;
82  VectorXs lx_;
83  VectorXs lu_;
84 };
85 
86 template <typename _Scalar>
88  typedef _Scalar Scalar;
91  typedef typename MathBase::VectorXs VectorXs;
92  typedef typename MathBase::MatrixXs MatrixXs;
93 
94  template <template <typename Scalar> class Model>
95  explicit DifferentialActionDataLQRTpl(Model<Scalar>* const model) : Base(model) {
96  // Setting the linear model and quadratic cost here because they are constant
97  Fx.leftCols(model->get_state()->get_nq()) = model->get_Fq();
98  Fx.rightCols(model->get_state()->get_nv()) = model->get_Fv();
99  Fu = model->get_Fu();
100  Lxx = model->get_Lxx();
101  Luu = model->get_Luu();
102  Lxu = model->get_Lxu();
103  }
104 
105  using Base::cost;
106  using Base::Fu;
107  using Base::Fx;
108  using Base::Lu;
109  using Base::Luu;
110  using Base::Lx;
111  using Base::Lxu;
112  using Base::Lxx;
113  using Base::r;
114  using Base::xout;
115 };
116 
117 } // namespace crocoddyl
118 
119 /* --- Details -------------------------------------------------------------- */
120 /* --- Details -------------------------------------------------------------- */
121 /* --- Details -------------------------------------------------------------- */
122 #include "crocoddyl/core/actions/diff-lqr.hxx"
123 #endif // CROCODDYL_CORE_ACTIONS_DIFF_LQR_HPP_
Abstract class for differential action model.
virtual bool checkData(const boost::shared_ptr< DifferentialActionDataAbstract > &data)
Checks that a specific data belongs to this model.
boost::shared_ptr< StateAbstract > state_
Model of the state.
virtual void print(std::ostream &os) const
Print relevant information of the LQR model.
virtual boost::shared_ptr< DifferentialActionDataAbstract > createData()
Create the differential action data.