class Sensor: def __init__(self, trigger_pin, echo_pin, angle): self._trigger_pin = trigger_pin self._echo_pin = echo_pin self._angle = angle self._sr04 = Echo(self._trigger_pin, self._echo_pin) def getDistance(self, samples = 1): return self._sr04.read('cm', samples) def getAngle(self): return self._angle def getTriggerPin(self): return self._trigger_pin def getEchoPin(self): return self._echo_pin def stop(self): self._sr04.stop()
#DEVANT ; trig 27 echo 22 // gauche : echo 17 trigger 18 """File: echo_multi_sensor.py""" # Import necessary libraries. from time import sleep from Bluetin_Echo import Echo # Define pin constants TRIGGER_PIN_1 = 27 ECHO_PIN_1 = 22 TRIGGER_PIN_2 = 18 ECHO_PIN_2 = 17 speed_of_sound = 315 while True: capteurDevant = Echo(TRIGGER_PIN1, ECHO_PIN1, speed_of_sound) samples = 5 result = capteurDevant.read('cm', samples) print(result, 'cm') capteurDevant.stop() capteurGauche = Echo(TRIGGER_PIN2, ECHO_PIN2, speed_of_sound) samples = 5 result = capteurGauche.read('cm', samples) print(result, 'cm') capteurGauche.stop() time.sleep(1)
"""File: echo_simple_once.py""" # Import necessary libraries. from Bluetin_Echo import Echo # Define GPIO pin constants. TRIGGER_PIN = 16 ECHO_PIN = 12 # Initialise Sensor with pins, speed of sound. speed_of_sound = 315 echo = Echo(TRIGGER_PIN, ECHO_PIN, speed_of_sound) # Measure Distance 5 times, return average. samples = 5 result = echo.read('cm', samples) # Print result. print(result, 'cm') # Reset GPIO Pins. echo.stop()
#!/usr/bin/env python3 from prometheus_client import start_http_server, Gauge import signal,sys import time from Bluetin_Echo import Echo trigger_pin = 23 echo_pin = 24 sensor = Echo(trigger_pin, echo_pin) distanceMetric = Gauge('distance', 'Distance in cm') start_http_server(8000) def handle_sigterm(*args): sensor.stop() sys.exit() signal.signal(signal.SIGTERM, handle_sigterm) while True: distance = sensor.read('cm', samples = 5) distanceMetric.set(distance) time.sleep(0.5)
s.put_text("Scan Complete: Await Processing", 5, 10) s.redraw() mask_flag = mask(img) if (not mask_flag): s.clear() s.put_text( "Cannot allow without mask, please step aside from queue", 5, 10) s.redraw() fc = 0 tc = 5 break s.clear() s.put_text("Please bring forehead close to red sensor", 5, 10) s.redraw() distance = echo.read('cm') while (distance > 10): s.clear() s.put_text("Please bring forehead close to red sensor", 5, 10) s.redraw() distance = echo.read('cm') T = temp.get_obj_temp() if (T > 99): s.clear() s.put_text( "Cannot allow due to high body temperature, please step aside from queue", 5, 10) s.redraw() fc = 0 tc = 5 break
gapmax = 30 # Vitesse du robot speed = 100 # Le robot ne suis pas encore un mur au depart onTrack = False #time.sleep(30) pz.init() try: while True: # recuperation ultrson capteurDevant = Echo(TRIGGER_PIN1, ECHO_PIN1, speed_of_sound) front = capteurDevant.read('cm', samples) capteurDevant.stop() capteurGauche = Echo(TRIGGER_PIN2, ECHO_PIN2, speed_of_sound) side = capteurGauche.read('cm', samples) capteurGauche.stop() print("devant = ", front, " gauche = ", side) #correction erreur distance > a 4metres while front > 1000 or side > 1000: print("Erreur du capteur, nouvelle prise de donnees") pz.stop() samples = 3 capteurDevant = Echo(TRIGGER_PIN1, ECHO_PIN1, speed_of_sound) front = capteurDevant.read('cm', samples) capteurDevant.stop()
def back(): GPIO.output(12, True) GPIO.output(16, False) GPIO.output(20, True) GPIO.output(21, False) time.sleep(1) def go(): GPIO.output(16, True) GPIO.output(12, False) GPIO.output(21, True) GPIO.output(20, False) time.sleep(1) def stop(): GPIO.output(16, False) GPIO.output(12, False) GPIO.output(21, False) GPIO.output(20, False) data = Echo(23, 24, 315) ret = data.read('cm', 3) print(ret)