libstp
Robotics library for Botball
Loading...
Searching...
No Matches
IRSensor.hpp
Go to the documentation of this file.
1//
2// Created by eternalRose on 11/13/25.
3//
4
5#pragma once
6
7#ifdef SAFETY_CHECKS_ENABLED
8#include <set>
9#endif
10#include "hal/Analog.hpp"
11
20 {
21 public:
24 float whiteMean = 0.0f;
25 float blackMean = 0.0f;
26 float whiteStdDev = 1.0f;
27 float blackStdDev = 1.0f;
28
38 explicit IRSensor(const int& port);
39
41 [[nodiscard]] bool isCalibrated() const;
42
44 static float mean(const std::vector<float>& v);
45
47 static float stddev(const std::vector<float>& v);
48
50 static float variance(const std::vector<float>& v, float m);
51
53 bool calibrate(const std::vector<float>& values);
54
56 void setCalibration(float newBlackThreshold, float newWhiteThreshold);
57
59 bool isOnWhite() const;
60
62 virtual bool isOnBlack();
63
65 float probabilityOfBlack() const;
67 float probabilityOfWhite() const;
68
69 private:
71 bool calibrated = false;
72
74 void loadStoredCalibration();
75
77 void ensureCalibrated(const char* query) const;
78 };
79}
static float stddev(const std::vector< float > &v)
bool calibrate(const std::vector< float > &values)
void setCalibration(float newBlackThreshold, float newWhiteThreshold)
static float mean(const std::vector< float > &v)
static float variance(const std::vector< float > &v, float m)