示例#1
0
def Lidar(mode):
    Lidarsensor = mp.VL53L1X()
    if mode == 0:
        Lidarsensor.start_ranging(mp.VL53L1X.SHORT_DST_MODE)
    elif mode == 1:
        Lidarsensor.start_ranging(mp.VL53L1X.MEDIUM_DST_MODE)
    elif mode == 2:
        Lidarsensor.start_ranging(mp.VL53L1X.LONG_DST_MODE)
    TOF = Lidarsensor.get_measurement()
    TOF = TOF / 10
    Lidarsensor.stop_ranging()
    Lidarsensor.close_connection()
    print("Lidar")
    return TOF
示例#2
0
    def __init__(self, fountain):

        self.fountain = fountain
        self.temp_distance_to_water_mm = 0

        self.water_level_state = WaterLevelState.UNKNOWN
        self.water_depth_mm = 0
        self.state_change_notify_list = []

        self.water_level_sensor = mp.VL53L1X()
        self.water_level_sensor.setROI(6, 11, 10, 7)
        self.water_level_sensor.start_ranging(mp.VL53L1X.SHORT_DST_MODE)
        value_mm = self.water_level_sensor.get_measurement()
        if value_mm != -1:
            logger.info("water level sensor initialized. Value: %s" % value_mm)
            # Update the depth first-time before we complete initalization
            self.__set_depth_mm(self.__calculate_water_depth_mm())
            monitor_water_level_thread = threading.Thread(
                target=self.__monitor_water_level)
            monitor_water_level_thread.daemon = True
            monitor_water_level_thread.start()

            # Docs: https://schedule.readthedocs.io/en/stable/
            # DOcs: https://github.com/dbader/schedule
            schedule.every().hour.at(":00").do(self.__log_data)

            # schedule.every().minute.do(self.__log_data)
            # schedule.every().hour.do(job)
            # schedule.every().day.at("10:30").do(job)
            # schedule.every(5).to(10).minutes.do(job)
            # schedule.every().monday.do(job)
            # schedule.every().wednesday.at("13:15").do(job)
            # schedule.every().minute.at(":17").do(job)

            self.__start_schedule_thread()

        else:
            logger.error("water level sensor initialize error")
示例#3
0
def main():
    #    constants
    MAX_DST = 250
    width = 800
    height = 480
    font_size = 64
    text_color = (255, 255, 255)
    text_pos = (10, 60)
    message = "Distance: {} cm"
    font_name = ""
    font = pygame.font.match_font(pygame.font.get_fonts()[0])

    rect_color = (255, 0, 0)

    background_color = (0, 0, 0)

    #    initialize pygame
    pygame.init()

    pygame.mouse.set_visible(False)

    screen = pygame.display.set_mode((width, height))
    pygame.display.set_caption('distance sensor')

    #    initialize the sensor
    sensor = mp.VL53L1X()
    sensor.start_ranging(mp.VL53L1X.MEDIUM_DST_MODE)

    #    main loop
    do_main = True
    while do_main:
        pressed = pygame.key.get_pressed()
        pygame.key.set_repeat()
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                do_main = False

            if pressed[pygame.K_ESCAPE]:
                do_main = False

            if event.type is pygame.KEYDOWN and event.key == pygame.K_f:
                if screen.get_flags() & pygame.FULLSCREEN:
                    pygame.display.set_mode((width, height), )
                else:
                    pygame.display.set_mode((width, height), pygame.FULLSCREEN)

        screen.fill(background_color)

        dst = int(sensor.get_measurement() / 10)
        rect = ((0, height / 2), (dst / MAX_DST * width, height / 4))
        pygame.draw.rect(screen, rect_color, rect)

        dst = MAX_DST + 1 if dst > MAX_DST or dst == 0 else dst
        format_msg = "> {}".format(
            MAX_DST) if dst > MAX_DST or dst == 0 else dst
        text(screen, font, font_size, text_color, text_pos,
             message.format(format_msg))

        pygame.display.update()

        #time.sleep(0.1)

    pygame.quit()
示例#4
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 12 18:23:18 2019

@author: Leonardo La Rocca
"""

import melopero_vl53l1x as mp

sensor = mp.VL53L1X()
sensor.start_ranging(mp.VL53L1X.MEDIUM_DST_MODE)

for i in range(100):
    print(sensor.get_measurement())

sensor.stop_ranging()
sensor.close_connection()
        
    tempVal = abs(inp)
    outp = str(tempVal)
    
    #This functions pads zeros to the start of inp till it reaches maxlength
    if len(str(tempVal)) < maxlength:
        for i in range(maxlength - len(str(tempVal))):
            outp = "0" + outp
    
    #THis is all done so that when the package is transmitted, the elements can have uniform string length
    return polarity + outp
    
#=========================================
#==========TIME OF FLIGHT SENSOR==========
#=========================================
LS = mp.VL53L1X()

def Lidar(sensr):
    #Code for obtaining the distance from the timeof flight sensor
     sensr.start_ranging(mp.VL53L1X.LONG_DST_MODE)
     TOF = sensr.get_measurement()
     TOF = TOF/10
     sensr.stop_ranging()
     #sensr.close_connection()
     return TOF

#==================================
#==========SONAR RETRIEVE==========
#==================================
def Sonar(TRIG, ECHO, LKV):
    #Code for obtaining the distance from the sonar sensor