Ejemplo n.º 1
0
def get_dist() :
    '''Get the distance
    
    Returns:
        Distance in cm
    '''
    output (PIN_TRIGGER, False)
    sleep  (DELAY_SETUP)

    output (PIN_TRIGGER, True)
    sleep  (DELAY_EXEC)
    output (PIN_TRIGGER, False)

    while not input (PIN_ECHO):
        pulse_start = time()

    while input (PIN_ECHO):
        pulse_end  = time()

    distance = (pulse_end - pulse_start) * CM_CONVERTOR
    distance = round (distance, 2)
    
    if not MIN_DIST < distance < MAX_DIST:
        distance = 0
        
    return distance
def loop():
    '''Infinity loop
    Setup the trigger
    get the echo
    calculate and prints distance
    prints out of range if the distance is incorrect
    '''
    pulse_start = 0
    pulse_end = 0

    while True:
        output(PIN_TRIGGER, False)
        sleep(TIMESTAMP_SETUP)

        output(PIN_TRIGGER, True)
        sleep(TIMESTAMP_EXEC)
        output(PIN_TRIGGER, False)

        while not input(PIN_ECHO):
            pulse_start = time()

        while input(PIN_ECHO):
            pulse_end = time()

        distance = (pulse_end - pulse_start) * CM_CONVERTOR
        distance = round(distance, 2)
        distance -= 0.5

        if 2 < distance < 250:
            print("Distance: ", distance, "cm")
        else:
            print("Out Of Range (", distance, ")")
Ejemplo n.º 3
0
def loop():
    for foo in camera.capture_continuous(stream,
                                         format='bgr',
                                         resize=(640, 480),
                                         use_video_port=True):
        #TODO: check mph and if off by a bit accelerate/decelerate

        #TODO: write clean acceleration and breaking methods to import from another file. maybe have varying degrees of acceleration or breaking.
        #to read in mph: need try except because arduino sometimes gives null values

        # try:
        #     if ser.readline().split()[1] < 2 & braking == False:
        #         thr.start()
        # except:
        #     pass

        if input(brake_pin):
            global braked
            if not braked:
                print "breaking"
                dobrake(speed=1000, time_on=1.5)
                braked = True
                kill()
            stream.truncate()

            stream.seek(0)

            #TODO: disengage accelerator motor
            continue
        ret3, frame = threshold(
            bilateralFilter(cvtColor(stream.array, COLOR_BGR2GRAY), 12, 70,
                            70), 0, 255, THRESH_BINARY + THRESH_OTSU)
        edges = Canny(frame, 1000, 1000, 5)
        lines = HoughLines(edges, 1, pi / 180, 100)
        if lines is None:
            kill()
            stream.truncate()
            stream.seek(0)
            continue
        thetas = array([theta for rho, theta in lines[0]])
        theta_filtered = thetas[where((thetas >= 0) & (thetas <= pi))]

        #use list of thetas to figure out degrees to turn
        if (average(theta_filtered) < half):
            radians_to_turn = half - average(thetas)
            print "turning %d degrees right" % degrees(radians_to_turn)
            turn(degrees(radians_to_turn), dir=True)
        else:
            radians_to_turn = average(thetas) - half
            print "turning %d degrees left" % degrees(radians_to_turn)
            turn(degrees(radians_to_turn), dir=False)
        stream.truncate()
        stream.seek(0)
Ejemplo n.º 4
0
        """ Send string to LCD. Newline wraps to second line"""
        for char in text:
            if char == '\n':
                self.write4bits(0xC0)  # next line
            else:
                self.write4bits(ord(char), True)

lcd = Adafruit_CharLCD()
lcd.begin(16, 1)

INTERVAL = 3
DELAY = 60 / INTERVAL
countdown = DELAY
tzinfo = timezone('US/Eastern')

while True:
    lcd.clear()
    cmd = "ip addr show eth0 | grep inet | awk '{print $2}' | cut -d/ -f1"
    p = Popen(cmd, shell=True, stdout=PIPE)
    ipaddr = p.communicate()[0].split('\n')[0]
    lcd.message(datetime.now(tzinfo).strftime('%b %d  %H:%M:%S\n'))
    lcd.message('IP %s' % (ipaddr))

    if input(18):
        countdown = DELAY
    else:
        countdown -= 1
    if countdown == 0:
        os.system('shutdown -h now')
    sleep(INTERVAL)
Ejemplo n.º 5
0
        for char in text:
            if char == '\n':
                self.write4bits(0xC0)  # next line
            else:
                self.write4bits(ord(char), True)


lcd = Adafruit_CharLCD()
lcd.begin(16, 1)

INTERVAL = 3
DELAY = 60 / INTERVAL
countdown = DELAY
tzinfo = timezone('US/Eastern')

while True:
    lcd.clear()
    cmd = "ip addr show wlan0 | grep inet | awk '{print $2}' | cut -d/ -f1"
    p = Popen(cmd, shell=True, stdout=PIPE)
    ipaddr = p.communicate()[0].split('\n')[0]
    lcd.message(datetime.now(tzinfo).strftime('%b %d  %H:%M:%S\n'))
    lcd.message(ipaddr)

    if input(18):
        countdown = DELAY
    else:
        countdown -= 1
    if countdown == 0:
        os.system('shutdown -h now')
    sleep(INTERVAL)
Ejemplo n.º 6
0
 def state(self):
     return input(self.gpio)