|
Valkyrie 2026
|
Sensor for detecting changes in motor current. More...
#include <valkyrie/sensors/CurrentSensor.h>
Public Member Functions | |
| CurrentSensor (units::ampere_t threshold) | |
| Construct a new CurrentSensor object. | |
| void | Reset () override |
| Reset the sensor state. | |
| void | SetSpikeCallback (std::function< void()> cb) |
| Set a callback function to trigger when a current spike is detected. | |
| void | SetThreshold (units::ampere_t threshold) |
| Set the threshold for detecting a current spike. | |
| units::ampere_t | GetThreshold () const |
| void | SetFilterSize (int size) |
| Set the size of the rolling average cache. | |
| void | SetFilterTime (units::second_t time) |
| Set the time interval of the rolling average cache. | |
| Public Member Functions inherited from valor::sensors::BaseSensor< units::ampere_t > | |
| void | SetGetter (std::function< units::ampere_t()> _lambda) |
| Set the lambda function to fetch sensor data. | |
| void | ApplyPostProcessing (std::function< units::ampere_t(units::ampere_t)> func) |
| Set a post-processing function for sensor data. | |
| units::ampere_t | 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> | |
| 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> | |
| 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 current sensor-specific calculations. | |
| units::ampere_t | GetAverage () const |
| Get the average current from the rolling cache. | |
| void | LoggablePeriodic () override |
| Periodic callback for logging updates. | |
| Protected Member Functions inherited from valor::Loggable | |
| virtual void | OnLoggingStart () |
| Hook invoked when logging is started for this object. | |
Additional Inherited Members | |
| Static Public Member Functions inherited from valor::Loggable | |
| static units::millisecond_t | GetLoggingTime () |
| static constexpr Loggable & | GetRoot () |
| 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< units::ampere_t > | |
| std::function< units::ampere_t()> | sensorLambda |
| Lambda function to fetch sensor data. | |
| std::function< units::ampere_t(units::ampere_t)> | postProcessor |
| Lambda function to post-process sensor data. | |
| units::ampere_t | prevState |
| Previous and current sensor states. | |
| units::ampere_t | currState |
Sensor for detecting changes in motor current.
This class monitors the output current of a motor and uses a rolling average to detect spikes in current. It can trigger callbacks when a spike is detected.
|
explicit |
Construct a new CurrentSensor object.
| robot | Reference to the robot, used to schedule the calculate method. |
| threshold | The current threshold for the moving average |
|
overrideprotectedvirtual |
Perform current sensor-specific calculations.
This method is called every 10ms and processes the current data to detect spikes.
Reimplemented from valor::sensors::BaseSensorCore.
|
inlineprotected |
Get the average current from the rolling cache.
|
overrideprotectedvirtual |
Periodic callback for logging updates.
If a derived class needs to perform periodic updates to published values, override this method. It is intended to be called by the logging framework; this base class provides an empty implementation.
Reimplemented from valor::Loggable.
|
overridevirtual |
Reset the sensor state.
Clears the rolling average cache and resets the spike setpoint.
Reimplemented from valor::sensors::BaseSensor< units::ampere_t >.
| void valor::sensors::CurrentSensor::SetFilterSize | ( | int | size | ) |
Set the size of the rolling average cache.
| size | Number of data points to include in the rolling average. |
|
inline |
Set the time interval of the rolling average cache.
| time | Time interval of the rolling average |
|
inline |
Set a callback function to trigger when a current spike is detected.
| cb | Callback to execute on a current spike. |
| void valor::sensors::CurrentSensor::SetThreshold | ( | units::ampere_t | threshold | ) |
Set the threshold for detecting a current spike.
| threshold | Current value that triggers a spike. |