-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeas_client.py
More file actions
61 lines (49 loc) · 2.69 KB
/
meas_client.py
File metadata and controls
61 lines (49 loc) · 2.69 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
'''
# @ Author: Daniel Raimundo (DR)
# @ Create Time: 2021-07-14 07:50:42
# @ Modified time: 2021-07-14 07:52:25
# @ Description:
'''
from datetime import datetime
from numpy import double, arctan, pi
from PySide6 import QtCore
import numpy
class MeasWorkerTextSignal(QtCore.QObject):
result = QtCore.Signal(str)
class MeasWorkerPlotSignal(QtCore.QObject):
result = QtCore.Signal(float,float)
class MeasWorker(QtCore.QRunnable):
def __init__(self, uartHandle, textSignal, plotSignal, exportHandle=None):
super(MeasWorker, self).__init__()
self.exportHandle = exportHandle
self.uartHandle = uartHandle
self.textSignal = textSignal
self.plotSignal = plotSignal
def run(self):
self.uartHandle.write(b"d")
try:
xpos = double(self.uartHandle.readLine())
ypos = double(self.uartHandle.readLine())
xneg = double(self.uartHandle.readLine())
yneg = double(self.uartHandle.readLine())
temp = double(self.uartHandle.readLine())/10.0
except ValueError:
self.textSignal.result.emit("<b>UART port not valid -- RANDOM VALUES as measurements</b>")
xpos = numpy.random.random_integers(1,5000)
ypos = numpy.random.random_integers(1,5000)
xneg = numpy.random.random_integers(1,5000)
yneg = numpy.random.random_integers(1,5000)
temp = double(numpy.random.random_integers(1,500))/10.0
den = 2 * (xpos + ypos + xneg + yneg)
if(den != 0):
xposition = (5.7 * ((xpos + yneg) - (xneg + ypos))) / den
xdeviation = arctan(xposition/67.4)*(180/pi)
yposition = (5.7 * ((xpos + ypos) - (xneg + yneg))) / den
ydeviation = arctan(yposition/67.4)*(180/pi)
text = "Measurements: x+: " + str(xpos) + "; y+: " + str(ypos) + "; x-: " + str(xneg) + "; y-: " + str(yneg) + "; temp: " + str(temp) + "\r\n" + "Measurements: xpos: " + '{:f}'.format(xposition) + "; ypos : " + '{:f}'.format(yposition) + "; xdev: " + '{:f}'.format(xdeviation) + "; ydev: " + '{:f}'.format(ydeviation)
if(self.exportHandle!=None):
self.exportHandle.writeRow([datetime.now().strftime("%H:%M:%S.%f")[:-4], str(xpos), str(ypos), str(xneg), str(yneg), str(xposition), str(yposition), str(xdeviation), str(ydeviation), str(temp)])
self.plotSignal.result.emit(xdeviation, ydeviation)
else:
text = "Denominator == 0 = (x+ = " + str(xpos) + " ) + (y+ = " + str(ypos) + " ) + (x- = " + str(xneg) + " ) + (y- = " + str(yneg) + " ); temp: " + str(temp) + "\r\n"
self.textSignal.result.emit(text)