-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIMU_IR_Data_Logger.py
183 lines (163 loc) · 6.15 KB
/
IMU_IR_Data_Logger.py
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#Used to collect raw data from know distances and output them to a CSV for future analysis
#Does this for both IR Sensors and the IMU, just call the correct function to do with distances
#As either a magnitude or in component form
import sensors
import time
ir_spacing = 9.5 # cm
sensors.initSensors()
def baseOnDistanceIR(): #Magnitude
#initialization
distLeft = 0
distRight = 0
leftDists = []
rightDists = []
leftData = []
rightData = []
entries = 0
#Collects Data
while(distLeft != -1):
distLeft = float(input("please enter the distance away from the hazard the left IR sensor is or enter -1 to end: "))
if(distLeft != -1):
distRight = float(input("please enter the distance away from the hazard the Right IR sensor is: "))
leftDists.append(distLeft)
rightDists.append(distRight)
sensors.updateSensors()
leftData.append(sensors.getIRLevelLeft())
rightData.append(sensors.getIRLevelRight())
entries = entries + 1
#output to CSV
data = open("IR_Distance_Magnitude_Data.csv", "w")
data.write("Left IR Distance,")
data.write("Left IR Reading,")
data.write("Right IR Distance,")
data.write("Right IR Reading")
i = 0
while (i < entries):
data.write("%.1f cm," %leftDists[i])
data.write("%.3f ," %leftData[i])
data.write("%.1f cm," %rightDists[i])
data.write("%.3f \n" %rightData[i])
i = i + 1
def baseOnDistanceComponentsIR(): #Components
#initialization
distLeftX = 0
distLeftY = 0
distRightX = 0
distRightY = 0
leftDistsX = []
leftDistsY = []
rightDistsX = []
rightDistsY = []
leftData = []
rightData = []
entries = 0
#Collects Data
while(distLeftX != -1):
distLeftX = float(input("please enter the X (horizontal, robot left = +) component distance away from the hazard the left IR sensor is or enter -1 to end: "))
if(distLeftX != -1):
distLeftY = float(input("please enter the Y component distance away from the hazard the left IR sensor is or enter -1 to end: "))
distRightX = distLeftX - ir_spacing # input("please enter the X component distance away from the hazard the Right IR sensor is: ")
distRightY = distLeftY # input("please enter the Y component distance away from the hazard the Right IR sensor is: ")
leftDistsX.append(distLeftX)
leftDistsY.append(distLeftY)
rightDistsX.append(distRightX)
rightDistsY.append(distRightY)
sensors.updateSensors()
leftData.append(sensors.getIRLevelLeft())
rightData.append(sensors.getIRLevelRight())
entries = entries + 1
#output to CSV
data = open("IR_Distance_Component_Data.csv", "w")
data.write("Left IR Distance (X),")
data.write("Left IR Distance (Y),")
data.write("Left IR Reading,")
data.write("Right IR Distance (X),")
data.write("Right IR Distance (Y),")
data.write("Right IR Reading\n")
i = 0
while (i < entries):
data.write("%.1f cm," %leftDistsX[i])
data.write("%.1f cm," %leftDistsY[i])
data.write("%.3f ," %leftData[i])
data.write("%.1f cm," %rightDistsX[i])
data.write("%.1f cm," %rightDistsY[i])
data.write("%.3f \n" %rightData[i])
i = i + 1
def baseOnDistanceIMU(): #Magnitude
#initialization
distMag = 0
magDataX = [] #x component reading
magDataY = [] #y component reaing
magDataMag = [] #magnitude reading
dists = []
entries = 0
#Collects Data
while(distMag != -1):
distMag = float(input("please enter the distance away from the hazard the IMU is or enter -1 to end: "))
if(distMag != -1):
dists.append(distMag)
sensors.updateSensors()
x, y, z = sensors.getMagneticLevel() #x, y, amd z component magnetic Readings
magDataX.append(x)
magDataY.append(y)
entries = entries + 1
#output to CSV
data = open("IMU_Distance_Magnitude_Data.csv", "w")
data.write("IMU distance,")
data.write("x comp Mag reading,")
data.write("y comp Mag reading,")
data.write("Magnitude Mag reading\n")
i = 0
while (i < entries):
data.write("%.1f cm," %dists[i])
data.write("%.3f ," %magDataX[i])
data.write("%.3f ," %magDataY[i])
data.write("%.3f \n" %magDataMag[i])
i = i + 1
def baseOnDistanceComponentsIMU(): #Magnitude
#initialization
distX = 0
distY = 0
magDataX = [] #x component reading
magDataY = [] #y component reaing
magDataZ = [] #z component reaing
magDataMag = [] #magnitude reading
distsX = []
distsY = []
entries = 0
#collects data
while(distX != -1):
distX = float(input("please enter the X (horizontal, robot left = +) component distance away from the hazard the IMU is or enter -1 to end: "))
if(distX != -1):
distY = float(input("please enter the Y component distance away from the hazard the IMU is or enter -1 to end: "))
distsX.append(distX)
distsY.append(distY)
sensors.updateSensors()
x, y, z = sensors.getMagneticLevel() #x, y, amd z component magnetic Readings
magDataX.append(x)
magDataY.append(y)
magDataZ.append(z)
magDataMag.append(sensors.getMagneticMagnitude())
entries = entries + 1
#outputs to CSV
data = open("IMU_Distance_Component_Data.csv", "w")
data.write("IMU distance (X),")
data.write("IMU distance (Y),")
data.write("x comp Mag reading,")
data.write("y comp Mag reading,")
data.write("z comp Mag reading,")
data.write("Magnitude Mag reading \n")
i = 0
while (i < entries):
data.write("%.1f cm," %distsX[i])
data.write("%.1f cm," %distsY[i])
data.write("%.3f ," %magDataX[i])
data.write("%.3f ," %magDataY[i])
data.write("%.3f ," %magDataZ[i])
data.write("%.3f \n" %magDataMag[i])
i = i + 1
#Call any of the 4
#baseOnDistanceIR()
#baseOnDistanceComponentsIR()
#baseOnDistanceIMU()
baseOnDistanceComponentsIMU()