def ultrasonics(): while True: dist = running_average.update( ultrasonic_distance.distance(trig1, echo1)) left = running_average.update( ultrasonic_distance.distance(trig2, echo2)) right = running_average.update( ultrasonic_distance.distance(trig3, echo3)) time.sleep(0.05)
def thread_function(name): while True: print(ultrasonic_distance.distance(trig1, echo1)) #print(ultrasonic_distance.distance(trig2, echo2)) #print(ultrasonic_distance.distance(trig3, echo3)) print("") time.sleep(1)
def motor1(x): dist = distance() if dist < 20: print 'stop...' if x == 'True': GPIO.output(Motor1_A, GPIO.LOW) GPIO.output(Motor1_B, GPIO.HIGH) elif x == 'False': GPIO.output(Motor1_A, GPIO.HIGH) GPIO.output(Motor1_B, GPIO.LOW)
def doggy_detected(): import ultrasonic_distance import pygame x = 0 totalDistance = 0 averageDistance = 0 while x < 50: x = x + 1 time.sleep(.01) totalDistance = ultrasonic_distance.distance() + totalDistance averageDistance = totalDistance / x inchesDistance = averageDistance / 2.54 if inchesDistance < detectionDistance: pygame.mixer.music.play() while pygame.mixer.music.get_busy() == True: continue print(averageDistance) print(inchesDistance)
def ultrasonic1(): while True: global dist dist = running_average.update( ultrasonic_distance.distance(trig1, echo1)) time.sleep(SENSOR_DELAY)
import dhhht import ultrasonic_distance import time import moto from firebase import firebase firebase=firebase.FirebaseApplication('https://farming-48619.firebaseio.com/') while True: b=firebase.get('/iot','motor') print(b) moto.mot(17) a1=soil1.soil(2) print(a1) firebase.put('iot','soil moisture',a1) #firebase.get('/iot','soil moisture') a2,a3=dhhht.dh(3) firebase.put('iot','temp',a2) firebase.put('iot','humidity',a3) a=ultrasonic_distance.distance(18,24) print(a) firebase.put('iot','distance',a) a4=soil1.soil(4) print(a4) firebase.put('iot','light',a4) ## else: ## pass time.sleep(1)
WINDOW_LENGTH = 5 if __name__ == '__main__': try: print ("Starting") motors.enable() motors.setSpeeds(0, 0) Lspeed = 0 Rspeed = 0 lst = [MIN_DIST] * WINDOW_LENGTH running_average.average_init(lst) ultrasonic_distance.init(trig1, echo1) # ultrasonic_distance.init(trig2, echo2) # ultrasonic_distance.init(trig3, echo3) while True: dist = running_average.update(ultrasonic_distance.distance(trig1, echo1)) # left = running_average.update(ultrasonic_distance.distance(trig2, echo2)) # right = running_average.update(ultrasonic_distance.distance(trig3, echo3)) #stop if too close if dist < MIN_DIST and DEC == False: print ("TOO CLOSE") DEC = True ACC = False # start if in range elif dist >= MIN_DIST and ACC == False: ACC = True DEC = False # reached max speed elif ACC == True and (Lspeed >= FORWARD_SPEED or Rspeed >= FORWARD_SPEED): print ("CRUISING FORWARD") ACC = False
def motor_forward(request): motor.forward() dist = distance() if dist < 20: print 'Motor stop' return HttpResponse("Motor forward")
try: print("Starting") motors.enable() motors.setSpeeds(0, 0) Lspeed = 0 Rspeed = 0 lst = [MIN_DIST] * WINDOW_LENGTH running_average.average_init(lst) ultrasonic_distance.init(trig1, echo1) ultrasonic_distance.init(trig2, echo2) ultrasonic_distance.init(trig3, echo3) while True: # dist = ultrasonic_distance.distance(trig1, echo1) time.sleep(.25) dist = running_average.update( ultrasonic_distance.distance(trig1, echo1)) time.sleep(.25) left = running_average.update( ultrasonic_distance.distance(trig2, echo2)) time.sleep(.25) right = running_average.update( ultrasonic_distance.distance(trig3, echo3)) #stop if too close if dist < MIN_DIST and DEC == False: print("TOO CLOSE") DEC = True DECELERATE = list(range( Lspeed, -REVERSE_SPEED, DEC_VALUE)) + list( range(-REVERSE_SPEED, 0, -DEC_VALUE)) # L_DECELERATE = list(range(Lspeed, -REVERSE_SPEED, DEC_VALUE)) + list(range(-REVERSE_SPEED, 0, -DEC_VALUE)) # R_DECELERATE = list(map(lambda x: Rspeed if