-
Notifications
You must be signed in to change notification settings - Fork 1
/
servo_calibrate.py
53 lines (43 loc) · 1.03 KB
/
servo_calibrate.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
import serial
from sys import stdout
import time
import os
from rf import Serial_Thread
import keyboard
# Define Globals
startMarker = '<'
endMarker = '>'
dataStarted = False
dataBuf = ""
messageComplete = False
def exit_key():
# Button press that exits the program
keyboard.press('x')
time.sleep(0.01)
print('Closing all...')
os._exit(1)
def main():
keyboard.add_hotkey('x', exit_key)
port = 'COM6'
baud_rate = 9600
com = serial.Serial()
com.port = port
com.baudrate = baud_rate
com.timeout = 0.1
com.writeTimeout=0
com.open()
serial_thread = Serial_Thread(com)
print('Starting Serial Thread...')
recv_msg='XXX'
while True:
key = input('Press c')
if key=='c':
serial_thread.send_msg = key
serial_thread.sendToArduino()
time.sleep(0.5)
while recv_msg == 'XXX':
recv_msg = serial_thread.recvArduino()
print(recv_msg)
recv_msg='XXX'
if __name__ == '__main__':
main()