33 const Matrix &R,
const Matrix &M,
const double tolerance,
34 const uint max_num_iteration,
Matrix *ptr_K,
35 uint *iterate_num,
double *result_diff) {
36 if (A.rows() != A.cols() || B.
rows() != A.rows() || Q.
rows() != Q.cols() ||
37 Q.
rows() != A.rows() || R.
rows() != R.cols() || R.
rows() != B.cols() ||
38 M.
rows() != Q.
rows() || M.cols() != R.cols()) {
39 AERROR <<
"LQR solver: one or more matrices have incompatible dimensions.";
50 uint num_iteration = 0;
51 double diff = std::numeric_limits<double>::max();
52 while (num_iteration++ < max_num_iteration && diff > tolerance) {
55 (AT * P * B + M) * (R + BT * P * B).inverse() * (BT * P * A + MT) + Q;
57 diff = fabs((P_next - P).maxCoeff());
61 if (num_iteration >= max_num_iteration) {
62 ADEBUG <<
"LQR solver cannot converge to a solution, "
63 "last consecutive result diff is: "
66 ADEBUG <<
"LQR solver converged at iteration: " << num_iteration
67 <<
", max consecutive result diff.: " << diff;
69 *iterate_num = num_iteration;
71 *ptr_K = (R + BT * P * B).inverse() * (BT * P * A + MT);
void SolveLQRProblem(const Matrix &A, const Matrix &B, const Matrix &Q, const Matrix &R, const Matrix &M, const double tolerance, const uint max_num_iteration, Matrix *ptr_K, uint *iterate_num, double *result_diff)