예제 #1
0
def rover_initialize():

    global RMotor, LMotor, MotorWake, AtmoSensor, LeftEye, RightEye, Accelo, Gyro

    # Initializing I2C for sensors
    i2c = I2C(board.SCL, board.SDA)

    # Initializing Gyro and Magnetometer
    Accelo = FXOS8700(i2c)
    Gyro = FXAS21002C(i2c)

    # Initializing Atmo Sensor
    AtmoSensor = SI7021(i2c)

    # Annoyingly it looks like the HCSR04 Libary uses DPI Pin Numbering instead
    # of Broadcom.  Check here https://pinout.xyz/pinout/pin18_gpio24
    # Read about speed of sound calibration in doc
    # BCM 23 & 24 are DPI 19 and 20
    LeftEye = Echo(23, 24)
    RightEye = Echo(17, 27)

    MotorWake = LED(17)
    MotorWake.off()

    # Args are GPIO Pins for forward, backward, and motor controller sleep
    RMotor = Motor(20, 21)  # Motor(19, 26, 13)
    LMotor = Motor(19, 26)  # Motor(20, 21, 13)

    return True
예제 #2
0
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()
예제 #3
0
#!/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)
예제 #4
0
# Import necessary libraries.
from time import sleep

from Bluetin_Echo import Echo  # https://github.com/MarkAHeywood/Bluetin_Python_Echo

# Define pin constants
TRIGGER_PIN_1 = 27
ECHO_PIN_1 = 17
TRIGGER_PIN_2 = 22
ECHO_PIN_2 = 23

# Initialise two sensors.
echo = [Echo(TRIGGER_PIN_1, ECHO_PIN_1), Echo(TRIGGER_PIN_2, ECHO_PIN_2)]


def main():
    sleep(0.1)
    try:
        while True:

            result1 = echo[0].read('cm', 3)
            result2 = echo[1].read('cm', 3)
            print('C1: {}cm\tC2: {}cm'.format(round(result2, 1),
                                              round(result1, 1)))

    except KeyboardInterrupt:
        echo[0].stop()
        print("Measurement stopped by User")


if __name__ == '__main__':
예제 #5
0
# Import necessary libraries.
from time import sleep

from Bluetin_Echo import Echo

import paho.mqtt.publish as publish

MQTT_SERVER = "localhost"
MQTT_PATH = "test_channel"

# Define pin constants
TRIGGER_PIN_1 = 23
ECHO_PIN_1 = 24

# Initialise two sensors.
echo = [Echo(TRIGGER_PIN_1, ECHO_PIN_1)]


def main():
    sleep(0.1)
    for counter in range(1, 2):
        for counter2 in range(0, len(echo)):
            result = echo[counter2].read('cm', 3)
            print(result)
            result2 = int(result)
            if result2 > 0:
                publish.single(MQTT_PATH,
                               'coco distance:' + str(result2),
                               hostname=MQTT_SERVER)

예제 #6
0
# https://github.com/MarkAHeywood/Bluetin_Python_Echo
from Bluetin_Echo import Echo  # HCSR04 Module Uses BCM Pins!
from time import sleep

# BCM 23 & 24 are DPI 19 and 20
DistSense = Echo(23, 24)


def report_dist():
    samples = 4
    try:
        while True:
            d = DistSense.read('cm', samples)
            print(d, 'cm')
            sleep(.5)
    except KeyboardInterrupt:
        pass


report_dist()

DistSense.stop()

print('End Of File.')
예제 #7
0
	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)
예제 #8
0
ent_trig_pin = 23
ent_echo_pin = 24
trig_pin = [7, 16, 25]
echo_pin = [1, 20, 8]
led = 21

GPIO.setmode(GPIO.BCM)
GPIO.setup(led, GPIO.OUT)
GPIO.setwarnings(False)

status = [0] * len(trig_pin)
prev_status = [0] * len(trig_pin)
ent_status = 0
echo = []

ent_echo = Echo(ent_trig_pin, ent_echo_pin, speed_of_sound)
for i in range(len(trig_pin)):
    echo.append(Echo(trig_pin[i], echo_pin[i], speed_of_sound))


def led_blink():
    for x in range(0, 2):
        GPIO.output(led, True)
        time.sleep(0.3)
        GPIO.output(led, False)
        time.sleep(0.1)


def log_event(event, event_detail):
    client.publish(pub_topic, str(event) + ";" + event_detail)
    cur = mdb.cursor()
예제 #9
0
from quart import websocket, Quart, render_template
from functools import wraps
from Bluetin_Echo import Echo
import time
import asyncio

app = Quart(__name__)
Pins = ((17, 18), (23, 22))
speed = 320
samples = 5
Distance = [Echo(*pin, speed) for pin in Pins]
print(Distance[0].read('cm'))
clients = set()


class Dummy:
    def done(self):
        return True


task = Dummy()


async def SendtoWebsocket():
    while clients:  #while clients are connected (if 0 < websockets in the clients set)
        reads = [round(d.read('cm', samples), 1)
                 for d in Distance]  #read data from the two sensors
        [
            await websocket.send(str(reads)) for websocket in clients
        ]  #loops through all webscokets open and sends the data from the sensors
        await asyncio.sleep(
예제 #10
0
# video
fc = 0
# tolerance count is the minimum number of frames a face can be absent from
# center
tc = 5
# Create display object
s = ST7920()
# Initialize mlx90614 address
thermometer_address = 0x5a
# Create temperature sensor instance
temp = MLX90614(thermometer_address)
#defining values for ultrasonic sensor
TRIGGER_PIN = 8
ECHO_PIN = 7
speed_of_sound = 340
echo = Echo(TRIGGER_PIN, ECHO_PIN, speed_of_sound)
# Initializing servo motor
GPIO.setmode(GPIO.BOARD)
servo = 4  # Pin to which servo is connected
GPIO.setup(servo, GPIO.OUT)
pwm = GPIO.PWM(servo, 50)
pwm.start(0)
# Initializing dc pump
GPIO.setmode(GPIO.BOARD)
pump_pin = 21
GPIO.setup(pump_pin, GPIO.OUT)
GPIO.output(pump_pin, False)
# Initializing ir sensor
GPIO.setmode(GPIO.BOARD)
ir_sensor = 26
GPIO.setup(ir_sensor, GPIO.IN)
예제 #11
0
gapmin = 20
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)
예제 #12
0
#!/usr/bin/env python3

from time import sleep
from Bluetin_Echo import Echo
""" Define GPIO pin constants """
TRIGGER_PIN = 17
ECHO_PIN = 18
""" Calibrate sensor with initial speed of sound m/s value """
SPEED_OF_SOUND = 343
""" Initialise Sensor with pins, speed of sound. """
echo = Echo(TRIGGER_PIN, ECHO_PIN, SPEED_OF_SOUND)


def main():
    """
	Test class properties and methods.
	"""

    print('\n+++++ Properties +++++\n')
    """
	Check that the sensor is ready to operate.
	"""
    print('Sensor ready? {}'.format(echo.is_ready))
    sleep(0.06)
    print('Sensor ready? {}'.format(echo.is_ready))
    """
	You can adjust the speed of sound to fit environmental conditions.
	"""
    speed = echo.speed
    print('Speed of sound Setting: {}m/s'.format(speed))
    echo.speed = speed
예제 #13
0
from math import *
from Bluetin_Echo import Echo

TRIGGER_PIN_1 = 5
ECHO_PIN_1 = 6
TRIGGER_PIN_2 = 20
ECHO_PIN_2 = 21
TRIGGER_PIN_3 = 23
ECHO_PIN_3 = 24
TRIGGER_PIN_4 = 26
ECHO_PIN_4 = 25
TRIGGER_PIN_5 = 22
ECHO_PIN_5 = 27

echo = [
    Echo(TRIGGER_PIN_1, ECHO_PIN_1),
    Echo(TRIGGER_PIN_2, ECHO_PIN_2),
    Echo(TRIGGER_PIN_3, ECHO_PIN_3),
    Echo(TRIGGER_PIN_4, ECHO_PIN_4),
    Echo(TRIGGER_PIN_5, ECHO_PIN_5)
]

distance = [0, 0, 0, 0, 0]
for sensor in range(0, len(echo)):
    distance[sensor] = echo[sensor].read('cm', 3)

pi_hw = pigpio.pi()
pi_hw.set_mode(13, pigpio.OUTPUT)
pi_hw.set_mode(18, pigpio.OUTPUT)

LEFT_MOTOR_PIN = 13
예제 #14
0
import RPi.GPIO as GPIO
import paho.mqtt.publish as publish
import json
GPIO.setwarnings(False)

from Bluetin_Echo import Echo

# Define pin constants
TRIGGER_PIN_1 = 26
ECHO_PIN_1 = 13
TRIGGER_PIN_2 = 18
ECHO_PIN_2 = 24

# Initialise two sensors.
echo = {
    ECHO_PIN_1: Echo(TRIGGER_PIN_1, ECHO_PIN_1),
    ECHO_PIN_2: Echo(TRIGGER_PIN_2, ECHO_PIN_2)
}


def main():
    sleep(0.1)


while True:
    publishData = {}
    sleep(5)
    for counter2 in echo:
        result = echo[counter2].read('cm', 3)
        publishData[counter2] = round(result, 2)
예제 #15
0
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)
예제 #16
0
"""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()
예제 #17
0
#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)
예제 #18
0
import os  #importing os library so as to communicate with the system
import time  #importing time library to make Rpi wait because its too impatient
os.system("sudo pigpiod")  #Launching GPIO library
time.sleep(
    1
)  # As i said it is too impatient and so if this delay is removed you will get an error
import pigpio  #importing GPIO library
from Bluetin_Echo import Echo

ESC = 4  #Connect the ESC in this GPIO pin
triggerPin = 27
echoPin = 17

pi = pigpio.pi()
pi.set_servo_pulsewidth(ESC, 0)
echo = Echo(triggerPin, echoPin, 340)

max_value = 2000  #change this if your ESC's max value is different or leave it be
min_value = 700  #change this if your ESC's min value is different or leave it be
#print ("For first time launch, select calibrate")
#print ("Type the exact word for the function you want")
#print ("calibrate OR manual OR control OR arm OR stop")


def manual_drive(
):  #You will use this function to program your ESC if required
    print(
        "You have selected manual option so give a value between 0 and you max value"
    )
    while True:
        inp = input()