diff --git a/wpimath/src/main/java/edu/wpi/first/math/controller/ControlAffinePlantInversionFeedforward.java b/wpimath/src/main/java/edu/wpi/first/math/controller/ControlAffinePlantInversionFeedforward.java index 385c5c0342..a2a59448c4 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/controller/ControlAffinePlantInversionFeedforward.java +++ b/wpimath/src/main/java/edu/wpi/first/math/controller/ControlAffinePlantInversionFeedforward.java @@ -181,6 +181,9 @@ public class ControlAffinePlantInversionFeedforward calculate(Matrix r, Matrix nextR) { var rDot = (nextR.minus(r)).div(m_dt); + // ṙ = f(r) + Bu + // Bu = ṙ − f(r) + // u = B⁺(ṙ − f(r)) m_uff = m_B.solve(rDot.minus(m_f.apply(r, new Matrix<>(m_inputs, Nat.N1())))); m_r = nextR; diff --git a/wpimath/src/main/java/edu/wpi/first/math/controller/LinearPlantInversionFeedforward.java b/wpimath/src/main/java/edu/wpi/first/math/controller/LinearPlantInversionFeedforward.java index a7628512af..b0f23a8dcc 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/controller/LinearPlantInversionFeedforward.java +++ b/wpimath/src/main/java/edu/wpi/first/math/controller/LinearPlantInversionFeedforward.java @@ -139,6 +139,9 @@ public class LinearPlantInversionFeedforward< * @return The calculated feedforward. */ public Matrix calculate(Matrix r, Matrix nextR) { + // rₖ₊₁ = Arₖ + Buₖ + // Buₖ = rₖ₊₁ − Arₖ + // uₖ = B⁺(rₖ₊₁ − Arₖ) m_uff = new Matrix<>(m_B.solve(nextR.minus(m_A.times(r)))); m_r = nextR; diff --git a/wpimath/src/main/native/include/frc/controller/ControlAffinePlantInversionFeedforward.h b/wpimath/src/main/native/include/frc/controller/ControlAffinePlantInversionFeedforward.h index ee21a24023..6306457655 100644 --- a/wpimath/src/main/native/include/frc/controller/ControlAffinePlantInversionFeedforward.h +++ b/wpimath/src/main/native/include/frc/controller/ControlAffinePlantInversionFeedforward.h @@ -166,6 +166,9 @@ class ControlAffinePlantInversionFeedforward { InputVector Calculate(const StateVector& r, const StateVector& nextR) { StateVector rDot = (nextR - r) / m_dt.value(); + // ṙ = f(r) + Bu + // Bu = ṙ − f(r) + // u = B⁺(ṙ − f(r)) m_uff = m_B.householderQr().solve(rDot - m_f(r, InputVector::Zero())); m_r = nextR; diff --git a/wpimath/src/main/native/include/frc/controller/LinearPlantInversionFeedforward.h b/wpimath/src/main/native/include/frc/controller/LinearPlantInversionFeedforward.h index e1f6b1be39..1d905e24ab 100644 --- a/wpimath/src/main/native/include/frc/controller/LinearPlantInversionFeedforward.h +++ b/wpimath/src/main/native/include/frc/controller/LinearPlantInversionFeedforward.h @@ -138,6 +138,9 @@ class LinearPlantInversionFeedforward { * @return The calculated feedforward. */ InputVector Calculate(const StateVector& r, const StateVector& nextR) { + // rₖ₊₁ = Arₖ + Buₖ + // Buₖ = rₖ₊₁ − Arₖ + // uₖ = B⁺(rₖ₊₁ − Arₖ) m_uff = m_B.householderQr().solve(nextR - (m_A * r)); m_r = nextR; return m_uff;