- 3.0.2 optimal control module.
CARE.hpp
Go to the documentation of this file.
1 /**********************************************************************************************************************
2 This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich.
3 Licensed under the BSD-2 license (see LICENSE file in main directory)
4 **********************************************************************************************************************/
5 
6 #pragma once
7 
8 #include <iostream>
9 
10 // Schur reordering from Lapack
11 #ifdef CT_USE_LAPACK
12 extern "C" void dtrsen_(const char* JOB,
13  const char* COMPQ,
14  const int* SELECT,
15  const int* N,
16  const double* T,
17  const int* LDT,
18  const double* Q,
19  const int* LDQ,
20  double* WR,
21  double* WI,
22  int* M,
23  double* S,
24  double* SEP,
25  double* WORK,
26  const int* LWORK,
27  int* IWORK,
28  const int* LIWORK,
29  int* INFO);
30 #endif
31 
32 namespace ct {
33 namespace optcon {
34 
45 template <size_t STATE_DIM, size_t CONTROL_DIM>
46 class CARE
47 {
48 public:
49  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
50 
51  typedef Eigen::Matrix<double, STATE_DIM, STATE_DIM> state_matrix_t;
52  typedef Eigen::Matrix<double, CONTROL_DIM, CONTROL_DIM> control_matrix_t;
53  typedef Eigen::Matrix<double, CONTROL_DIM, STATE_DIM> control_state_matrix_t;
54  typedef Eigen::Matrix<double, STATE_DIM, CONTROL_DIM> control_gain_matrix_t;
55  typedef Eigen::Matrix<double, CONTROL_DIM, STATE_DIM> control_feedback_t;
56 
57  typedef Eigen::Matrix<double, 2 * STATE_DIM, 2 * STATE_DIM> schur_matrix_t;
58  typedef Eigen::Matrix<double, 2 * STATE_DIM, STATE_DIM> factor_matrix_t;
59 
60  CARE();
61 
62  // Implementation using the Schur-Method
63  // This is numerically more stable and should be preferred over the naive implementation
64  bool solve(const state_matrix_t& Q,
65  const control_matrix_t& R,
66  const state_matrix_t& A,
67  const control_gain_matrix_t& B,
68  state_matrix_t& P,
69  bool RisDiagonal,
70  control_matrix_t& R_inverse,
71  bool useIterativeSolver = false);
72 
73  state_matrix_t computeSteadyStateRiccatiMatrix(const state_matrix_t& Q,
74  const control_matrix_t& R,
75  const state_matrix_t& A,
76  const control_gain_matrix_t& B,
77  const bool RisDiagonal = false,
78  const bool useIterativeSolver = false);
79 
80 private:
81  bool solveSchurIterative(const schur_matrix_t& M,
82  state_matrix_t& P,
83  double epsilon = 1e-6,
84  int maxIterations = 100000);
85 
86  bool solveSchurDirect(const schur_matrix_t& M, state_matrix_t& P);
87 
88  Eigen::RealSchur<schur_matrix_t> schur_;
89  Eigen::FullPivLU<factor_matrix_t> FullPivLU_;
90 
91  // Lapack
92  int LWORK_;
93  int LIWORK_;
94 
95  Eigen::VectorXd WORK_;
96  Eigen::VectorXi IWORK_;
97 };
98 } // namespace optcon
99 } // namespace ct
state_matrix_t computeSteadyStateRiccatiMatrix(const state_matrix_t &Q, const control_matrix_t &R, const state_matrix_t &A, const control_gain_matrix_t &B, const bool RisDiagonal=false, const bool useIterativeSolver=false)
Definition: CARE-impl.hpp:80
CARE()
Definition: CARE-impl.hpp:12
Eigen::Matrix< double, CONTROL_DIM, STATE_DIM > control_state_matrix_t
Definition: CARE.hpp:53
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef Eigen::Matrix< double, STATE_DIM, STATE_DIM > state_matrix_t
Definition: CARE.hpp:51
Continuous-Time Algebraic Riccati Equation.
Definition: CARE.hpp:46
Eigen::Matrix< double, 2 *STATE_DIM, 2 *STATE_DIM > schur_matrix_t
Definition: CARE.hpp:57
Eigen::Matrix< double, CONTROL_DIM, STATE_DIM > control_feedback_t
Definition: CARE.hpp:55
Eigen::Matrix< double, CONTROL_DIM, CONTROL_DIM > control_matrix_t
Definition: CARE.hpp:52
bool solve(const state_matrix_t &Q, const control_matrix_t &R, const state_matrix_t &A, const control_gain_matrix_t &B, state_matrix_t &P, bool RisDiagonal, control_matrix_t &R_inverse, bool useIterativeSolver=false)
Definition: CARE-impl.hpp:51
Eigen::Matrix< double, STATE_DIM, CONTROL_DIM > control_gain_matrix_t
Definition: CARE.hpp:54
Eigen::Matrix< double, 2 *STATE_DIM, STATE_DIM > factor_matrix_t
Definition: CARE.hpp:58