// Copyright (c) FIRST and other WPILib contributors. // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. package edu.wpi.first.math; import org.ejml.simple.SimpleMatrix; public final class DARE { private DARE() { throw new UnsupportedOperationException("This is a utility class!"); } /** * Computes the unique stabilizing solution X to the discrete-time algebraic Riccati equation. * *
AᵀXA − X − AᵀXB(BᵀXB + R)⁻¹BᵀXA + Q = 0 * *
This internal function skips expensive precondition checks for increased performance. The * solver may hang if any of the following occur: * *
Only use this function if you're sure the preconditions are met.
*
* @param 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ₖ.
*
* This is a more general form of the following. The linear-quadratic regulator is the feedback
* control law uₖ that minimizes the following cost function subject to xₖ₊₁ = Axₖ + Buₖ:
*
* This can be refactored as:
*
* This internal function skips expensive precondition checks for increased performance. The
* solver may hang if any of the following occur:
*
* Only use this function if you're sure the preconditions are met.
*
* @param AᵀXA − X − AᵀXB(BᵀXB + R)⁻¹BᵀXA + Q = 0
*
* @param 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ₖ.
*
* This is a more general form of the following. The linear-quadratic regulator is the feedback
* control law uₖ that minimizes the following cost function subject to xₖ₊₁ = Axₖ + Buₖ:
*
* This can be refactored as:
*
*
* ∞ [xₖ]ᵀ[Q N][xₖ]
* J = Σ [uₖ] [Nᵀ R][uₖ] ΔT
* k=0
*
*
*
* ∞
* J = Σ (xₖᵀQxₖ + uₖᵀRuₖ) ΔT
* k=0
*
*
*
* ∞ [xₖ]ᵀ[Q 0][xₖ]
* J = Σ [uₖ] [0 R][uₖ] ΔT
* k=0
*
*
*
*
*
*
* ∞ [xₖ]ᵀ[Q N][xₖ]
* J = Σ [uₖ] [Nᵀ R][uₖ] ΔT
* k=0
*
*
*
* ∞
* J = Σ (xₖᵀQxₖ + uₖᵀRuₖ) ΔT
* k=0
*
*
*
* ∞ [xₖ]ᵀ[Q 0][xₖ]
* J = Σ [uₖ] [0 R][uₖ] ΔT
* k=0
*
*
* @param