示例#1
0
def controlLoop(freq=100):
    global pose,sensorData,stopCommand,sharedArray
    while stopCommand.value == 0:
        start = time.time()
        while not commandQueue.empty():
            com = commandQueue.get()
            if(com == ACTIVATE):
                wpNav.activate()
            elif(com == DEACTIVATE):
                wpNav.deactivate()
            elif(com == CLEAR):
                wpNav.clearWaypoints()
            elif(com == FOLLOW_START):
                wf.reset()
            elif(com == RAMP_CHANGE):
                ser.receiveData()
                ser.serCont.send('RAMPCH')
            elif(com == SHOOTER_CHANGE):
                ser.receiveData()
                ser.serCont.send('SHOOTER')
            elif(com == ADD_WPS):
                while not wpQueue.empty():
                    wpNav.addWaypoints(wpQueue.get())
            elif(com == ALIGN_RESET):
                wa.reset()
                
        update()
        sharedArray[:] = [pose[0],pose[1],pose[2]] + sensorData
        time.sleep(max(0,1/float(freq) - (time.time()-start)))
    update(stop=True)
示例#2
0
def update(sensorPoints,pose):
    global state
    global desiredDist
    global timeoutStart,lostTimeout
    
    if state == FIND:
        for i,s in enumerate(sensorPoints[:-1]):
            if s[2] and distance(pose,s) <= desiredDist:
                wpNav.initialize()
                wpNav.clearWaypoints()
                wpNav.addWaypoint([pose[0],pose[1],pose[2]+(sen.angArray[i]-sen.angArray[-1]),True])
                print "Aligning with the wall (using waypoint navigator)"
                state=ORIENT
                return wpNav.update(pose)
        return [6.0,0.0]
    elif state == ORIENT:
        if wpNav.state != wpNav.IDLE:
            return wpNav.update(pose)
        else:
            distAngTroller.setDesired(desiredDist,reset=True)#distance(sensorPoints[0],pose),reset=True)
            print "Found and aligned with wall, following now."
            state = FOLLOW
            return [0,0]
    elif state == FOLLOW:
        sp = sensorPoints
        if not sp[-1][2] and not sp[-2][2]:
            print "Lost wall, trying to find it again."
            timeoutStart = time.time()
            state = LOST_TIMEOUT
            return [5.0,-2.0]
        elif not sp[-2][2]:
            dist = distance(sp[-1],pose)
        elif not sp[-1][2]:
            dist = distance(sp[-2],pose)
        else:
            ax,ay = sp[-2][0]-sp[-1][0],sp[-2][1]-sp[-1][1]
            bx,by = pose[0]-sp[-1][0],pose[1]-sp[-1][1]
            x = distance(pose,sp[-1])
            dist = x*math.sqrt(1- (ax*bx + ay*by)/(distance(sp[-1],sp[-2])*x))
        return [5.0,distAngTroller.update(dist)]
    elif state == LOST_TIMEOUT:
        if sensorPoints[-1][2] or sensorPoints[-2][2]:
            print "Found wall again, back to following it."
            distAngTroller.setDesired(desiredDist,reset=True)
            state = FOLLOW
            return [0,0]
        elif (time.time()-timeoutStart) > lostTimeout:
            state=FIND
        return [5.0,-2.0]
示例#3
0
def initialize():
    ser.initialize()
    wpNav.initialize()
    wf.initialize()
    odo.initialize(realWidth/2.0, realHeight/2.0)
    
    wpNav.clearWaypoints()
    wpNav.deactivate()
    CONTROLLER.value = WAYPOINT
    basicFor.value = basicAng.value = 0.0
    stopCommand.value = 0
    inWait.value = 1

    p = mp.Process(target=controlLoop)
    p.start()
示例#4
0
def controlLoop(freq=200):
    global pose,sensorData,stopCommand,sharedArray
    while stopCommand.value == 0:
        start = time.time()
        while not wpQueue.empty():
            wpNav.addWaypoints(wpQueue.get())
        while not commandQueue.empty():
            com = commandQueue.get()
            if(com == ACTIVATE):
                wpNav.activate()
            elif(com == DEACTIVATE):
                wpNav.deactivate()
            elif(com == CLEAR):
                wpNav.clearWaypoints()
            elif(com == FOLLOW_START):
                wf.reset()
        update()
        sharedArray[:] = [pose[0],pose[1],pose[2]] + sensorData
        time.sleep(max(0,1/float(freq) - (time.time()-start)))
    update(stop=True)