crocoddyl  1.3.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 
41  const MatrixXs& get_Fq() const;
42  const MatrixXs& get_Fv() const;
43  const MatrixXs& get_Fu() const;
44  const VectorXs& get_f0() const;
45  const VectorXs& get_lx() const;
46  const VectorXs& get_lu() const;
47  const MatrixXs& get_Lxx() const;
48  const MatrixXs& get_Lxu() const;
49  const MatrixXs& get_Luu() const;
50 
51  void set_Fq(const MatrixXs& Fq);
52  void set_Fv(const MatrixXs& Fv);
53  void set_Fu(const MatrixXs& Fu);
54  void set_f0(const VectorXs& f0);
55  void set_lx(const VectorXs& lx);
56  void set_lu(const VectorXs& lu);
57  void set_Lxx(const MatrixXs& Lxx);
58  void set_Lxu(const MatrixXs& Lxu);
59  void set_Luu(const MatrixXs& Luu);
60 
61  protected:
63  using Base::nr_;
64  using Base::nu_;
65  using Base::state_;
66  using Base::u_lb_;
67  using Base::u_ub_;
68  using Base::unone_;
69 
70  private:
71  bool drift_free_;
72  MatrixXs Fq_;
73  MatrixXs Fv_;
74  MatrixXs Fu_;
75  VectorXs f0_;
76  MatrixXs Lxx_;
77  MatrixXs Lxu_;
78  MatrixXs Luu_;
79  VectorXs lx_;
80  VectorXs lu_;
81 };
82 
83 template <typename _Scalar>
85  typedef _Scalar Scalar;
88  typedef typename MathBase::VectorXs VectorXs;
89  typedef typename MathBase::MatrixXs MatrixXs;
90 
91  template <template <typename Scalar> class Model>
92  explicit DifferentialActionDataLQRTpl(Model<Scalar>* const model) : Base(model) {
93  // Setting the linear model and quadratic cost here because they are constant
94  Fx.leftCols(model->get_state()->get_nq()) = model->get_Fq();
95  Fx.rightCols(model->get_state()->get_nv()) = model->get_Fv();
96  Fu = model->get_Fu();
97  Lxx = model->get_Lxx();
98  Luu = model->get_Luu();
99  Lxu = model->get_Lxu();
100  }
101 
102  using Base::cost;
103  using Base::Fu;
104  using Base::Fx;
105  using Base::Lu;
106  using Base::Luu;
107  using Base::Lx;
108  using Base::Lxu;
109  using Base::Lxx;
110  using Base::r;
111  using Base::xout;
112 };
113 
114 } // namespace crocoddyl
115 
116 /* --- Details -------------------------------------------------------------- */
117 /* --- Details -------------------------------------------------------------- */
118 /* --- Details -------------------------------------------------------------- */
119 #include "crocoddyl/core/actions/diff-lqr.hxx"
120 #endif // CROCODDYL_CORE_ACTIONS_DIFF_LQR_HPP_
This class DifferentialActionModelAbstract represents a first-order ODE, i.e. where and represents ...
std::size_t nr_
Dimension of the cost residual.
bool has_control_limits_
Indicates whether any of the control limits is finite.
boost::shared_ptr< StateAbstract > state_
Model of the state.