Пример #1
0
def gotoline(speed, over=True):
    """Proceed forward until cross the line."""
    pi2go.goBoth(speed)
    while not pi2go.irLeftLine():
        time.sleep(0.1)
    if over:
        # get off the line
        while pi2go.irLeftLine():
            time.sleep(0.1)
Пример #2
0
def three_point_turn():
    """Perform three point turn."""
    # start speed
    speed = 100
    # start with no turn-rate
    turn = 100.0
    
    # start inside a marked, A3-sized box.
    
    # proceed forward and cross the red line.
    gotoline(speed, True)
    timestartout = time.time()
            
    # proceed forward and cross the next.
    gotoline(speed, True)
            
    # proceed forward and cross the next.
    gotoline(speed, True)
    timestopout = time.time()
                
    # turn left by 90 degrees (either on the spot or in-motion).
    pi2go.spinLeft(turn)
    time.sleep(timespincircle*90.0/360)
        
    # drive forward and touch or cross the first black line.
    # forward to left line
    timestart = time.time()
    gotoline(speed, False)
    # leave on line
    timestop = time.time()

    # drive backwards in a straight line and touch or cross the first black line.
    # reverse off line and then to right line
    gotoline(-speed, True)
    gotoline(-speed, True)
    
    # drive forwards to the middle of the turning area.
    # move half across distance we have just reversed
    pi2go.goBoth(speed)
    time.sleep(timestop-timestart)

    # turn left by 90 degrees (either on the spot or in-motion).
    pi2go.spinLeft(turn)
    time.sleep(timespincircle*90.0/360)
        
    # return to the starting box.
    # move outbound distance back to start
    pi2go.goBoth(speed)
    time.sleep(timestopout-timestartout)
    
    stop()
Пример #3
0
def straight_line():
    """Straight line speed test."""
    # Full speed
    speed = 100
    
    # start inside a marked, A3-sized box.
    
    # cross the start line
    gotoline(speed, True)
    
    # continue to finish line
    gotoline(speed,True)
    
    # go 20cm further (cross the line)
    pi2go.goBoth(speed)
    time.sleep(time10cm*2)
    
    pi2go.stop()
Пример #4
0
def proximity_test():
    """Perform whole PiWars Proximity Test challenge."""
    MIN_DIST = 1.45

    # drive forward 1.3m so that sensors are in range.
    # use wheel turn calibration on distance
    #pi2go.goBoth(100)
    #time.sleep(time10cm*1)  # test
    #time.sleep(time10cm*13)
    pi2go.stop()
    
    # square off to the wall
    distance = square_up()
    logging.debug('Distance={}'.format(distance))

    # proceed towards the wall slowing down as we approach
    # speeed 1 (max) at 20cm and 0 (min) at 0.5cm
    while distance >= MIN_DIST:
        logging.debug('Speed={}'.format((distance - MIN_DIST) / (20 - MIN_DIST) * 100))
        pi2go.goBoth(min((distance - MIN_DIST) / (20 - MIN_DIST) * 100, 100))
        distance = pi2go.getDistance()
        logging.debug('Distance={}'.format(distance))
    pi2go.stop()