diff --git a/wpimath/src/main/java/edu/wpi/first/math/filter/LinearFilter.java b/wpimath/src/main/java/edu/wpi/first/math/filter/LinearFilter.java index c26270fa494..850b7f2f75c 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/filter/LinearFilter.java +++ b/wpimath/src/main/java/edu/wpi/first/math/filter/LinearFilter.java @@ -313,6 +313,15 @@ public double calculate(double input) { return retVal; } + /** + * Returns the last value calculated by the LinearFilter. + * + * @return The last value. + */ + public double lastValue() { + return m_outputs.getFirst(); + } + /** * Factorial of n. * diff --git a/wpimath/src/main/java/edu/wpi/first/math/filter/MedianFilter.java b/wpimath/src/main/java/edu/wpi/first/math/filter/MedianFilter.java index 13c4e104373..d1d67b5b524 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/filter/MedianFilter.java +++ b/wpimath/src/main/java/edu/wpi/first/math/filter/MedianFilter.java @@ -72,6 +72,15 @@ public double calculate(double next) { } } + /** + * Returns the last value calculated by the MedianFilter. + * + * @return The last value. + */ + public double lastValue() { + return m_valueBuffer.getFirst(); + } + /** Resets the filter, clearing the window of all elements. */ public void reset() { m_orderedValues.clear(); diff --git a/wpimath/src/main/java/edu/wpi/first/math/filter/SlewRateLimiter.java b/wpimath/src/main/java/edu/wpi/first/math/filter/SlewRateLimiter.java index 6c34f35bc08..d9eca58419a 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/filter/SlewRateLimiter.java +++ b/wpimath/src/main/java/edu/wpi/first/math/filter/SlewRateLimiter.java @@ -64,6 +64,15 @@ public double calculate(double input) { return m_prevVal; } + /** + * Returns the value last calculated by the SlewRateLimiter. + * + * @return The last value. + */ + public double lastValue() { + return m_prevVal; + } + /** * Resets the slew rate limiter to the specified value; ignores the rate limit when doing so. * diff --git a/wpimath/src/main/native/include/frc/filter/LinearFilter.h b/wpimath/src/main/native/include/frc/filter/LinearFilter.h index 051a6ddd268..3bc5465a3d2 100644 --- a/wpimath/src/main/native/include/frc/filter/LinearFilter.h +++ b/wpimath/src/main/native/include/frc/filter/LinearFilter.h @@ -371,6 +371,13 @@ class LinearFilter { return retVal; } + /** + * Returns the last value calculated by the LinearFilter. + * + * @return The last value. + */ + T LastValue() const { return m_outputs.front(); } + private: wpi::circular_buffer m_inputs; wpi::circular_buffer m_outputs; diff --git a/wpimath/src/main/native/include/frc/filter/MedianFilter.h b/wpimath/src/main/native/include/frc/filter/MedianFilter.h index 40422a6d24a..4c714fb547e 100644 --- a/wpimath/src/main/native/include/frc/filter/MedianFilter.h +++ b/wpimath/src/main/native/include/frc/filter/MedianFilter.h @@ -61,6 +61,13 @@ class MedianFilter { } } + /** + * Returns the last value calculated by the MedianFilter. + * + * @return The last value. + */ + T LastValue() const { return m_valueBuffer.front(); } + /** * Resets the filter, clearing the window of all elements. */ diff --git a/wpimath/src/main/native/include/frc/filter/SlewRateLimiter.h b/wpimath/src/main/native/include/frc/filter/SlewRateLimiter.h index 9f7c6744b97..ceba4ca2bc7 100644 --- a/wpimath/src/main/native/include/frc/filter/SlewRateLimiter.h +++ b/wpimath/src/main/native/include/frc/filter/SlewRateLimiter.h @@ -75,6 +75,13 @@ class SlewRateLimiter { return m_prevVal; } + /** + * Returns the value last calculated by the SlewRateLimiter. + * + * @return The last value. + */ + Unit_t LastValue() const { return m_prevVal; } + /** * Resets the slew rate limiter to the specified value; ignores the rate limit * when doing so.