def on_release(key): if key == Key.esc: d = ManualData() d.endProgram = True sendData(sock, d) time.sleep(2) sock.shutdown(socket.SHUT_RDWR) sock.close() s.shutdown(socket.SHUT_RDWR) s.close() return False
def press(key): if key == Key.up: self.data.manualDrive = 1 print("Set command to drive forward") elif key == KeyCode.from_char('2'): self.data.manualDrive = 2 print("Set command to drive forward slowly") elif key == Key.down: self.data.manualDrive = -1 print("Set command to drive backwards") elif key == Key.right: self.data.manualTurn = 1 sendData(sock, self.data) self.data = ManualData() print("Send command to turn right ***") elif key == Key.left: self.data.manualTurn = -1 sendData(sock, self.data) self.data = ManualData() print("Send command to turn left ***") elif key == KeyCode.from_char('r'): self.data.raiseForDig = 1 print("Set command to raise digger") elif key == KeyCode.from_char('l'): self.data.raiseForDig = -1 print("Set command to lower digger") elif key == KeyCode.from_char('c'): speed = int(input("Dig speed: ")) self.data.dig = speed print("Set command to dig (collect)") elif key == KeyCode.from_char('p'): self.data.packin = True sendData(sock, self.data) self.data = ManualData() print("Send command to pack in ***") elif key == KeyCode.from_char('d'): speed = int(input("Dump speed: ")) self.data.dump = speed print("Set command to dump") elif key == Key.space: self.data.stop = True sendData(sock, self.data) self.data = ManualData() print("Send command to stop ***") elif key == KeyCode.from_char('s'): print("-----Send command-----") sendData(sock, self.data) self.data = ManualData() else: print("Not a valid command")
def __init__(self): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(("", 20000)) print("binding") s.listen(1) print("listening") self.sock, address = s.accept() print("accepted connection") self.data = ManualData()
def on_press(key): data = ManualData() if key == Key.up: data.manualDrive = 1 print("Set command to drive forward") sendData(sock, data) elif key == Key.down: data.manualDrive = -1 print("Set command to drive backwards") sendData(sock, data) elif key == KeyCode.from_char('1'): data.drive = 100 print("Set command to drive backwards") sendData(sock, data) elif key == KeyCode.from_char('2'): data.drive = -100 print("Set command to drive backwards") sendData(sock, data) elif key == Key.right: data.manualTurn = 1 print("Set command to turn right") sendData(sock, data) elif key == Key.left: data.manualTurn = -1 print("Set command to turn left") sendData(sock, data) elif key == KeyCode.from_char('e'): data.dig = True print("Set command to excavate") sendData(sock, data) elif key == KeyCode.from_char('p'): data.packin = True print("Set command to pack in") sendData(sock, data) elif key == KeyCode.from_char('d'): data.dump = True print("Set command to dump") sendData(sock, data) elif key == Key.space: data.stop = True print("Set command to stop") sendData(sock, data) elif key == KeyCode.from_char('f'): data.forwardScan = True print("Scan LiDAR forward") sendData(sock, data) elif key == KeyCode.from_char('b'): data.backwardScan = True print("Scan LiDAR backwards") sendData(sock, data) elif key == KeyCode.from_char('a'): data.autonomousMode = True print("switch from manual to autonomous") sendData(sock, data) else: print("Not a valid command")
def on_press(key): data = ManualData() if key == Key.up: data.manualDrive = 1 print("Set command to drive forward") sendData(sock, data) elif key == KeyCode.from_char('s'): data.manualDrive = 2 print("Set command to drive slowly") sendData(sock, data) elif key == KeyCode.from_char('0'): data.raiseForDig = -2 sendData(sock, data) time.sleep(.1) data.raiseForDig = 0 print("Set command to lower and dig slowly") sendData(sock, data) elif key == KeyCode.from_char('9'): data.raiseForDig = -3 sendData(sock, data) time.sleep(.1) data.raiseForDig = 0 print("Set command to lower and dig extra slowly") sendData(sock, data) elif key == KeyCode.from_char('1'): data.manualDrive = 2 speed = int(input("Dig speed: ")) data.dig = speed print("Set command to lower and dig") sendData(sock, data) elif key == KeyCode.from_char('2'): data.raiseForDig = -1 speed = int(input("Dig speed: ")) data.dig = speed data.manualDrive = 2 print("Set command to lower, dig, drive forward slowly") sendData(sock, data) elif key == KeyCode.from_char('3'): data.raiseForDig = -1 data.manualDrive = 1 print("Set command to lower and drive normal") sendData(sock, data) elif key == KeyCode.from_char('4'): data.manualDrive = 3 print("Set command to unstick from left side") sendData(sock, data) elif key == KeyCode.from_char('5'): data.manualDrive = 4 print("Set command to unstick from right side") sendData(sock, data) elif key == KeyCode.from_char('6'): data.manualDrive = 5 print("Set command to unstick from back") sendData(sock, data) elif key == KeyCode.from_char('7'): data.manualDrive = 6 print("Set command to unstick from front") sendData(sock, data) elif key == Key.down: data.manualDrive = -1 print("Set command to drive backwards") sendData(sock, data) elif key == Key.right: data.manualTurn = 1 print("Set command to turn right") sendData(sock, data) elif key == Key.left: data.manualTurn = -1 print("Set command to turn left") sendData(sock, data) elif key == KeyCode.from_char('r'): data.raiseForDig = 1 print("Set command to raise digger") sendData(sock, data) elif key == KeyCode.from_char('l'): data.raiseForDig = -1 print("Set command to lower digger") sendData(sock, data) elif key == KeyCode.from_char('c'): speed = int(input("Dig speed: ")) data.dig = speed print("Set command to dig (collect)") sendData(sock, data) elif key == KeyCode.from_char('p'): data.packin = True print("Set command to pack in") sendData(sock, data) elif key == KeyCode.from_char('d'): speed = int(input("Dump speed: ")) data.dump = speed print("Set command to dump") sendData(sock, data) elif key == Key.space: data.stop = True print("Set command to stop") sendData(sock, data) else: print("Not a valid command")