Beispiel #1
0
def moveForward(P):
    if P<700:
        print("FORWARD")
        wpi.serialPuts(serial, "3")
        time.sleep(0.1)
        return 0
    else:
        wpi.serialPuts(serial, "D")
        time.sleep(0.1) 
        print("reached", P)
        return 1
Beispiel #2
0
    def lumiere(self, r, v, b):
        msg = [0x80]
        for c in [r, v, b]:
            if c < 0 or c > 255:
                return False
            else:
                msg.append(int(c / 2))

        ser = wiringpi2.serialOpen(self.config.get("pin_led"), 115200)
        for j in msg:
            wiringpi2.serialPuts(ser, struct.pack("I", j))
        wiringpi2.serialClose(ser)
Beispiel #3
0
def runImage():   #this function follows a user for a set amount of time
                  #This is ran with the heel command
    p_prev = 0
    z=0
    wpi.serialPuts(serial, "D")
    wpi.serialPuts(serial, "D")
    time.sleep(0.1)
    flag = 0
    while z != 2000:
        
          a = 0
          b=0
          
          z = z+1
          ret, img = cap.read()
          wpi.digitalWrite(0,0)
          gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
          faces = face.detectMultiScale(gray, 1.3, 1,minSize=(110,110))
          faces = face.detectMultiScale(gray, 1.1, 1)

          for (x,y,w,h) in faces:
              flag = 1
              p = x+y+w+h
              cx = x+w//2
              a = moveCenter(cx);
              b = moveForward((p+p_prev)//2);
              cy = y+h//2
              cv2.rectangle(img, (x,y), (x+w, y+h), (178,255,34),5) #draws rectange around image, for debugging purposes. Comment out during ops

              wpi.digitalWrite(0,1)	                    #turn on LED
              
              if a != 1:              #function sets a = 1 when robot is centered
                 a = moveCenter(cx);
              if a ==1:             #when a = 1 robot moves forward based on size of p
                                      
                  if b == 0:
                      b = moveForward((p+p_prev)//2);
              p_prev = p
          if flag == 0:
                  wpi.serialPuts(serial, "D")
                  time.sleep(0.1)
          else:
              flag = 0
              
              
          cv2.imshow('Cam',img)  #comment out during operation
          if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    wpi.serialPuts(serial, "D")   #send default value to UART
    time.sleep(0.1)                 
    wpi.digitalWrite(0,0)       #turn off LED
    cap.release()               #destroy windows
    cv2.destroyAllWindows()
Beispiel #4
0
def moveCenter(x):
    if x<250:
         print("Left")
         wpi.serialPuts(serial, "2")  #Sends TX commands
         time.sleep(0.1)
         return 0
    elif x>375:
         print("Right")
         wpi.serialPuts(serial, "1")
         time.sleep(0.1)
         return 0
         
    else:
        print("MID")
        cx=0
        wpi.serialPuts(serial, "D")
        time.sleep(0.1)
         
        return 1
Beispiel #5
0
import wiringpi2 as wiringpi
wiringpi.wiringPiSetup()
serial = wiringpi.serialOpen('/dev/ttyAMA0',115200)
wiringpi.serialPuts(serial,'hello world!')
Beispiel #6
0
import wiringpi2
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)
Beispiel #7
0
import wiringpi2 as wiringpi
import time

wiringpi.wiringPiSetup()
serial = wiringpi.serialOpen('/dev/ttyS0', 9600)

i = 0
while True:
    wiringpi.serialPuts(serial, str(i % 2))
    time.sleep(0.1)
    i += 1
Beispiel #8
0
import wiringpi2
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):
Beispiel #9
0
#!/user/bin/python

import time
import sys
import OSC
import wiringpi2

serial = wiringpi2.serialOpen('/dev/ttyAMA0', 57600)

if serial < 0:
    print("Unable to open serial device: \n")
    sys.exit()

if wiringpi2.wiringPiSetup() == -1:
    print("Unable to start wiringPi: \n")
    sys.exit()


msg = "2" #set data 

while True:
    wiringpi2.serialPuts(serial, msg)
    print(msg)
    time.sleep(0.1) #wait 0.1 sec

wiringpi2.serialClose(serial)