Valkyrie 2026
Loading...
Searching...
No Matches
valor::sensors::BaseSensor< T > Class Template Reference

Abstract class that all Valor sensors should implement. More...

#include <valkyrie/sensors/BaseSensor.h>

Inheritance diagram for valor::sensors::BaseSensor< T >:
valor::sensors::BaseSensorCore valor::Loggable

Public Member Functions

virtual void Reset ()
 Reset the sensor state.
void SetGetter (std::function< T()> _lambda)
 Set the lambda function to fetch sensor data.
void ApplyPostProcessing (std::function< T(T)> func)
 Set a post-processing function for sensor data.
Get () const
 Get the current sensor state.
void Refresh () override
 Refresh the sensor state.
Public Member Functions inherited from valor::sensors::BaseSensorCore
virtual void Calculate ()
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 Attributes

std::function< T()> sensorLambda
 Lambda function to fetch sensor data.
std::function< T(T)> postProcessor
 Lambda function to post-process sensor data.
prevState
 Previous and current sensor states.
currState

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

Detailed Description

template<class T>
class valor::sensors::BaseSensor< T >

Abstract class that all Valor sensors should implement.

Template Parameters
TSensor data type.

This class provides a framework for managing sensors on the robot. It abstracts repetitive code and organizes sensor logic. The calculate method, which runs every 10ms, is the core of this class and is automatically scheduled.

Sensors are not directly owned by this class. Instead, a lambda function is passed to fetch sensor data, allowing flexibility for different sensor types.

Member Function Documentation

◆ ApplyPostProcessing()

template<class T>
void valor::sensors::BaseSensor< T >::ApplyPostProcessing ( std::function< T(T)> func)
inline

Set a post-processing function for sensor data.

This function is applied to the sensor data after it is fetched. It can be used to modify or process the data before it is stored.

Parameters
funcLambda function for post-processing sensor data.

◆ Get()

template<class T>
T valor::sensors::BaseSensor< T >::Get ( ) const
inline

Get the current sensor state.

Returns the most recent sensor data fetched by the lambda function. If no lambda function is set, it returns the default value of the sensor type.

Returns
T Current sensor state.

◆ Refresh()

template<class T>
void valor::sensors::BaseSensor< T >::Refresh ( )
inlineoverridevirtual

Refresh the sensor state.

Updates prevState and currState by fetching new data using the lambda function. If a post-processing function is set, it is applied to the fetched data.

Implements valor::sensors::BaseSensorCore.

Reimplemented in valor::sensors::LaserProximitySensor.

◆ Reset()

template<class T>
virtual void valor::sensors::BaseSensor< T >::Reset ( )
inlinevirtual

Reset the sensor state.

Clears member variables and sets default values for prevState and currState. This method can be implemented in derived classes and should also be called in their constructors.

Reimplemented in valor::Gamepad::AnalogValue, valor::sensors::CANdleSensor, valor::sensors::CurrentSensor, and valor::sensors::LaserProximitySensor.

◆ SetGetter()

template<class T>
void valor::sensors::BaseSensor< T >::SetGetter ( std::function< T()> _lambda)
inline

Set the lambda function to fetch sensor data.

This function allows developers to specify how sensor data is obtained. The lambda function is called every 10ms to fetch the latest sensor data.

Parameters
_lambdaLambda function to fetch sensor data.

Member Data Documentation

◆ postProcessor

template<class T>
std::function<T(T)> valor::sensors::BaseSensor< T >::postProcessor
protected

Lambda function to post-process sensor data.

This function is applied to the sensor data after it is fetched.

◆ prevState

template<class T>
T valor::sensors::BaseSensor< T >::prevState
protected

Previous and current sensor states.

prevState holds the last sensor state, while currState holds the current sensor state fetched by the lambda function.

◆ sensorLambda

template<class T>
std::function<T()> valor::sensors::BaseSensor< T >::sensorLambda
protected

Lambda function to fetch sensor data.

This function is called every 10ms to fetch the latest sensor data.


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