-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilities.cpp
More file actions
76 lines (65 loc) · 2.08 KB
/
Copy pathUtilities.cpp
File metadata and controls
76 lines (65 loc) · 2.08 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
#include "Utilities.h"
#include "SensorHelper.h"
CoordSet calcCenterBetweenMeasurementPoints(CoordSet setA, CoordSet setB){
bool measurementOnX = false;
bool measurementOnY = false;
CoordSet centerBetweenPoints;
centerBetweenPoints.x = 0;
centerBetweenPoints.y = 0;
// Find what axis the measurement is on
// When setA is higher then setB
if(setA.x >= setB.x){
// Check if the X is the measurement or position diferrence
if(setA.x - setB.x >= MAX_DISTANCE_BETWEEN_MEASUREMENTS)
measurementOnX = true;
else measurementOnY = true;
}
// When setB is higher then setA
if(setB.x >= setA.x){
// Check if the X is the measurement or position diferrence
if(setB.x - setA.x >= MAX_DISTANCE_BETWEEN_MEASUREMENTS)
measurementOnX = true;
else measurementOnY = true;
}
// Only fill the CoordSet with the center between position difference
if(measurementOnX){
if(setA.y > setB.y)
centerBetweenPoints.y = setA.y + ((setA.y - setB.y) / 2);
if(setB.y > setA.y)
centerBetweenPoints.y = setB.y + ((setB.y - setA.y) / 2);
}
if(measurementOnY){
if(setA.x > setB.x)
centerBetweenPoints.x = setA.x + ((setA.x - setB.x) / 2);
if(setB.x > setA.x)
centerBetweenPoints.x = setB.x + ((setB.x - setA.x) / 2);
}
return centerBetweenPoints;
}
CoordSet calcCenterBetweenPoints(CoordSet setA, CoordSet setB){
bool constantOnX = false;
bool constantOnY = false;
CoordSet centerBetweenPoints;
centerBetweenPoints.x = 0;
centerBetweenPoints.y = 0;
// Find the constant axis
if(setA.x >= (setB.x - MAX_SIDEWAYS_DEVIATION) || setA.x <= (setB.x + MAX_SIDEWAYS_DEVIATION))
constantOnX = true;
else constantOnY = true;
if(constantOnX){
if(setA.y > setB.y)
centerBetweenPoints.y = setA.y + ((setA.y - setB.y) / 2);
if(setB.y > setA.y)
centerBetweenPoints.y = setB.y + ((setB.y - setA.y) / 2);
}
if(constantOnY){
if(setA.x > setB.x)
centerBetweenPoints.x = setA.x + ((setA.x - setB.x) / 2);
if(setB.x > setA.x)
centerBetweenPoints.x = setB.x + ((setB.x - setA.x) / 2);
}
}
float pingCm(int pin){
float microSec = ping(pin);
return (SPEED_OF_SOUND_MODIFIER * microSec) / 2;
}