Skip to content

Commit

Permalink
[wpimath] LinearFilter lastValue(): Fix runtime exception (#6713)
Browse files Browse the repository at this point in the history
  • Loading branch information
Braykoff authored Jun 8, 2024
1 parent 1c884b2 commit 0606da6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class LinearFilter {
private final DoubleCircularBuffer m_outputs;
private final double[] m_inputGains;
private final double[] m_outputGains;
private double m_lastOutput;

private static int instances;

Expand Down Expand Up @@ -310,6 +311,7 @@ public double calculate(double input) {
m_outputs.addFirst(retVal);
}

m_lastOutput = retVal;
return retVal;
}

Expand All @@ -319,7 +321,7 @@ public double calculate(double input) {
* @return The last value.
*/
public double lastValue() {
return m_outputs.getFirst();
return m_lastOutput;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion wpimath/src/main/native/include/frc/filter/LinearFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ class LinearFilter {
m_outputs.push_front(retVal);
}

m_lastOutput = retVal;
return retVal;
}

Expand All @@ -375,13 +376,14 @@ class LinearFilter {
*
* @return The last value.
*/
T LastValue() const { return m_outputs.front(); }
T LastValue() const { return m_lastOutput; }

private:
wpi::circular_buffer<T> m_inputs;
wpi::circular_buffer<T> m_outputs;
std::vector<double> m_inputGains;
std::vector<double> m_outputGains;
T m_lastOutput{0.0};

/**
* Factorial of n.
Expand Down

0 comments on commit 0606da6

Please sign in to comment.