-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtestprocessor.py
More file actions
240 lines (213 loc) · 8.62 KB
/
testprocessor.py
File metadata and controls
240 lines (213 loc) · 8.62 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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
from __future__ import division
from termcolor import colored
class TestProcessor():
def __init__(self):
self.fullStep = []
self.halfStep = []
self.quarterStep = []
self.sixteenthStep = []
self.vrefs = []
self.supplys = []
self.supplyVoltages = []
self.mosfetHigh = []
self.mosfetLow = []
self.endstopHigh = []
self.endstopLow = []
self.thermistors = []
self.errors = ""
self.failedAxes = [False,False,False,False,False]
self.failedMosfets = [False,False,False,False,False,False]
self.failedEndstops = [False,False,False,False,False,False]
self.axisNames = ["X","Y","Z","E0","E1"]
self.thermistorNames = ["T0","T1","T2","T3"]
self.supplyNames = ["Extruder rail","Bed rail", "5V rail"]
self.mosfetNames = ["Bed","Fan2","Fan1","Heat1","Fan0","Heat0"]
self.endstopNames = ["X min", "Y min", "Z min", "X max", "Y max", "Z max"]
def testVrefs(self):
passed = True
if self._wasTimedOut(self.vrefs):
print "...Timed out at vref test"
return False
for idx, val in enumerate(self.vrefs):
if not 166 <= val <= 195:
self.errors += self.axisNames[idx] + " axis vref incorrect\n"
passed &= False
if max(self.vrefs) - min(self.vrefs) >= 15:
self.errors += "Vref variance too high!\n"
passed &= False
return passed
def testSupplys(self):
passed = True
if self._wasTimedOut(self.supplys):
print "...Timed out at supply test"
return False
for i in [0,1]:
if 11.5 <= self.supplyVoltages[i] <= 12.5:
pass
else:
self.errors += "Test " + self.supplyNames[i] + " supply\n"
passed &= False
if 4.7 <= self.supplyVoltages[2] <= 5.2:
pass
else:
self.errors += "Test " + self.supplyNames[2] + " supply\n"
passed &= False
return passed
def testThermistors(self):
passed = True
if self._wasTimedOut(self.thermistors):
print "...Timed out at thermistor test"
return False
for idx, val in enumerate(self.thermistors):
if not 967 <= val <= 985:
self.errors += "Check Thermistor " + self.thermistorNames[idx] + "\n"
passed = False
return passed
def testMosfetLow(self):
passed = True
if self._wasTimedOut(self.mosfetLow):
print "...Timed out at MOSFET low test"
return False
for idx, val in enumerate(self.mosfetLow):
if not val == 1 and not self.failedMosfets[idx]:
self.errors += "Check " + self.mosfetNames[idx] + " MOSFET\n"
self.failedMosfets[idx] = True
passed = False
return passed
def testMosfetHigh(self):
passed = True
if self._wasTimedOut(self.mosfetHigh):
print "...Timed out at MOSFET high test"
return False
for idx, val in enumerate(self.mosfetHigh):
if not val == 0 and not self.failedMosfets[idx]:
self.errors += "Check " + self.mosfetNames[idx] + " MOSFET\n"
self.failedMosfets[idx] = True
passed = False
return passed
def testEndstopHigh(self):
passed = True
if self._wasTimedOut(self.endstopHigh):
print "...Timed out at endstop high test"
return False
for idx, val in enumerate(self.endstopHigh):
if not val == 1 and not self.failedEndstops[idx]:
self.errors += "Check " + self.endstopNames[idx] + " endstop\n"
self.failedEndstops[idx] = True
passed = False
return passed
def testEndstopLow(self):
passed = True
if self._wasTimedOut(self.endstopLow):
print "...Timed out at endstop low test"
return False
for idx, val in enumerate(self.endstopLow):
if not val == 0 and not self.failedEndstops[idx]:
self.errors += "Check " + self.endstopNames[idx] + " endstop\n"
self.failedEndstops[idx] = True
passed = False
return passed
def testStepperResults(self, vals):
passed = True
if self._wasTimedOut(vals):
print "...Timed out at stepper test"
return False
for i in range(5): #Iterate over each stepper
forward = vals[i] #Forward value are the first 5 in the list
reverse = vals[i+5] #Reverse are the last 5
print "Forward -> " + str(forward) + "Reverse -> " + str(reverse)
for j in range(5): #Iterates over each entry in the test list
#Here we fold the recording values onto each other and make sure
#each residency time in a flag section is within +- 10 for
#the forward and reverse segments
validRange = range(reverse[4-j]-10,reverse[4-j]+10)
if forward[j] not in validRange and not self.failedAxes[i]:
self.errors += "Check "+self.axisNames[i]+" stepper\n"
self.failedAxes[i] = True
passed = False
return passed
def verifyAllTests(self):
passed = True
if self.supplys: #Just realized this is spelled wrong
print "Supply voltage values..."
self._analogToVoltage(readings = self.supplys)
print self.supplyVoltages
passed &= self.testSupplys()
if self.vrefs:
print "Vref values..."
print self.vrefs
passed &= self.testVrefs()
if self.thermistors:
print "Target thermistor readings..."
print self.thermistors
passed &= self.testThermistors()
if self.mosfetHigh:
print "Mosfet high values..."
print self.mosfetHigh
passed &= self.testMosfetHigh()
if self.mosfetLow:
print "Mosfet low values..."
print self.mosfetLow
passed &= self.testMosfetLow()
if self.endstopHigh:
print "Endstop high values..."
print self.endstopHigh
passed &= self.testEndstopHigh()
if self.endstopLow:
print "Endstop low values..."
print self.endstopLow
passed &= self.testEndstopLow()
if self.fullStep:
print "Full step results"
passed &= self.testStepperResults(self.fullStep)
if self.halfStep:
print "Half step results"
passed &= self.testStepperResults(self.halfStep)
if self.quarterStep:
print "Quarter step results"
passed &= self.testStepperResults(self.quarterStep)
if self.sixteenthStep:
print "Sixteeth step results"
passed &= self.testStepperResults(self.sixteenthStep)
return passed
def showErrors(self):
print colored(self.errors, 'red')
def restart(self):
self.fullStep = []
self.halfStep = []
self.quarterStep = []
self.sixteenthStep = []
self.vrefs = []
self.supplys = []
self.supplyVoltages = []
self.mosfetHigh = []
self.mosfetLow = []
self.endstopHigh = []
self.endstopLow = []
self.thermistors = []
self.errors = ""
self.failedAxes = [False,False,False,False,False]
self.failedMosfets = [False,False,False,False,False,False]
self.failedEndstops = [False,False,False,False,False,False]
def resultsDictionary(self):
return dict(fullStep=self.fullStep,
halfStep=self.halfStep,
quarterStep=self.quarterStep,
sixteenthStep=self.sixteenthStep,
vrefs=self.vrefs,
supplys=self.supplys,
supplyVoltages=self.supplyVoltages,
mosfetHigh=self.mosfetHigh,
mosfetLow=self.mosfetLow,
endstopHigh=self.endstopHigh,
endstopLow=self.endstopLow,
thermistors=self.thermistors)
def _wasTimedOut(self, vals):
if -1 in vals:
return True
else:
return False
def _analogToVoltage(self, readings = [], voltage = 5, bits = 10, dividerFactor = 0.091):
#divider factor is R2/(R1+R2)
for val in readings:
self.supplyVoltages += [(val/pow(2, bits))*(voltage/dividerFactor)]