8 #ifdef USE_MATLAB_CPP_INTERFACE 9 #include <matlabCppInterface/Engine.hpp> 15 template <
size_t STATE_DIM,
size_t CONTROL_DIM>
22 bool solveRiccatiIteratively)
27 bool success = care_.solve(Q, R, A, B, P, RisDiagonal, R_inverse, solveRiccatiIteratively);
29 K = (R_inverse * (B.transpose() * P));
34 #ifdef USE_MATLAB_CPP_INTERFACE 35 template <
size_t STATE_DIM,
size_t CONTROL_DIM>
41 bool checkControllability)
43 if (!matlabEngine_.isInitialized())
44 matlabEngine_.initialize();
46 matlabEngine_.put(
"Q", Q);
47 matlabEngine_.put(
"R", R);
48 matlabEngine_.put(
"A", A);
49 matlabEngine_.put(
"B", B);
51 if (checkControllability)
53 matlabEngine_.executeCommand(
"Co=ctrb(A,B);");
54 matlabEngine_.executeCommand(
"unco=length(A)-rank(Co);");
55 int uncontrollableStates = 0;
56 matlabEngine_.get(
"unco", uncontrollableStates);
58 if (uncontrollableStates > 0)
60 std::cout <<
"System is not controllable, # uncontrollable states: " << uncontrollableStates << std::endl;
64 matlabEngine_.executeCommand(
"[K,~,~] = lqr(A,B,Q,R);");
66 Eigen::MatrixXd Kmatlab;
67 matlabEngine_.get(
"K", Kmatlab);
73 #endif //USE_MATLAB_CPP_INTERFACE Eigen::Matrix< double, STATE_DIM, CONTROL_DIM > control_gain_matrix_t
Definition: LQR.hpp:40
continuous-time infinite-horizon LQR
Definition: LQR.hpp:32
Eigen::Matrix< double, CONTROL_DIM, CONTROL_DIM > control_matrix_t
Definition: LQR.hpp:38
bool compute(const state_matrix_t &Q, const control_matrix_t &R, const state_matrix_t &A, const control_gain_matrix_t &B, control_feedback_t &K, bool RisDiagonal=false, bool solveRiccatiIteratively=false)
design the infinite-horizon LQR controller.
Definition: LQR-impl.hpp:16
Eigen::Matrix< double, nStates, nStates > state_matrix_t
Eigen::Matrix< double, CONTROL_DIM, STATE_DIM > control_feedback_t
Definition: LQR.hpp:41