Package edu.wpi.first.math.filter
Class EdgeCounterFilter
java.lang.Object
edu.wpi.first.math.filter.EdgeCounterFilter
A rising edge counter for boolean streams. Requires that the boolean change value to true for a
specified number of times within a specified time window after the first rising edge before the
filtered value changes.
The filter activates when the input has risen (transitioned from false to true) the required number of times within the time window. Once activated, the output remains true as long as the input is true. The edge count resets when the time window expires or when the input goes false after activation.
Input must be stable; consider using a Debouncer before this filter to avoid counting noise as multiple edges.
-
Constructor Summary
ConstructorsConstructorDescriptionEdgeCounterFilter(int requiredEdges, double windowTime) Creates a new EdgeCounterFilter. -
Method Summary
Modifier and TypeMethodDescriptionbooleancalculate(boolean input) Applies the edge counter filter to the input stream.intGets the required number of edges.doubleGets the time window duration.voidsetRequiredEdges(int requiredEdges) Sets the required number of edges.voidsetWindowTime(double windowTime) Sets the time window duration.
-
Constructor Details
-
EdgeCounterFilter
Creates a new EdgeCounterFilter.- Parameters:
requiredEdges- The number of rising edges required before the output goes true.windowTime- The maximum number of seconds in which all required edges must occur after the first rising edge.
-
-
Method Details
-
calculate
Applies the edge counter filter to the input stream.- Parameters:
input- The current value of the input stream.- Returns:
- True if the required number of edges have occurred within the time window and the input is currently true; false otherwise.
-
setWindowTime
Sets the time window duration.- Parameters:
windowTime- The maximum window of seconds in which all required edges must occur after the first rising edge.
-
getWindowTime
Gets the time window duration.- Returns:
- The maximum window of seconds in which all required edges must occur after the first rising edge.
-
setRequiredEdges
Sets the required number of edges.- Parameters:
requiredEdges- The number of rising edges required before the output goes true.
-
getRequiredEdges
Gets the required number of edges.- Returns:
- The number of rising edges required before the output goes true.
-