Example #1
0
def OffAxisBy(repeats=5): 
	FL_dist = 0 
	FR_dist = 0 
	FM_dist = 0 
	for i in range(0,repeats): 
		FL_dist += rngf_FL.MeasureOnce() 
		FR_dist += rngf_FR.MeasureOnce() 
		FM_dist += rngf_FM.MeasureOnce() 
		HCSR04.sleep(rngf_FM.setl_len) 	# Give time for sensors to settle 
	FL_dist /= repeats 			# +15deg dist in cm 
	FR_dist /= repeats 			# -15deg dist in cm 
	FM_dist /= repeats 			#   0deg dist in cm 
    def calculateCurrentVolume(self):

        values = []

        for count in range(1, 10):
            uSeconds = hc.readvalue(self.trigger_gpio_pin, self.echo_gpio_pin)
            values.append(uSeconds)

        uSeconds = median(values)

        distance = uSeconds * (
            343.59 / 1000000.0000
        )  # time in us * ( speed of sound m/s / 10e6 ) -> m/us -> m
        distance = distance * 100  # m -> cm
        distance = distance / 2  # signal from sensor is traveling to surface and back thus dividing by two
        log.debug("Distance: " + str(distance))

        liquidHeight = self.sensor_distance - distance

        volume = self.calculateVolume(self.reservoir_length,
                                      self.reservoir_width, liquidHeight)

        litres = self.cubicCentiMetersToLitres(
            volume
        ) * self.reservoir_multiplier  # litres multiplied by multiplier, in my setup I have two plastic boxes connected to each other, water will level between boxes by physics

        log.debug("Litres: " + str(litres))

        return round(litres)
 def __init__(self, trig_pin, echo_pin, i2c_bus=1, _get_state=None):
     self.bus = SMBus(i2c_bus)
     self.IRSens = MLX90614(self.bus)
     self.ProxSens = HCSR04.HCSR_04(trig_pin, echo_pin,
                                    self.IRSens.get_ambient())
     self.VERIFICATION = 10
     self._get_state = _get_state
    def calculateCurrentVolume(self):
        
        values = []
        
        for count in range(1,10):
            uSeconds = hc.readvalue(self.trigger_gpio_pin, self.echo_gpio_pin)
            values.append(uSeconds)
        
        uSeconds = median(values)
    
        distance = uSeconds * ( 343.59 / 1000000.0000 ) # time in us * ( speed of sound m/s / 10e6 ) -> m/us -> m
        distance = distance * 100 # m -> cm
        distance = distance / 2 # signal from sensor is traveling to surface and back thus dividing by two
        log.debug("Distance: " + str(distance))
        
        liquidHeight = self.sensor_distance - distance
        
        volume = self.calculateVolume(self.reservoir_length, self.reservoir_width, liquidHeight)

        litres = self.cubicCentiMetersToLitres(volume) * self.reservoir_multiplier # litres multiplied by multiplier, in my setup I have two plastic boxes connected to each other, water will level between boxes by physics

        log.debug("Litres: " + str(litres))

        return round(litres) 
Example #5
0
'''
Created on Jul 1, 2015

@author: markos
'''

import HCSR04 as hc

if __name__ == '__main__':
    ''' trigger, echo '''
    val = hc.readvalue(23,24)
    val = val / 1000000.00
    
    distance = val * 343.59 * 100
    distance = distance / 2
    distance = distance / 1000000.00
    distance = round(distance, 2)
    print "Distance : %.1f" % distance    
    
Example #6
0
def turn():
    stopCount = 0
    print "TURN"
    motor_ctrl.setMode("LEFT")
    time.sleep(.6)
    motor_ctrl.setMode("BACKWARD")
    time.sleep(.3)
    motor_ctrl.setMode("STOP")


stopCount = 0

config.initialize()

sensor1 = HCSR04.HCSR04(16, 18, "FRONT")

sensor1.start()

motor_ctrl = L298N.L298N(7, 11, 12, 13)
motor_ctrl.start()

while True:
    print "FRONT: ", sensor1.read()
    distance = sensor1.read()
    time.sleep(0.05)
    if distance < 40:
        stopCount = stopCount + 1
        print "STOP"
        motor_ctrl.setMode("STOP")
        if stopCount > 2:
Example #7
0
STOP_DISTANCE = 40

def turn():
  stopCount = 0
  print "TURN"
  motor_ctrl.setMode("LEFT")
  time.sleep(.6)
  motor_ctrl.setMode("BACKWARD")
  time.sleep(.3)
  motor_ctrl.setMode("STOP")

stopCount = 0

config.initialize()

sensorC = HCSR04.HCSR04(37, 38, "FRONT")
sensorC.start()
sensorL = HCSR04.HCSR04(35, 36, "LEFT")
sensorL.start()
sensorR = HCSR04.HCSR04(31, 32, "RIGHT")
sensorR.start()

motor_ctrl = L298N.L298N(22, 11, 12, 13)
motor_ctrl.start()
motor_ctrl.setMode("FORWARD")

def checkDistances():
  print "Checking distances"
  center = sensorC.read()
  left = sensorL.read()
  right = sensorR.read()
Example #8
0
def turn():
    stopCount = 0
    print "TURN"
    motor_ctrl.setMode("LEFT")
    time.sleep(.6)
    motor_ctrl.setMode("BACKWARD")
    time.sleep(.3)
    motor_ctrl.setMode("STOP")


stopCount = 0

config.initialize()

sensorFront = HCSR04.HCSR04(config.TRIG1, config.ECHO, "FRONT")
#sensorRight = HCSR04.HCSR04(config.TRIG2, config.ECHO, "RIGHT")
#sensorLeft = HCSR04.HCSR04(config.TRIG4, config.ECHO, "LEFT")

sensorFront.start()
#sensorRight.start()
#sensorLeft.start()

motor_ctrl = L298N.L298N(22, 11, 12, 13)
motor_ctrl.start()

#logicUnit = logic.LogicalUnit(motor_ctrl, [sensorFront, sensorRight, sensorLeft])

print "Setup Complete"

#logicUnit.start()
Example #9
0
#  Author:  Ben Evans 
# 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 

# from time import sleep  		# Already imported in HCSR04.py, so use that 
# import RPi.GPIO as GPIO 		# Shouldn't be needed here 
import HCSR04 

# INITIALIZE SENSORS # 
rngf_FL = HCSR04.HCSR04(7,13)  	# -> rangefinder: front left 
rngf_FM = HCSR04.HCSR04(19,21) 	# -> rangefinder: front mid 
rngf_FR = HCSR04.HCSR04(23,22) 	# -> rangefinder: front right 
rngf_ML = HCSR04.HCSR04(8,12)  	# -> rangefinder:  mid  left 
rngf_MR = HCSR04.HCSR04(16,18) 	# -> rangefinder:  mid  right 
rngf_RM = HCSR04.HCSR04(24,26) 	# -> rangefinder:  rear mid 
HCSR04.sleep(0.5) 			# Extra time for all sensor pins to settle 


def OffAxisBy(repeats=5): 
	FL_dist = 0 
	FR_dist = 0 
	FM_dist = 0 
	for i in range(0,repeats): 
		FL_dist += rngf_FL.MeasureOnce() 
		FR_dist += rngf_FR.MeasureOnce() 
		FM_dist += rngf_FM.MeasureOnce() 
		HCSR04.sleep(rngf_FM.setl_len) 	# Give time for sensors to settle 
	FL_dist /= repeats 			# +15deg dist in cm 
	FR_dist /= repeats 			# -15deg dist in cm 
	FM_dist /= repeats 			#   0deg dist in cm 
Example #10
0
'''
Created on Jul 1, 2015

@author: markos
'''

import HCSR04 as hc

if __name__ == '__main__':
    ''' trigger, echo '''
    val = hc.readvalue(23, 24)
    val = val / 1000000.00

    distance = val * 343.59 * 100
    distance = distance / 2
    distance = distance / 1000000.00
    distance = round(distance, 2)
    print "Distance : %.1f" % distance
Example #11
0
# definir o mapeamento dos pins para placa
GPIO.setmode(GPIO.BOARD)

# definir os pinos GPIO como input/'entrada'
leftSensor = 7
rightSensor = 10
GPIO.setup(leftSensor, GPIO.IN)
GPIO.setup(rightSensor, GPIO.IN)

# chamar a função para confirmar que os motores estão desligados
motores_f.Parar()
# desligar as mensagens de erro
GPIO.setwarnings(False)

while True:  # Loop principal
    if HCSR04.distance() < 15.0:
        motores_f.Parar()
        for x in range(x, 5, 1):
            print(
                'Objeto detectado em uma distância menor que 15cm. Por favor retirar da trajetoria.'
            )
        time.sleep(10)
    else:
        # se ambos os sensores estiverem desligados, desligar todos os motores
        if GPIO.input(leftSensor) == 0 and GPIO.input(rightSensor) == 0:
            motores_f.Frente_Esquerda_Off()
            motores_f.Frente_Direita_Off()
            motores_f.Tras_Esquerda_Off()
            motores_f.Tras_Direita_Off()
        # se ambos os sensores estiverem ligados, ligar ambos os motores
        if GPIO.input(leftSensor) == 1 and GPIO.input(rightSensor) == 1:
 def __init__(self, trig_pin, echo_pin):
     self.ProxSens= HCSR04.HCSR_04(trig_pin, echo_pin)
Example #13
0
from HCSR04 import *
import time
import _thread

sensor = HCSR04(trigger_pin=5, echo_pin=18)

def ultraRead():
    while(True):
        distance = sensor.distance_cm()
        print('Distance:', distance, 'cm')
        time.sleep_ms(500)

_thread.start_new_thread(ultraRead, ())