Valor 6800 1.0
Loading...
Searching...
No Matches
valor::DebounceSensor Class Reference

Sensor for debouncing and detecting rising/falling edges of boolean inputs. More...

#include <DebounceSensor.h>

Inheritance diagram for valor::DebounceSensor:
valor::BaseSensor< bool > valor::Loggable valor::LaserProximitySensor valor::CANrangeSensor valor::GrappleSensor

Public Member Functions

 DebounceSensor (frc::TimedRobot &robot)
 Construct a new DebounceSensor object.
 
void setEdgeCallback (std::function< void()> _lambda)
 Set a callback function for detecting any edge (rising or falling).
 
void setRisingEdgeCallback (std::function< void()> _lambda)
 Set a callback function for detecting a rising edge.
 
void setFallingEdgeCallback (std::function< void()> _lambda)
 Set a callback function for detecting a falling edge.
 
- Public Member Functions inherited from valor::BaseSensor< bool >
virtual void reset ()
 Reset the sensor state.
 
void setGetter (std::function< bool()> _lambda)
 Set the lambda function to fetch sensor data.
 
void applyPostProcessing (std::function< bool(bool)> func)
 Set a post-processing function for sensor data.
 
bool get ()
 Get the current sensor state.
 
- Public Member Functions inherited from valor::Loggable
void LogChild (std::string_view name, Loggable *child)
 Register a child Loggable under a named subtree.
 
void LogChild (std::string_view name, wpi::Sendable *child)
 Register a child Sendable under a named subtree.
 
void setLoggingPeriod (units::millisecond_t period)
 Set the minimum period between LoggablePeriodic() invocations.
 
template<>
decltype(Loggable::subscribers) ::iterator addSubscriber (std::string_view field, const std::vector< bool > &defaultValue)
 
template<>
void WriteLogImpl (nt::Publisher *pub, const std::vector< bool > &data)
 
template<>
std::vector< boolReadLogImpl (nt::Subscriber *sub)
 

Protected Member Functions

void calculate () override
 Perform debounce-specific calculations.
 
- Protected Member Functions inherited from valor::BaseSensor< bool >
 BaseSensor (frc::TimedRobot &robot)
 Construct a new BaseSensor object.
 
virtual void refresh ()
 Refresh the sensor state.
 
- Protected Member Functions inherited from valor::Loggable
 Loggable (std::string_view name)
 Construct a Loggable that registers a top-level table name.
 
 Loggable ()
 Default construct an uninitialized Loggable.
 
virtual ~Loggable ()=default
 Virtual destructor.
 
virtual void OnLoggingStart ()
 Hook invoked when logging is started for this object.
 
virtual void LoggablePeriodic ()
 Periodic callback for logging updates.
 
template<typename T >
T WriteLog (std::string_view field, const T &data)
 Publish a value to NetworkTables under the given field.
 
template<typename T >
ReadLog (std::string_view field, const T &defaultValue={})
 Read a value from NetworkTables for the given field.
 

Additional Inherited Members

- Static Public Member Functions inherited from valor::Loggable
static units::millisecond_t GetLoggingTime ()
 
- Protected Attributes inherited from valor::BaseSensor< bool >
std::function< bool()> sensorLambda
 Lambda function to fetch sensor data.
 
std::function< bool(bool)> postProcessor
 Lambda function to post-process sensor data.
 
bool prevState
 Previous and current sensor states.
 
bool currState
 
frc::Timer profiler
 

Detailed Description

Sensor for debouncing and detecting rising/falling edges of boolean inputs.

This class filters out noise in boolean inputs and detects edges (state changes).

  • A rising edge occurs when the input changes from false to true.
  • A falling edge occurs when the input changes from true to false.

Debouncing ensures that rapid state changes are treated as a single edge.

Constructor & Destructor Documentation

◆ DebounceSensor()

valor::DebounceSensor::DebounceSensor ( frc::TimedRobot & robot)
explicit

Construct a new DebounceSensor object.

Parameters
robotReference to the robot, used to schedule the calculate method.

Member Function Documentation

◆ calculate()

void valor::DebounceSensor::calculate ( )
overrideprotectedvirtual

Perform debounce-specific calculations.

This method is called every 10ms and processes the boolean input to detect edges.

Implements valor::BaseSensor< bool >.

Reimplemented in valor::LaserProximitySensor.

◆ setEdgeCallback()

void valor::DebounceSensor::setEdgeCallback ( std::function< void()> _lambda)

Set a callback function for detecting any edge (rising or falling).

Parameters
_lambdaLambda function to execute when an edge is detected.

◆ setFallingEdgeCallback()

void valor::DebounceSensor::setFallingEdgeCallback ( std::function< void()> _lambda)

Set a callback function for detecting a falling edge.

Parameters
_lambdaLambda function to execute when a falling edge is detected.

◆ setRisingEdgeCallback()

void valor::DebounceSensor::setRisingEdgeCallback ( std::function< void()> _lambda)

Set a callback function for detecting a rising edge.

Parameters
_lambdaLambda function to execute when a rising edge is detected.

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