crocoddyl  1.4.0
Contact RObot COntrol by Differential DYnamic programming Library (Crocoddyl)
diff-lqr.hpp
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2018-2020, 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, 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 
62  protected:
64  using Base::nr_;
65  using Base::nu_;
66  using Base::state_;
67  using Base::u_lb_;
68  using Base::u_ub_;
69  using Base::unone_;
70 
71  private:
72  bool drift_free_;
73  MatrixXs Fq_;
74  MatrixXs Fv_;
75  MatrixXs Fu_;
76  VectorXs f0_;
77  MatrixXs Lxx_;
78  MatrixXs Lxu_;
79  MatrixXs Luu_;
80  VectorXs lx_;
81  VectorXs lu_;
82 };
83 
84 template <typename _Scalar>
86  typedef _Scalar Scalar;
89  typedef typename MathBase::VectorXs VectorXs;
90  typedef typename MathBase::MatrixXs MatrixXs;
91 
92  template <template <typename Scalar> class Model>
93  explicit DifferentialActionDataLQRTpl(Model<Scalar>* const model) : Base(model) {
94  // Setting the linear model and quadratic cost here because they are constant
95  Fx.leftCols(model->get_state()->get_nq()) = model->get_Fq();
96  Fx.rightCols(model->get_state()->get_nv()) = model->get_Fv();
97  Fu = model->get_Fu();
98  Lxx = model->get_Lxx();
99  Luu = model->get_Luu();
100  Lxu = model->get_Lxu();
101  }
102 
103  using Base::cost;
104  using Base::Fu;
105  using Base::Fx;
106  using Base::Lu;
107  using Base::Luu;
108  using Base::Lx;
109  using Base::Lxu;
110  using Base::Lxx;
111  using Base::r;
112  using Base::xout;
113 };
114 
115 } // namespace crocoddyl
116 
117 /* --- Details -------------------------------------------------------------- */
118 /* --- Details -------------------------------------------------------------- */
119 /* --- Details -------------------------------------------------------------- */
120 #include "crocoddyl/core/actions/diff-lqr.hxx"
121 #endif // CROCODDYL_CORE_ACTIONS_DIFF_LQR_HPP_
Abstract class for differential action model.
std::size_t nr_
Dimension of the cost residual.
virtual bool checkData(const boost::shared_ptr< DifferentialActionDataAbstract > &data)
Checks that a specific data belongs to this model.
bool has_control_limits_
Indicates whether any of the control limits is finite.
boost::shared_ptr< StateAbstract > state_
Model of the state.
virtual boost::shared_ptr< DifferentialActionDataAbstract > createData()
Create the differential action data.