コード例 #1
0
def turn():
    steer(-1)
    drive(0.28)
    time.sleep(3)
    steer(0)
    drive(0.28)
    time.sleep(1)
    drive(0)
コード例 #2
0
def detect(path):
    cascade = cv2.CascadeClassifier(path)
    if webcam:
        video_cap = cv2.VideoCapture("http://localhost:8081") # use 0,1,2..depanding on your webcam
    else:
        video_cap = cv2.VideoCapture("stopvideo.MOV")
    
    steer(0)
   # WINDOW_NAME = "Object Detection"
   # cv2.namedWindow(WINDOW_NAME, cv2.WINDOW_AUTOSIZE)
   # cv2.startWindowThread()
    drive(0.26)
    while True:
        # Capture frame-by-frame
        ret, img = video_cap.read()
        
        if (ret==False):
            break
 
        #converting to gray image for faster video processing
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
 
        rects = cascade.detectMultiScale(gray, scaleFactor=scale_factor, minNeighbors=min_neighbors,
                                         minSize=min_size)
        # if at least 1 face detected
        if len(rects) > 0:
            # Draw a rectangle around the faces
            #for (x, y, w, h) in rects:
              #  cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
           # print("Width"+str(w))
           # print("Height"+str(h))
           # print()
            drive(-1)
            time.sleep(3)
            print("Object Detecting")
            turn()
            break
            #steer(-1)
            #drive(0.28)
            #time.sleep(1)
            #drive(0)
            # Display the resulting frame
           # r = 1000.0 / img.shape[1]
           # dim = (1000, int(img.shape[0] * r))
           # resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA)
           # cv2.imshow(WINDOW_NAME, resized)
            #wait for 'c' to close the application
           # if cv2.waitKey(1) & 0xFF == ord('q'):
            #    stop()
             #   break
    
    video_cap.release()
コード例 #3
0
def on_new_client(clientsocket, addr):
    counter = 0
    while True:
        try:
            size = struct.unpack("i",
                                 clientsocket.recv(struct.calcsize("i")))[0]
            data = ""
            #cmd = msg.decode(encoding='utf-8')
            while len(data) < size:
                msg = clientsocket.recv(size - len(data))
                empty_socket(clientsocket)
                if not msg:
                    break
                data += msg.decode()
            print(data)
            counter += 1
            if (counter > 10):
                inControl.drive(.255)
        except:
            inControl.stop()
            #clientsocket.close()
            break

        #subprocess.call(data, shell=True)
        if "steer" in data:
            words = data.split()
            amt = float(words[1])
            inControl.steer(amt)

        if "speed" in data:
            words = data.split()
            amt = float(words[1])
            inControl.drive(amt)

        #time.sleep(0.1)
    clientsocket.close()
コード例 #4
0
def main():
    if (len(sys.argv) < 2):
        print("MISSING ARG")
        exit()
    steerVal = float(sys.argv[1])
    inControl.steer(steerVal)
コード例 #5
0
def doCommand(cEntry, q, workerList):
    global Stopped
    HARD_TURN = 1
    WAIT_AMT = 2.1
    #bits = cString.split()
    """
    <priority> <timestamp> <steer|drive|stop> <amt>
    """
    command = cEntry.command
    amt = float(cEntry.amount)
    print("Command is %s amount is %.2f" % (command, amt))
    if (command == "steer"):
        inControl.steer(amt)
    elif (command == "drive"):

        if (amt <= 0 and Stopped == True):
            amt = 0
        elif (amt <= 0 and Stopped == False):
            Stopped = True
        else:
            Stopped = False
        print("Amount %f" % amt)
        inControl.drive(amt)

    elif (command == "stop"):
        inControl.stop()
        time.sleep(amt)
    elif (command == "stopright"):
        Stopped = True
        signalDump(workerList, True)
        inControl.drive(-1)  #TODO
        time.sleep(amt)
        inControl.steer(HARD_TURN * -1)
        inControl.drive(.28)
        time.sleep(WAIT_AMT)
        inControl.steer(0)
        signalDump(workerList, False)
        Stopped = False
        #time.sleep(.3)
    elif (command == "stopleft"):
        Stopped = True
        signalDump(workerList, True)
        inControl.drive(-1)  #TODO
        time.sleep(amt)
        inControl.steer(HARD_TURN * 1)
        inControl.drive(.3)
        time.sleep(WAIT_AMT)
        #inControl.drive(.26)
        inControl.steer(0)
        signalDump(workerList, False)
        inControl.drive(0)
        time.sleep(.6)
        inControl.drive(.28)
        #time.sleep(.3)
        Stopped = False
    elif (command == "stopcenter"):
        Stopped = True
        #ts0=cEntry.timestamp
        signalDump(workerList, True)
        inControl.drive(-1)  #TODO
        time.sleep(amt)
        inControl.drive(.28)
        inControl.steer(0)
        #time.sleep(1)
        signalDump(workerList, False)
        #ts1 = time.time()
        Stopped = False

    else:
        print("Command not recognized")
コード例 #6
0
import edgeDetect.live_image as live_image
from servoController.inputController import drive, steer, stop
from time import sleep
from simple_pid import PID
steer(0)
drive(0)

c = "CENTER"
l = "LEFT"
r = "RIGHT"

steerMax = .8
centerSteer = 0

live_image.run()
try:
    drive(.26)
    while (True):
        angle = live_image.liveAngle
        botOfLine = live_image.liveLine
        # if(botOfLine == "NONE"):
        #     drive(-1)
        #     steer(0)
        #     sleep(1)
        #     drive(0)
        #     exit()
        #print("Got angle of %d" % (angle))
        if (angle > -88 and angle < 0):
            #drive(.28)
            if angle > -60.0:
                angle = -60.0
コード例 #7
0
import socket
import _thread
import sys
import os
import time
import struct
import select
import subprocess
sys.path.append('..')
import servoController.inputController as inControl

inControl.steer(0)


def empty_socket(sock):
    """remove the data present on the socket"""
    input = [sock]
    while 1:
        inputready, o, e = select.select(input, [], [], 0.0)
        if len(inputready) == 0: break
        for s in inputready:
            s.recv(1)


#loop to mannage connected socket input
def on_new_client(clientsocket, addr):
    counter = 0
    while True:
        try:
            size = struct.unpack("i",
                                 clientsocket.recv(struct.calcsize("i")))[0]
コード例 #8
0
       200]  #200cm 5 value scrolling window for fiter


def medianFilt(val):
    for i in range(0, 9):
        arr[i] = arr[i + 1]
    arr[9] = val
    temp = arr.copy()
    temp.sort()
    #print("Array is " + str(arr))
    return temp[5]


getDistance()
getDistance()
steer(-.22)
drive(0.28)
while (True):
    val = getDistance()
    val = medianFilt(val)
    print("Distance is: %.2f" % val)
    if (val < 60.0):
        drive(-1)
        sleep(1)
        stop()
        break
        print("Stopped")
print("Done")
cleanUp()
exit()