def cmd_forward(): open_serial_port() blinkon() for t in range(0,21): message = [0x88,int(math.floor(t*MAXSPEED/20)),0x8c,int(math.floor(t*MAXSPEED/20))] for a in range(0,4): wp.serialPutchar(rpi,(message[a])) if R_Ranger.obstacle_present() == 1: message = [0x88,0,0x8c,0] for a in range(0,4): wp.serialPutchar(rpi, message[a]) close_serial_port() return -1 time.sleep(PAUSE) for t in range(20,-1, -1): message = [0x88,int(math.floor(t*MAXSPEED/20)),0x8c,int(math.floor(t*MAXSPEED/20))] for a in range(0,4): wp.serialPutchar(rpi, message[a]) if R_Ranger.obstacle_present() == 1: message = [0x88,0,0x8c,0] for a in range(0,4): wp.serialPutchar(rpi, message[a]) close_serial_port() return -1 time.sleep(PAUSE) blinkoff() close_serial_port() return 0
def cmd_rotateright(): open_serial_port() blinkon() for t in range(0,21): message = [0x8a,int(math.floor(t*MAXSPEED/20)),0x8c,int(math.floor(t*MAXSPEED/20))] for a in range(0,4): wp.serialPutchar(rpi, message[a]) time.sleep(ROTATIONPAUSE) for t in range(20,-1,-1): message = [0x8a,int(math.floor(t*MAXSPEED/20)),0x8c,int(math.floor(t*MAXSPEED/20))] for a in range(0,4): wp.serialPutchar(rpi, message[a]) time.sleep(ROTATIONPAUSE) blinkoff() close_serial_port()
def cmd_reverse(): open_serial_port() blinkon() for t in range(0,21): message = [0x8a,int(math.floor(t*MAXSPEED/20)),0x8e,int(math.floor(t*MAXSPEED/20))] for a in range(0,4): wp.serialPutchar(rpi, message[a]) time.sleep(0.1) for t in range(20,-1,-1): message = [0x8a,int(math.floor(t*MAXSPEED/20)),0x8e,(math.floor(t*MAXSPEED/20))] for a in range(0,4): wp.serialPutchar(rpi, message[a]) time.sleep(0.1) blinkoff() close_serial_port()
def cmd_rotateleft(): open_serial_port() blinkon() for t in range(0, 21): message = [ 0x88, int(math.floor(t * MAXSPEED / 20)), 0x8e, int(math.floor(t * MAXSPEED / 20)) ] for a in range(0, 4): wp.serialPutchar(rpi, message[a]) time.sleep(ROTATIONPAUSE) for t in range(20, -1, -1): message = [ 0x88, int(math.floor(t * MAXSPEED / 20)), 0x8e, int(math.floor(t * MAXSPEED / 20)) ] for a in range(0, 4): wp.serialPutchar(rpi, message[a]) time.sleep(ROTATIONPAUSE) blinkoff() close_serial_port()
def cmd_reverse(): open_serial_port() blinkon() for t in range(0, 21): message = [ 0x8a, int(math.floor(t * MAXSPEED / 20)), 0x8e, int(math.floor(t * MAXSPEED / 20)) ] for a in range(0, 4): wp.serialPutchar(rpi, message[a]) time.sleep(0.1) for t in range(20, -1, -1): message = [ 0x8a, int(math.floor(t * MAXSPEED / 20)), 0x8e, (math.floor(t * MAXSPEED / 20)) ] for a in range(0, 4): wp.serialPutchar(rpi, message[a]) time.sleep(0.1) blinkoff() close_serial_port()
def cmd_forward(): open_serial_port() blinkon() for t in range(0, 21): message = [ 0x88, int(math.floor(t * MAXSPEED / 20)), 0x8c, int(math.floor(t * MAXSPEED / 20)) ] for a in range(0, 4): wp.serialPutchar(rpi, (message[a])) if R_Ranger.obstacle_present() == 1: message = [0x88, 0, 0x8c, 0] for a in range(0, 4): wp.serialPutchar(rpi, message[a]) close_serial_port() return -1 time.sleep(PAUSE) for t in range(20, -1, -1): message = [ 0x88, int(math.floor(t * MAXSPEED / 20)), 0x8c, int(math.floor(t * MAXSPEED / 20)) ] for a in range(0, 4): wp.serialPutchar(rpi, message[a]) if R_Ranger.obstacle_present() == 1: message = [0x88, 0, 0x8c, 0] for a in range(0, 4): wp.serialPutchar(rpi, message[a]) close_serial_port() return -1 time.sleep(PAUSE) blinkoff() close_serial_port() return 0
def open_serial_port(): global rpi rpi = wp.serialOpen("/dev/ttyAMA0",38400) wp.serialPutchar(rpi,170)
def dataOutput(target, value): dataOutputLock.acquire() wiringpi2.serialPutchar(middleLayer, target) wiringpi2.serialPutchar(middleLayer, mes) dataOutputLock.release()
def open_serial_port(): global rpi rpi = wp.serialOpen("/dev/ttyAMA0", 38400) wp.serialPutchar(rpi, 170)
import sys #this example need change script.bin #[uart_para6] #uart_used = 1 #uart_port = 6 #uart_type = 2 #uart_tx = port:PI12<3><1><default><default> #uart_rx = port:PI13<3><1><default><default> #PI12: pin46[U14 Next to sata] #PI13: pin48[U14 Next to sata] serial = wiringpi2.serialOpen('/dev/ttyS6', 115200) wiringpi2.serialPuts(serial, "\n") print serial wiringpi2.serialPuts(serial, "Putchar:") wiringpi2.serialPutchar(serial, 0x38) #sent ascii 0x38: 8 #wiringpi2.serialPutchar(serial,0x65)#sent ascii 0x68: A wiringpi2.serialPuts(serial, "\n") wiringpi2.serialPuts(serial, "Puts:") wiringpi2.serialPuts(serial, "hello\n") wiringpi2.serialPuts(serial, "Printf:") wiringpi2.serialPrintf(serial, "hello\n") #####get data from serial while 1: if wiringpi2.serialDataAvail(serial): val = wiringpi2.serialGetchar(serial) print chr(val)
def outputArduino(mes): arduinoOutLock.acquire() wiringpi2.serialPutchar(arduino, mes) arduinoOutLock.release()
import sys #this example need change script.bin #[uart_para6] #uart_used = 1 #uart_port = 6 #uart_type = 2 #uart_tx = port:PI12<3><1><default><default> #uart_rx = port:PI13<3><1><default><default> #PI12: pin46[U14 Next to sata] #PI13: pin48[U14 Next to sata] serial = wiringpi2.serialOpen('/dev/ttyS6',115200) wiringpi2.serialPuts(serial,"\n") print serial wiringpi2.serialPuts(serial,"Putchar:") wiringpi2.serialPutchar(serial,0x38)#sent ascii 0x38: 8 #wiringpi2.serialPutchar(serial,0x65)#sent ascii 0x68: A wiringpi2.serialPuts(serial,"\n") wiringpi2.serialPuts(serial,"Puts:") wiringpi2.serialPuts(serial,"hello\n") wiringpi2.serialPuts(serial,"Printf:") wiringpi2.serialPrintf(serial,"hello\n") #####get data from serial while 1: if wiringpi2.serialDataAvail(serial): val = wiringpi2.serialGetchar(serial)