[wpimath] Fix computation of C for DARE (A, C) detectability check (#5609)

If Q has off-diagonal entries, C and Cᵀ are different.
This commit is contained in:
Tyler Veness
2023-09-04 21:12:25 -07:00
committed by GitHub
parent ac23f92451
commit 814f18c7f5

View File

@@ -73,10 +73,13 @@ void CheckDARE_ABQ(const Eigen::Matrix<double, States, States>& A,
}
// Require (A, C) pair be detectable where Q = CᵀC
//
// Q = CᵀC = LDLᵀ
// C = √(D)Lᵀ
{
Eigen::Matrix<double, States, States> C =
Eigen::Matrix<double, States, States>{Q_ldlt.matrixL()} *
Q_ldlt.vectorD().cwiseSqrt().asDiagonal();
Q_ldlt.vectorD().cwiseSqrt().asDiagonal() *
Eigen::Matrix<double, States, States>{Q_ldlt.matrixL().transpose()};
if (!IsDetectable<States, States>(A, C)) {
std::string msg = fmt::format(