Skip to content

Commit

Permalink
[wpimath] Add lastValue() method to filters (#6351)
Browse files Browse the repository at this point in the history
  • Loading branch information
N0tACyb0rg authored Feb 10, 2024
1 parent e506e09 commit 3207795
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
7 changes: 7 additions & 0 deletions wpimath/src/main/native/include/frc/filter/LinearFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> m_inputs;
wpi::circular_buffer<T> m_outputs;
Expand Down
7 changes: 7 additions & 0 deletions wpimath/src/main/native/include/frc/filter/MedianFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
7 changes: 7 additions & 0 deletions wpimath/src/main/native/include/frc/filter/SlewRateLimiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 3207795

Please sign in to comment.