Skip to content
Snippets Groups Projects
Commit 76c9b9a0 authored by Zhaoliang Zheng's avatar Zhaoliang Zheng
Browse files

upload keyboard logic to main code

parent cb384acd
No related merge requests found
...@@ -301,21 +301,28 @@ def main_control(gbx, gby, gb_dist, tx, ty, tz, rx, ry, rz, LIDAR_dist, debugM): ...@@ -301,21 +301,28 @@ def main_control(gbx, gby, gb_dist, tx, ty, tz, rx, ry, rz, LIDAR_dist, debugM):
return pwm1, pwm2, pwm3, pwm4, dir1, dir2, dir3, dir4 return pwm1, pwm2, pwm3, pwm4, dir1, dir2, dir3, dir4
# ============= keyboard interruption =================== # ============= keyboard interruption ===================
def keyboard_stop():
key = cv2.waitKey(5) def init():
if key == ord('q'): pygame.init()
flag = 0 win= pygame.display.set_mode((200,200))
print_count = 1
return flag,print_count def keyboard_stop(flag_s,print_count_s):
def keyboard_interrupt(key): if get_key('q'):
flag_s = 0
if key == ord('s'): print_count_s = 1
stop_all() return flag_s,print_count_s
elif key == ord('c'):
manual_control() def get_key(keyname):
elif key == ord('v'): ans = False
variables_change() for eve in pygame.event.get(): pass
keyInput = pygame.key.get_pressed()
myKey = getattr(pygame,'K_{}'.format(keyname))
if keyInput[myKey]:
ans = True
pygame.display.update()
return ans
def auto_control(): def auto_control():
# =================================== tested autonomous control ====================================================== # =================================== tested autonomous control ======================================================
...@@ -382,32 +389,36 @@ if __name__ == '__main__': ...@@ -382,32 +389,36 @@ if __name__ == '__main__':
flag = 0 flag = 0
print_count = 1 print_count = 1
init()
# =========== LOOP FOREVER=========== # =========== LOOP FOREVER===========
while True: while True:
key = cv2.waitKey(5) if get_key('a'):
if key == ord('a'):
flag = 1 flag = 1
while (flag == 1): while (flag == 1):
auto_control() auto_control()
flag,print_count = keyboard_stop() flag, print_count = keyboard_stop(flag,print_count)
if flag == 0:
cap.release()
cv2.destroyAllWindows()
elif key == ord('s'): elif get_key('s'):
stop_all() stop_all()
print("stop all motors") print("stop all motors")
elif key == ord('c'): elif get_key('m'):
flag = 2 flag = 2
while (flag == 2): while (flag == 2):
manual_control() manual_control()
flag,print_count = keyboard_stop() flag, print_count = keyboard_stop(flag,print_count)
elif key == ord('v'): elif get_key('v'):
flag = 3 flag = 3
while (flag == 3): while (flag == 3):
variables_change() variables_change()
flag,print_count = keyboard_stop() flag, print_count = keyboard_stop(flag,print_count)
elif get_key('k'):
break
if print_count is not 0: if print_count is not 0:
print("No subsystem is running") print("No subsystem is running")
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment