def ArdReset(): if CF.Debug > 0: print("send reset signal to arduino") SC.DropPort(CF.Devices[0][0]) GPIO.output(CF.GPIOPins[0], False) time.sleep(0.1) GPIO.output(CF.GPIOPins[0], True) time.sleep(1.5) SC.InitPort() response = None while response != "Ready": if CF.Debug > 0: print("waiting Arduino boot") SC.DropPort(CF.Devices[0][0]) SC.InitPort() time.sleep(2) response = SC.ReadComand(CF.Devices[0][0]) if (response != None): response = response[:-4] SC.SendComand("p", CF.Devices[0][0]) print(response) if CF.Debug > 0: print("reset complete")
def TurnLeftMoving(Speed, Turn): Direction = ['0', '1', '0', '1'] comand = BuildMovingComand(Speed, Turn, Direction) SC.SendComand(comand, MovingArduino) if CF.Debug > 0: print(comand)
def BackRightMoving(Speed, Turn): Direction = ['2', '0', '0', '2'] comand = BuildMovingComand(Speed, Turn, Direction) SC.SendComand(comand, MovingArduino) if CF.Debug > 0: print(comand)
def ForwardMoving(Speed, Turn): #принимаем скорость и обороты колеса Direction = ['1', '1', '1', '1'] comand = BuildMovingComand(Speed, Turn, Direction) SC.SendComand(comand, MovingArduino) if CF.Debug > 0: print(comand)
new[6][TERMIOS.VMIN] = 1 new[6][TERMIOS.VTIME] = 0 termios.tcsetattr(fd, TERMIOS.TCSANOW, new) c = None try: c = os.read(fd, 1) finally: termios.tcsetattr(fd, TERMIOS.TCSAFLUSH, old) return c try: Speed = int(input('enter speed')) Turn = int(input('enter turn(1/1000)')) while True: print(SC.ReadComand(CF.Devices[0][0])) pressedKey = getkey().decode("utf-8") if pressedKey == 'y': sys.exit() elif pressedKey == 'w': MP.ForwardMoving(Speed, Turn) elif pressedKey == 'a': MP.LeftMoving(Speed, Turn) elif pressedKey == 's': MP.BackMoving(Speed, Turn) elif pressedKey == 'd': MP.RightMoving(Speed, Turn) elif pressedKey == 'q': MP.ForwardLeftMoving(Speed, Turn) elif pressedKey == 'e': MP.ForwardRightMoving(Speed, Turn)