crocoddyl  1.3.0
Contact RObot COntrol by Differential DYnamic programming Library (Crocoddyl)
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_LQR_HPP_
10 #define CROCODDYL_CORE_ACTIONS_LQR_HPP_
11 
12 #include <stdexcept>
13 
14 #include "crocoddyl/core/fwd.hpp"
15 #include "crocoddyl/core/action-base.hpp"
16 #include "crocoddyl/core/states/euclidean.hpp"
17 
18 namespace crocoddyl {
19 
20 template <typename _Scalar>
21 class ActionModelLQRTpl : public ActionModelAbstractTpl<_Scalar> {
22  public:
23  typedef _Scalar Scalar;
29  typedef typename MathBase::VectorXs VectorXs;
30  typedef typename MathBase::MatrixXs MatrixXs;
31 
32  ActionModelLQRTpl(const std::size_t& nx, const std::size_t& nu, bool drift_free = true);
33  virtual ~ActionModelLQRTpl();
34 
35  virtual void calc(const boost::shared_ptr<ActionDataAbstract>& data, const Eigen::Ref<const VectorXs>& x,
36  const Eigen::Ref<const VectorXs>& u);
37  virtual void calcDiff(const boost::shared_ptr<ActionDataAbstract>& data, const Eigen::Ref<const VectorXs>& x,
38  const Eigen::Ref<const VectorXs>& u);
39  virtual boost::shared_ptr<ActionDataAbstract> createData();
40 
41  const MatrixXs& get_Fx() const;
42  const MatrixXs& get_Fu() const;
43  const VectorXs& get_f0() const;
44  const VectorXs& get_lx() const;
45  const VectorXs& get_lu() const;
46  const MatrixXs& get_Lxx() const;
47  const MatrixXs& get_Lxu() const;
48  const MatrixXs& get_Luu() const;
49 
50  void set_Fx(const MatrixXs& Fx);
51  void set_Fu(const MatrixXs& Fu);
52  void set_f0(const VectorXs& f0);
53  void set_lx(const VectorXs& lx);
54  void set_lu(const VectorXs& lu);
55  void set_Lxx(const MatrixXs& Lxx);
56  void set_Lxu(const MatrixXs& Lxu);
57  void set_Luu(const MatrixXs& Luu);
58 
59  protected:
61  using Base::nr_;
62  using Base::nu_;
63  using Base::state_;
64  using Base::u_lb_;
65  using Base::u_ub_;
66  using Base::unone_;
67 
68  private:
69  bool drift_free_;
70  MatrixXs Fx_;
71  MatrixXs Fu_;
72  VectorXs f0_;
73  MatrixXs Lxx_;
74  MatrixXs Lxu_;
75  MatrixXs Luu_;
76  VectorXs lx_;
77  VectorXs lu_;
78 };
79 
80 template <typename _Scalar>
81 struct ActionDataLQRTpl : public ActionDataAbstractTpl<_Scalar> {
82  typedef _Scalar Scalar;
85 
86  template <template <typename Scalar> class Model>
87  explicit ActionDataLQRTpl(Model<Scalar>* const model) : Base(model) {
88  // Setting the linear model and quadratic cost here because they are constant
89  Fx = model->get_Fx();
90  Fu = model->get_Fu();
91  Lxx = model->get_Lxx();
92  Luu = model->get_Luu();
93  Lxu = model->get_Lxu();
94  }
95 
96  using Base::cost;
97  using Base::Fu;
98  using Base::Fx;
99  using Base::Lu;
100  using Base::Luu;
101  using Base::Lx;
102  using Base::Lxu;
103  using Base::Lxx;
104  using Base::r;
105  using Base::xnext;
106 };
107 
108 } // namespace crocoddyl
109 
110 /* --- Details -------------------------------------------------------------- */
111 /* --- Details -------------------------------------------------------------- */
112 /* --- Details -------------------------------------------------------------- */
113 #include "crocoddyl/core/actions/lqr.hxx"
114 
115 #endif // CROCODDYL_CORE_ACTIONS_LQR_HPP_
bool has_control_limits_
Indicates whether any of the control limits is finite.
Definition: action-base.hpp:70
std::size_t nu_
Control dimension.
Definition: action-base.hpp:64
VectorXs unone_
Neutral state.
Definition: action-base.hpp:67
VectorXs u_ub_
Upper control limits.
Definition: action-base.hpp:69
VectorXs u_lb_
Lower control limits.
Definition: action-base.hpp:68
boost::shared_ptr< StateAbstract > state_
Model of the state.
Definition: action-base.hpp:66
std::size_t nr_
Dimension of the cost residual.
Definition: action-base.hpp:65