2025-11-20 12:26:54 -06:00
|
|
|
#ifndef IND_SENSOR_MAP_HPP
|
|
|
|
|
#define IND_SENSOR_MAP_HPP
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
// Inductive Sensor Mapping Struct
|
|
|
|
|
typedef struct IndSensorMap {
|
|
|
|
|
float A;
|
|
|
|
|
float K;
|
|
|
|
|
float B;
|
|
|
|
|
float C;
|
|
|
|
|
float v;
|
2025-11-22 15:16:16 -06:00
|
|
|
|
|
|
|
|
// Pre-computed constants for faster toMM()
|
|
|
|
|
float invB; // 1.0 / B
|
|
|
|
|
float K_minus_A; // K - A
|
2025-11-20 12:26:54 -06:00
|
|
|
} IndSensorMap;
|
|
|
|
|
|
|
|
|
|
class IndSensor {
|
|
|
|
|
public:
|
|
|
|
|
bool oor;
|
|
|
|
|
float mmVal;
|
2025-11-20 16:16:34 -06:00
|
|
|
uint16_t analog;
|
2025-11-20 17:13:46 -06:00
|
|
|
float alpha; // EMA smoothing factor: 0-1, lower = more smoothing
|
2025-11-20 12:26:54 -06:00
|
|
|
|
|
|
|
|
// Constructor
|
2025-11-20 17:13:46 -06:00
|
|
|
IndSensor(IndSensorMap calibration, uint8_t analogPin, float emaAlpha = 0.3f);
|
2025-11-20 12:26:54 -06:00
|
|
|
// Read sensor directly from pin and convert to millimeters
|
|
|
|
|
float readMM();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
IndSensorMap consts;
|
|
|
|
|
uint8_t pin;
|
2025-11-20 17:13:46 -06:00
|
|
|
float filteredRaw;
|
2025-11-20 12:26:54 -06:00
|
|
|
|
|
|
|
|
// helper function to convert analog reading to millimeters
|
2025-11-20 16:16:34 -06:00
|
|
|
float toMM(uint16_t raw);
|
2025-11-20 12:26:54 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// sensor instances
|
|
|
|
|
extern IndSensor indL;
|
|
|
|
|
extern IndSensor indR;
|
|
|
|
|
extern IndSensor indF;
|
|
|
|
|
extern IndSensor indB;
|
|
|
|
|
|
|
|
|
|
#endif // IND_SENSOR_MAP_HPP
|