Skip to content

Commit

Permalink
[wpimath] Clean up notation in DARE precondition docs (wpilibsuite#5595)
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul authored Aug 31, 2023
1 parent b2dd594 commit 10d4f5b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
28 changes: 22 additions & 6 deletions wpimath/src/main/java/edu/wpi/first/math/DARE.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ public static <States extends Num, Inputs extends Num> Matrix<States, States> da
*
* <p>AᵀXA − X − (AᵀXB + N)(BᵀXB + R)⁻¹(BᵀXA + Nᵀ) + Q = 0
*
* <p>This is equivalent to solving the original DARE:
*
* <p>A₂ᵀXA₂ − X − A₂ᵀXB(BᵀXB + R)⁻¹BᵀXA₂ + Q₂ = 0
*
* <p>where A₂ and Q₂ are a change of variables:
*
* <p>A₂ = A − BR⁻¹Nᵀ and Q₂ = Q − NR⁻¹Nᵀ
*
* <p>This overload of the DARE is useful for finding the control law uₖ that minimizes the
* following cost function subject to xₖ₊₁ = Axₖ + Buₖ.
*
Expand Down Expand Up @@ -88,10 +96,10 @@ public static <States extends Num, Inputs extends Num> Matrix<States, States> da
* solver may hang if any of the following occur:
*
* <ul>
* <li>Q − NR⁻¹Nᵀ isn't symmetric positive semidefinite
* <li>Q isn't symmetric positive semidefinite
* <li>R isn't symmetric positive definite
* <li>The (A − BR⁻¹Nᵀ, B) pair isn't stabilizable
* <li>The (A, C) pair where Q = CᵀC isn't detectable
* <li>The (A, B) pair isn't stabilizable
* <li>The (A, C) pair where Q = CᵀC isn't detectable
* </ul>
*
* <p>Only use this function if you're sure the preconditions are met.
Expand Down Expand Up @@ -163,6 +171,14 @@ public static <States extends Num, Inputs extends Num> Matrix<States, States> da
*
* <p>AᵀXA − X − (AᵀXB + N)(BᵀXB + R)⁻¹(BᵀXA + Nᵀ) + Q = 0
*
* <p>This is equivalent to solving the original DARE:
*
* <p>A₂ᵀXA₂ − X − A₂ᵀXB(BᵀXB + R)⁻¹BᵀXA₂ + Q₂ = 0
*
* <p>where A₂ and Q₂ are a change of variables:
*
* <p>A₂ = A − BR⁻¹Nᵀ and Q₂ = Q − NR⁻¹Nᵀ
*
* <p>This overload of the DARE is useful for finding the control law uₖ that minimizes the
* following cost function subject to xₖ₊₁ = Axₖ + Buₖ.
*
Expand Down Expand Up @@ -197,10 +213,10 @@ public static <States extends Num, Inputs extends Num> Matrix<States, States> da
* @param R Input cost matrix.
* @param N State-input cross-term cost matrix.
* @return Solution of DARE.
* @throws IllegalArgumentException if Q − NR⁻¹Nᵀ isn't symmetric positive semidefinite.
* @throws IllegalArgumentException if Q isn't symmetric positive semidefinite.
* @throws IllegalArgumentException if R isn't symmetric positive definite.
* @throws IllegalArgumentException if the (A − BR⁻¹Nᵀ, B) pair isn't stabilizable.
* @throws IllegalArgumentException if the (A, C) pair where Q = CᵀC isn't detectable.
* @throws IllegalArgumentException if the (A, B) pair isn't stabilizable.
* @throws IllegalArgumentException if the (A, C) pair where Q = CᵀC isn't detectable.
*/
public static <States extends Num, Inputs extends Num> Matrix<States, States> dare(
Matrix<States, States> A,
Expand Down
30 changes: 23 additions & 7 deletions wpimath/src/main/native/include/frc/DARE.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ Riccati equation:
AᵀXA − X − (AᵀXB + N)(BᵀXB + R)⁻¹(BᵀXA + Nᵀ) + Q = 0
This is equivalent to solving the original DARE:
A₂ᵀXA₂ − X − A₂ᵀXB(BᵀXB + R)⁻¹BᵀXA₂ + Q₂ = 0
where A₂ and Q₂ are a change of variables:
A₂ = A − BR⁻¹Nᵀ and Q₂ = Q − NR⁻¹Nᵀ
This overload of the DARE is useful for finding the control law uₖ that
minimizes the following cost function subject to xₖ₊₁ = Axₖ + Buₖ.
Expand Down Expand Up @@ -212,10 +220,10 @@ J = Σ [uₖ] [0 R][uₖ] ΔT
This internal function skips expensive precondition checks for increased
performance. The solver may hang if any of the following occur:
<ul>
<li>Q − NR⁻¹Nᵀ isn't symmetric positive semidefinite</li>
<li>Q isn't symmetric positive semidefinite</li>
<li>R isn't symmetric positive definite</li>
<li>The (A − BR⁻¹Nᵀ, B) pair isn't stabilizable</li>
<li>The (A, C) pair where Q = CᵀC isn't detectable</li>
<li>The (A, B) pair isn't stabilizable</li>
<li>The (A, C) pair where Q = CᵀC isn't detectable</li>
</ul>
Only use this function if you're sure the preconditions are met.
Expand Down Expand Up @@ -300,6 +308,14 @@ Riccati equation:
AᵀXA − X − (AᵀXB + N)(BᵀXB + R)⁻¹(BᵀXA + Nᵀ) + Q = 0
This is equivalent to solving the original DARE:
A₂ᵀXA₂ − X − A₂ᵀXB(BᵀXB + R)⁻¹BᵀXA₂ + Q₂ = 0
where A₂ and Q₂ are a change of variables:
A₂ = A − BR⁻¹Nᵀ and Q₂ = Q − NR⁻¹Nᵀ
This overload of the DARE is useful for finding the control law uₖ that
minimizes the following cost function subject to xₖ₊₁ = Axₖ + Buₖ.
Expand Down Expand Up @@ -334,11 +350,11 @@ J = Σ [uₖ] [0 R][uₖ] ΔT
@param Q The state cost matrix.
@param R The input cost matrix.
@param N The state-input cross cost matrix.
@throws std::invalid_argument if Q − NR⁻¹Nᵀ isn't symmetric positive
semidefinite.
@throws std::invalid_argument if Q₂ isn't symmetric positive semidefinite.
@throws std::invalid_argument if R isn't symmetric positive definite.
@throws std::invalid_argument if the (A − BR⁻¹Nᵀ, B) pair isn't stabilizable.
@throws std::invalid_argument if the (A, C) pair where Q = CᵀC isn't detectable.
@throws std::invalid_argument if the (A₂, B) pair isn't stabilizable.
@throws std::invalid_argument if the (A₂, C) pair where Q₂ = CᵀC isn't
detectable.
*/
template <int States, int Inputs>
Eigen::Matrix<double, States, States> DARE(
Expand Down

0 comments on commit 10d4f5b

Please sign in to comment.