Valkyrie 2026
Loading...
Searching...
No Matches
valor::sensors::DebounceSensor Class Reference

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

#include <valkyrie/sensors/DebounceSensor.h>

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

Public Member Functions

 DebounceSensor ()
 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::sensors::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 () const
 Get the current sensor state.
void Refresh () override
 Refresh the sensor state.
Public Member Functions inherited from valor::Loggable
 Loggable (std::string_view name)
 Construct a Loggable that registers a top-level table name.
 Loggable (std::shared_ptr< nt::NetworkTable > table)
 Construct a Loggable that uses an existing NetworkTable.
 Loggable ()
 Default construct an uninitialized 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 SetPeriodicLevel (LogLevel level)
 Set the logging level for LoggablePeriodic.
template<typename T>
WriteLog (std::string_view field, const T &data, LogLevel level=LogLevel::Normal)
 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.
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< bool > ReadLogImpl (nt::Subscriber *sub)

Protected Member Functions

void Calculate () override
 Perform debounce-specific calculations.
Protected Member Functions inherited from valor::Loggable
virtual void OnLoggingStart ()
 Hook invoked when logging is started for this object.
virtual void LoggablePeriodic ()
 Periodic callback for logging updates.

Additional Inherited Members

Static Public Member Functions inherited from valor::Loggable
static units::millisecond_t GetLoggingTime ()
static constexpr LoggableGetRoot ()
Static Public Attributes inherited from valor::sensors::BaseSensorCore
static constexpr units::millisecond_t LOOP_PERIOD = frc::TimedRobot::kDefaultPeriod / 2
Protected Attributes inherited from valor::sensors::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

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::sensors::DebounceSensor::DebounceSensor ( )

Construct a new DebounceSensor object.

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

Member Function Documentation

◆ Calculate()

void valor::sensors::DebounceSensor::Calculate ( )
overrideprotectedvirtual

Perform debounce-specific calculations.

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

Reimplemented from valor::sensors::BaseSensorCore.

Reimplemented in valor::sensors::LaserProximitySensor.

◆ SetEdgeCallback()

void valor::sensors::DebounceSensor::SetEdgeCallback ( std::function< void()> lambda)
inline

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

Parameters
_lambdaLambda function to execute when an edge is detected.

◆ SetFallingEdgeCallback()

void valor::sensors::DebounceSensor::SetFallingEdgeCallback ( std::function< void()> lambda)
inline

Set a callback function for detecting a falling edge.

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

◆ SetRisingEdgeCallback()

void valor::sensors::DebounceSensor::SetRisingEdgeCallback ( std::function< void()> lambda)
inline

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: