-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtelecommand.py
executable file
·71 lines (50 loc) · 1.64 KB
/
telecommand.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
import serial
import serial.tools.list_ports
import constants as cns
class Telecommand:
def __init__(self, widget):
self.widget = widget
self.ser = serial.Serial()
def connect(self, port, baud):
self.portName = port
self.baudrate = baud
try:
self.ser = serial.Serial(self.portName, self.baudrate)
print("TELE Connected : ", self.portName)
return True
except serial.serialutil.SerialException:
print("TELE Can't open : ", self.portName)
return False
def disconnect(self):
if self.ser.isOpen():
self.ser.close()
print("TELE Disconnected : ", self.portName)
def sendTelecommand(self, telecommand):
index = telecommand.index(".")
selected = int(telecommand[0:index])
if selected == 1:
self.ser.write(b'\x00')
elif selected == 2:
self.ser.write(b'\x01')
elif selected == 3:
self.ser.write(b'\x02')
elif selected == 4:
self.ser.write(b'\x03')
elif selected == 5:
self.ser.write(b'\x04')
elif selected == 6:
self.ser.write(b'\x05')
elif selected == 7:
self.ser.write(b'\x06')
elif selected == 8:
self.ser.write(b'\x07')
def sendServoOpen(self):
self.ser.write(b'\x08')
def sendServoClose(self):
self.ser.write(b'\x09')
def sendEngineRun(self, throttle):
value = throttle + 128
byte = bytes([value])
self.ser.write(byte)
def sendEngineStop(self):
self.ser.write(b'\x0A')