Valor 6800 1.0
Loading...
Searching...
No Matches
CurrentSensor.h
1
2#pragma once
3
4#include <deque>
5#include <string>
6
7#include <frc/TimedRobot.h>
8
9#include "valkyrie/sensors/BaseSensor.h"
10
11namespace valor {
12
19class CurrentSensor : public BaseSensor<double> {
20 public:
26 explicit CurrentSensor(frc::TimedRobot& robot);
27
33 void reset() override;
34
40 void setSpikeCallback(std::function<void()> _lambda);
41
48
55
56 protected:
57 CurrentSensor() = default;
58
64 void calculate() override;
65
71 double getAverage();
72
73 private:
74 static constexpr int DEFAULT_CACHE_SIZE = 20 / 20.0;
75 static constexpr double DEFAULT_SPIKE_VALUE = 22;
76
77 std::function<void()> spikeCallback;
78 std::deque<double> cache;
79 double spikedSetpoint{DEFAULT_SPIKE_VALUE};
80 int cacheSize{DEFAULT_CACHE_SIZE};
81};
82
83} // namespace valor
Abstract class that all Valor sensors should implement.
Definition BaseSensor.h:27
Sensor for detecting changes in motor current.
Definition CurrentSensor.h:19
void reset() override
Reset the sensor state.
void calculate() override
Perform current sensor-specific calculations.
void setSpikeCallback(std::function< void()> _lambda)
Set a callback function to trigger when a current spike is detected.
CurrentSensor(frc::TimedRobot &robot)
Construct a new CurrentSensor object.
void setSpikeSetpoint(double _setpoint)
Set the threshold for detecting a current spike.
double getAverage()
Get the average current from the rolling cache.
void setCacheSize(int _size)
Set the size of the rolling average cache.
T ReadLog(std::string_view field, const T &defaultValue={})
Read a value from NetworkTables for the given field.
Definition Loggable.h:343