예제 #1
0
            return

        else:
            turnRight()
            driveForward()


#ultrasound.when_in_range = avoidObstacles
#ultrasound.when_out_of_range = driveForTime
"""
def getDistance():
    while True:
        dist = int(ultrasound.distance * 100)
        print(dist)
        if dist < 45:
            turnRight()
        else:
            straightenWheels()

getDistance()
"""
#driveForTime()
#running = True
#sleep(20)
#running = False

driveForward()
ultrasound.wait_for_in_range(8)
#sleep(1)
stopDriving()
예제 #2
0
from gpiozero import LED, DistanceSensor
from time import sleep

led = LED(26)
sensor = DistanceSensor(echo=24, trigger=23)

sensor.wait_for_in_range()
led.on()
예제 #3
0
파일: US_Distance.py 프로젝트: guydvir2/Rpi
from gpiozero import DistanceSensor
from time import sleep

ultrasonic = DistanceSensor(echo=19, trigger=6)

while True:
    print("Y")
    ultrasonic.wait_for_in_range()
    print("In range")
    ultrasonic.wait_for_out_of_range()
    print("Out of range")

    #print("T")
    #ultrasonic.wait_for_in_range()
    #print("In range")
    #ultrasonic.wait_for_out_of_range()
    #print("Out of range")
    #sleep(1)
    #print(ultrasonic.distance)
예제 #4
0
        if distancia > 20:
            print("Esperando objeto")
            time.sleep(1)
        else:
            fecha_1 = time.ctime()
            print("{:.4f}".format(distancia) + " cm")
            time.sleep(0.5)
            ultrasonic.wait_for_out_of_range()
            ObjetoR(fecha_1, distancia)


def ObjetoR(fecha_1, distancia):
    fecha_2 = time.ctime()
    time.sleep(0.1)
    datos = [(fecha_1, fecha_2, distancia)]
    conexion(datos)


def conexion(datos):
    conexion = sqlite3.connect('Ultrasonido.db')
    c = conexion.cursor()
    c.executemany(
        "insert into acciones (fecha_1,fecha_2,distancia) values(?,?,?)",
        datos)
    conexion.commit()
    conexion.close()


while True:
    ultrasonic.wait_for_in_range = (ObjetoC())
예제 #5
0
from gpiozero import DistanceSensor
us = DistanceSensor(echo = 17, trigger = 4)
while True:
  us.wait_for_in_range()
  print(us.distance)
  us.wait_for_out_of_range()
  print('Out of range')


예제 #6
0
#!/usr/bin/env python3

import move
import signal
from gpiozero import DistanceSensor

min_distance = 0.15
sonic_sensor = DistanceSensor(
    echo=18, trigger=17, threshold_distance=min_distance)
speed = 0.5


def exit_gracefully():
    exit()


sonic_sensor.when_in_range = lambda: move.stop()
sonic_sensor.when_out_of_range = lambda: move.forward()

signal.signal(signal.SIGINT, exit_gracefully)

move.forward(speed)
while True:
    sonic_sensor.wait_for_in_range()
    move.backward(speed)
    sonic_sensor.wait_for_out_of_range()
    move.right(speed, 0.75)


exit_gracefully()