forked from cookem4/T265ControlSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEStop.py
executable file
·52 lines (43 loc) · 1.64 KB
/
EStop.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
import serial
import time
import struct
class EStop:
armingState = 0;
noDataCount = 0;
timeSum = 0
timeCt = 0
def __init__(self, port = '/dev/ttyUSB2', baudrate = 115200):
self.ser_EStop = serial.Serial( #Set up connection from Flight controller to linux machine
port=port,
baudrate=baudrate,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout = 0
)
print(self.ser_EStop.isOpen())
print("*EStop* - Port successfully Opened.")
def updateArmingState(self):
data = self.ser_EStop.readline() #Read in data from serial port
if(len(data) > 0):
self.armingState = data[len(data)-1]
self.noDataCount=0
else:
if(self.noDataCount > 10): #Watchdog to disarm is no data is received from EStop over 10 cycles
self.armingState = 0
self.noDataCount = 0
else:
self.noDataCount += 1
return int(self.armingState)
def closePort(self):
self.ser_EStop.close()
#####################################
# Main #
#####################################
if __name__ == "__main__":
test = EStop(port = 'COM8', baudrate = 115200)
while True:
## print('--------------------')
## print(time.perf_counter())
test.updateArmingState()
print(test.armingState)