WPILibC++ 2026.2.1
Loading...
Searching...
No Matches
frc::EdgeCounterFilter Class Reference

A rising edge counter for boolean streams. More...

#include <frc/filter/EdgeCountFilter.h>

Public Member Functions

 EdgeCounterFilter (int requiredEdges, units::second_t windowTime)
 Creates a new EdgeCounterFilter.
 
bool Calculate (bool input)
 Applies the edge counter filter to the input stream.
 
constexpr void SetWindowTime (units::second_t windowTime)
 Sets the time window duration.
 
constexpr units::second_t GetWindowTime () const
 Gets the time window duration.
 
constexpr void SetRequiredEdges (int requiredEdges)
 Sets the required number of edges.
 
constexpr int GetRequiredEdges () const
 Gets the required number of edges.
 

Detailed Description

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 & Destructor Documentation

◆ EdgeCounterFilter()

frc::EdgeCounterFilter::EdgeCounterFilter ( int requiredEdges,
units::second_t windowTime )
explicit

Creates a new EdgeCounterFilter.

Parameters
requiredEdgesThe number of rising edges required before the output goes true.
windowTimeThe maximum time window in which all required edges must occur after the first rising edge.

Member Function Documentation

◆ Calculate()

bool frc::EdgeCounterFilter::Calculate ( bool input)

Applies the edge counter filter to the input stream.

Parameters
inputThe 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.

◆ GetRequiredEdges()

int frc::EdgeCounterFilter::GetRequiredEdges ( ) const
inlineconstexpr

Gets the required number of edges.

Returns
The number of rising edges required before the output goes true.

◆ GetWindowTime()

units::second_t frc::EdgeCounterFilter::GetWindowTime ( ) const
inlineconstexpr

Gets the time window duration.

Returns
The maximum time window in which all required edges must occur after the first rising edge.

◆ SetRequiredEdges()

void frc::EdgeCounterFilter::SetRequiredEdges ( int requiredEdges)
inlineconstexpr

Sets the required number of edges.

Parameters
requiredEdgesThe number of rising edges required before the output goes true.

◆ SetWindowTime()

void frc::EdgeCounterFilter::SetWindowTime ( units::second_t windowTime)
inlineconstexpr

Sets the time window duration.

Parameters
windowTimeThe maximum time window in which all required edges must occur after the first rising edge.

The documentation for this class was generated from the following file: