-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSensorArray.h
More file actions
110 lines (91 loc) · 2.23 KB
/
Copy pathSensorArray.h
File metadata and controls
110 lines (91 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
--FILE--
SensorArray.h
--AUTHOR--
Name: Josh Alan
GitHub: theDataSmith
E-mail: thedatasmith1@gmail.com
--PROJECT--
Euclid, the line-following robot.
GitHub: github.com/theDataSmith/euclid
--CREATION DATE--
11 / 22 / 2016
*/
#pragma once
#include "ReflectanceSensor.h"
#include <Arduino.h>
#include <vector>
using namespace std;
namespace EuclidRobot
{
class SensorArray
{
public:
/*
The number of microseconds it takes for each sensor to go from HIGH to LOW on a white surface.
These values were measured and manually entered.
*/
const int MICROS_WHITE[6] = {
90, 70, 80, 100, 60, 90
};
/*
The number of microseconds it takes for each sensor to go from HIGH to LOW on a white surface.
These values were measured and manually entered.
*/
const int MICROS_BLACK[6] =
{
500, 600, 800, 850, 480, 750
};
/*
If the total reflectance is below this value, the line is not detected.
*/
const float MIN_TOTAL_REFLECTANCE = 0.2f;
/*
Initializes the positionalFactors and the sensors vector.
*/
SensorArray(int nSensors, const int pins[]);
/*
Deletes the positionalFactors and each sensor, and clears the sensors vector.
*/
~SensorArray();
/*
Returns a value between -1 and 1.
-1: The line is far left.
0: The line is dead center.
1: The line is far right.
If the bot loses the line, the most recently found
center is used to guess where the line is.
*/
float readLineCenter();
/*
Returns an array of values between 0 and 1, one for each sensor.
0: Completely white.
1: Completely black.
*/
float* readReflectances();
/*
Returns an array of longs.
Each one represents the number of microseconds it took for that sensor to go from HIGH to LOW.
*/
long* readMicros();
private:
/*
The number of sensors in the array.
*/
int nSensors;
/*
An array of values, one for each sensor.
Each value represents the position of that sensor, evenly spaced between -1 and 1.
*/
float* positionalFactors;
/*
An array of pointers to the sensor objects in the SensorArray.
*/
vector<ReflectanceSensor*> sensors = vector<ReflectanceSensor*>();
/*
The most recently found line center.
Used in case the array loses the line.
*/
float lastCenter = 0;
};
}