EEEN21000
GROUP 30 Line Following Buggy
Loading...
Searching...
No Matches
sensor.h
Go to the documentation of this file.
1#ifndef SENSOR_H
2#define SENSOR_H
3
4#include "debug1.h"
5#include "arm_math.h"
6#include "mbed.h"
7#include "helper.h"
8#include <algorithm>
9#include <array>
10#include <cstdio>
11
13#define PRESCALER 10.0f
15#define NO_TRACK 30
17#define WHITE_TRESHOLD 0.8
18
19#ifdef SENSORS_DEBUG
20#define _SENSORS_DEBUG 1
21#else
22#define _SENSORS_DEBUG 0
23#endif
24
30class Sensor {
31 private:
33 BusOut m_pins;
34
36 std::array<AnalogIn, 6> m_analog;
37
39 std::array<float, 6> m_reading{};
40
42 std::array<float, 6> m_noise{};
43
45 float m_distance{0};
46
49
50 public:
58 Sensor(PinName p1, PinName p2, PinName p3, PinName p4, PinName p5, PinName p6,
59 PinName in1, PinName in2, PinName in3, PinName in4, PinName in5, PinName in6);
60
62 static std::array<float, 6> WEIGHTS;
63
65 static std::array<float, 6> BLACK_TRESHOLD;
66
68 static std::array<float, 6> SCALE_FACTOR;
69
71 static bool s_run;
72
78 float read();
79
86 float getDistance() const;
87
93 int getNoTrackCounter() const;
94
100
106
107};
108
109#endif
Sensor class to handle the sensor readings.
Definition: sensor.h:30
float getDistance() const
Get the distance.
void calibrateWhite()
Calibrate the sensors on white area of the track.
static std::array< float, 6 > SCALE_FACTOR
Array of constant scale factor for sensors.
Definition: sensor.h:68
float read()
Read the sensor values.
int m_notrackcounter
No track counter.
Definition: sensor.h:48
static std::array< float, 6 > BLACK_TRESHOLD
Array of constant black threshold for sensors.
Definition: sensor.h:65
static std::array< float, 6 > WEIGHTS
Array of constant weights for sensors.
Definition: sensor.h:62
int getNoTrackCounter() const
Get the no track counter value.
BusOut m_pins
Array of sensors DigitalOut.
Definition: sensor.h:33
std::array< float, 6 > m_noise
Array of sensors noise.
Definition: sensor.h:42
float m_distance
Sensor position.
Definition: sensor.h:45
std::array< AnalogIn, 6 > m_analog
Array of sensors AnalogIn.
Definition: sensor.h:36
void calibrateBlack()
Calibrate the sensors on black area of the track.
std::array< float, 6 > m_reading
Array of sensors readings.
Definition: sensor.h:39
static bool s_run
Debugging flag for printing headers.
Definition: sensor.h:71
Sensor(PinName p1, PinName p2, PinName p3, PinName p4, PinName p5, PinName p6, PinName in1, PinName in2, PinName in3, PinName in4, PinName in5, PinName in6)
Constructor.