6#include <frc/TimedRobot.h>
7#include <frc/filter/LinearFilter.h>
9#include "valkyrie/sensors/BaseSensor.h"
51 inline units::ampere_t GetThreshold()
const {
return threshold; }
80 inline units::ampere_t
GetAverage()
const {
return filter.LastValue(); }
85 static constexpr int DEFAULT_CACHE_SIZE = 100_ms / LOOP_PERIOD;
87 frc::LinearFilter<units::ampere_t> filter = frc::LinearFilter<units::ampere_t>::MovingAverage(DEFAULT_CACHE_SIZE);
88 std::function<void()> callback;
89 units::ampere_t threshold;
Abstract class that all Valor sensors should implement.
Definition BaseSensor.h:52
void SetSpikeCallback(std::function< void()> cb)
Set a callback function to trigger when a current spike is detected.
Definition CurrentSensor.h:42
void SetFilterTime(units::second_t time)
Set the time interval of the rolling average cache.
Definition CurrentSensor.h:65
units::ampere_t GetAverage() const
Get the average current from the rolling cache.
Definition CurrentSensor.h:80
void SetThreshold(units::ampere_t threshold)
Set the threshold for detecting a current spike.
CurrentSensor(units::ampere_t threshold)
Construct a new CurrentSensor object.
void LoggablePeriodic() override
Periodic callback for logging updates.
void Calculate() override
Perform current sensor-specific calculations.
void Reset() override
Reset the sensor state.
void SetFilterSize(int size)
Set the size of the rolling average cache.