def laser():
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    GPIO.setup(21,GPIO.OUT)
    GPIO.setup(20,GPIO.OUT)
    GPIO.setup(16,GPIO.OUT)
    GPIO.setup(12,GPIO.OUT)
    GPIO.output(21,GPIO.LOW)
    GPIO.output(20,GPIO.LOW)
    GPIO.output(12,GPIO.LOW)
    GPIO.output(16,GPIO.LOW)
    GPIO.output(21,GPIO.HIGH)
    sleep(0.1)
    i2c = busio.I2C(board.SCL, board.SDA)
    LD = adafruit_vl6180x.VL6180X(i2c)
    LD.set_address(i2c,0x50)
    GPIO.output(20,GPIO.HIGH)
    sleep(0.1)
    LAD = adafruit_vl6180x.VL6180X(i2c)
    LAD.set_address(i2c,0x51)
    GPIO.output(16,GPIO.HIGH)
    sleep(0.1)
    LAS = adafruit_vl6180x.VL6180X(i2c)
    LAS.set_address(i2c,0x52)
    GPIO.output(12,GPIO.HIGH)
    sleep(0.1)
    LS = adafruit_vl6180x.VL6180X(i2c)
    LS.set_address(i2c,0x53)
예제 #2
0
 def __init__(self, i2c_port=1):
     i2c = I2C(i2c_port)  # Create I2C bus.
     #self.sensor_interface = sensor_interface.VL6180X(i2c) # Create sensor instance.
     self.sensor_interface = adafruit_vl6180x.VL6180X(
         i2c)  # Create sensor instance.
     self.handle_exit_signals()
     time.sleep(2)
예제 #3
0
def test_sensor_status():
    i2c = busio.I2C(board.SCL, board.SDA)
    sensor = adafruit_vl6180x.VL6180X(i2c)
    assert isinstance(sensor, adafruit_vl6180x.VL6180X)
    # See the vl6180x datasheet (Table 12)
    # https://www.st.com/resource/en/datasheet/vl6180x.pdf
    # The error codes and description:
    # 0     - No Error
    # 1-5   - System error
    # 6     - Early convergent estimate failed
    # 7     - System did not converge before max convergence time limit
    # 8     - Ignore threshold check failed
    # 9-10  - Not used
    # 11    - Ambient conditions to high.  Measurement not valid.
    # 12-14 - Range < 0.  If the target is very close (0-10mm) and the offset
    #         is not correctly calibrated it could lead to a small
    #         negative value
    # 13/15 - Range value out of range. This occurs when the
    #         target is detected by the device but is placed at a
    #         high distance (> 200mm) resulting in internal
    #         variable overflow.
    # 16    - Distance filtered by Wrap Around Filter (WAF).
    #         Occurs when a high reflectance target is
    #         detected between 600mm to 1.2m
    # 17    - Not used
    # 18    - Error returned by
    #         VL6180x_RangeGetMeasurementIfReady()
    #         when ranging data is not ready.
    assert 0 == sensor.range_status
예제 #4
0
    def __init__(self, serial_connection, N_FILTER=30):

        try:

            i2c = busio.I2C(board.SCL, board.SDA)
            self.sensor = adafruit_vl6180x.VL6180X(i2c)
        except ValueError:
            from ..dummy import dummy_range_sensor as sensor
            self.sensor = sensor
            serial_connection.NO_CONNECTION = "Tank sensor niet verbonden"
        except ModuleNotFoundError:
            from ..dummy import dummy_range_sensor as sensor
            self.sensor = sensor
            serial_connection.NO_CONNECTION = "Tank sensor niet verbonden"

        #Main loop print
        self.N_FILTER = N_FILTER  #pylint: disable=invalid-name

        self.raw_data_queue = [self.sensor.range] * self.N_FILTER

        D_TANK = 0.0335  #pylint: disable=invalid-name
        self.A_TANK = (3.1416 * (D_TANK / 2)**2) * 1e3  #pylint: disable=invalid-name
        self.V0 = 110  #pylint: disable=invalid-name

        self.corr = 0
예제 #5
0
    def _initialize_hardware(self):
        """
        Initializes the widget hardware.
        """
        # Import
        try:
            import board
            import busio
            import adafruit_vl6180x
        except Exception as ex:
            logging.error(
                '\n   *** ERROR importing Adafruit libraries: {}'.format(
                    ex, ), )

            # Things failed, so we must be running locally, not on a widget;
            # don't bother hooking up the VL6180X
            return

        # Initialize I2C and VL6180X
        try:
            i2c = busio.I2C(board.SCL, board.SDA)
            self._sensor = adafruit_vl6180x.VL6180X(i2c)
        except Exception as ex:
            logging.error(
                '\n   *** ERROR initializing I2C/LSM303: {}'.format(ex), )

        self._initialize_id_led()
예제 #6
0
	def on_activate(self):
		''' Init the device hardware
		'''
	
		# Create I2C bus.
		self.i2c = busio.I2C(board.SCL, board.SDA)
	 
		# Create sensor instance.
		self.sensor = adafruit_vl6180x.VL6180X(self.i2c)
예제 #7
0
def test_lux():
    i2c = busio.I2C(board.SCL, board.SDA)
    sensor = adafruit_vl6180x.VL6180X(i2c)
    lux = sensor.read_lux(adafruit_vl6180x.ALS_GAIN_1)
    print('\n\ntest_lux(): Light (1x gain): {0}lux'.format(lux))
    # https://www.st.com/resource/en/datasheet/vl6180x.pdf
    # Table 1, Technical specification
    # < 1 Lux up to 100 kLux(2) 16-bit output(3) 8 manual gain settings
    assert (0 <= lux <= 100000)
예제 #8
0
    def __init__(self):
        # Define DAQ
        self._daq = q2usb()
        print("DAQ Initialized")

        # Configure ToF sensor
        self._i2c = busio.I2C(board.SCL, board.SDA)
        self._tof_sensor = adafruit_vl6180x.VL6180X(self._i2c)
        print("ToF sensor Initialized")
예제 #9
0
 def startTOFSensor(self):
     self.loginfo("establishing connection with tof sensor")
     try:
         i2c = busio.I2C(board.SCL, board.SDA)
         self.tof_sensor = adafruit_vl6180x.VL6180X(i2c)
         self.tof_sensor_online = True
     except (ValueError, OSError) as e:
         self.loginfo('Could not connect to TOF sensor')
         print(e)
         self.tof_sensor_online = False
예제 #10
0
def getRange():
    OFFSET = 19
    i2c = busio.I2C(board.SCL, board.SDA)
    sensor = adafruit_vl6180x.VL6180X(i2c)
    measurement = sensor.range - OFFSET
    currentDate = datetime.datetime.now()
    ##print('{0}mm'.format(measurement))
    sensorStr = json.dumps(
        {currentDate.strftime("%Y-%m-%d %H:%M:%S"): measurement})
    #print(sensorStr)
    return sensorStr
예제 #11
0
    def __init__(self):
        # self.camera = PiCamera()
        # self.camera.rotation = 180
        #
        i2c = busio.I2C(board.SCL, board.SDA)

        try:
            self.vl53l0x = adafruit_vl53l0x.VL53L0X(i2c, address=28)
        except:
            input('Unplug VL6180 (top Time of Flight sensor)')
            # self.change_addr(i2c)
            self.vl53l0x = self.change_addr(i2c)
            input('Plug it back in and press enter to continue. ')

        try:
            self.vl6180X = adafruit_vl6180x.VL6180X(i2c)
        except:
            input('Plug in the VL6180x Sensor. Press enter to continue.')
            self.vl6180X = adafruit_vl6180x.VL6180X(i2c)
        time.sleep(0.25)
    def __init__(self):

        ## Arm and Hand Degrees ##
        self.armAngle = self.oldArmDegree = 0.0
        self.handAngle = self.oldHandDegree = -PI / 6

        self.maxArmAngle = PI / 2
        self.minArmAngle = 0

        self.maxHandAngle = 0
        self.minHandAngle = -PI / 2

        ## Robot Body ##
        self.robotWidth = 30
        self.robotHeight = 20
        self.robotPos = 20

        self.minRailPos = 0
        self.maxRailPos = 110

        ## Robot Arm ##
        self.armLength = 50

        ## Robot Hand ##
        self.handLength = 60

        self.positions = [20]

        i2c = busio.I2C(board.SCL, board.SDA)
        hat = adafruit_pca9685.PCA9685(i2c)
        self.kit = ServoKit(
            channels=16)  #, address=0x40, reference_clock_speed=25000000)
        self.sensor = adafruit_vl6180x.VL6180X(i2c)

        # Define the Reset Pin
        oled_reset = digitalio.DigitalInOut(board.D12)

        # Change these
        # to the right size for your display!
        WIDTH = 128
        HEIGHT = 32  # Change to 64 if needed
        BORDER = 5

        spi = busio.SPI(board.SCK, MOSI=board.MOSI)
        reset_pin = digitalio.DigitalInOut(board.D12)  # any pin!
        cs_pin = digitalio.DigitalInOut(board.D5)  # any pin!
        dc_pin = digitalio.DigitalInOut(board.D6)  # any pin!
        self.oled = adafruit_ssd1306.SSD1306_SPI(128, 32, spi, dc_pin,
                                                 reset_pin, cs_pin)

        # Load default font.
        self.font = ImageFont.load_default()
예제 #13
0
  def __init__(self, sensor):

    # Initialize I2C bus and sensor.
    self.i2c = busio.I2C(board.SCL, board.SDA)
    if sensor == 'vl53':
      self.sensor = adafruit_vl53l0x.VL53L0X(self.i2c)

    elif sensor == 'vl61':
      self.sensor = adafruit_vl6180x.VL6180X(self.i2c)


    if self.sensor:

      # set timing budget in milliseconds
      self.sensor.measurement_timing_budget = 10000
 def Light_Sensor(Activated, PIN):
     if Activated == True:
         try:
             GPIO.setmode(GPIO.BCM)
             GPIO.setwarnings(False)
             GPIO.setup(PIN, GPIO.OUT)
             GPIO.output(PIN, GPIO.HIGH)
             i2c = busio.I2C(board.SCL, board.SDA)
             sensor = adafruit_vl6180x.VL6180X(i2c)
             lux = sensor.read_lux(adafruit_vl6180x.ALS_GAIN_1)
             time.sleep(.1)
             GPIO.output(PIN, GPIO.LOW)
             time.sleep(.1)
             return lux
         except ValueError:
             return 100
def distancePub():
    pub = rospy.Publisher('obstacle', Float32, queue_size=10)
    rospy.init_node('distance', anonymous=True)
    rate = rospy.Rate(10)  # 10hz

    # Create I2C bus.
    i2c = busio.I2C(board.SCL, board.SDA)

    # Create sensor instance.
    sensor = adafruit_vl6180x.VL6180X(i2c)

    while not rospy.is_shutdown():
        range_mm = sensor.range
        rospy.loginfo(range_mm)
        pub.publish(range_mm)
        rate.sleep()
예제 #16
0
    def setup(self, multiplex_handler, right_sensor_channel):

        # IN1 - Forward Drive
        self.L298_LEFT_PWM_FORWARD_PIN = 26

        #IN2 - Reverse Drive
        self.L298_LEFT_PWM_REVERSE_PIN = 19

        self.forwardLeft = PWMOutputDevice(self.L298_LEFT_PWM_FORWARD_PIN,
                                           True, 0, 1000)
        self.reverseLeft = PWMOutputDevice(self.L298_LEFT_PWM_REVERSE_PIN,
                                           True, 0, 1000)

        self.i2c = multiplex_handler.getI2C()
        self.sensor = adafruit_vl6180x.VL6180X(self.i2c)

        self.multiplex_handler = multiplex_handler
        self.right_sensor_channel = right_sensor_channel
예제 #17
0
    def __init__(self, port, threshold=25, address_offset=0b000, address_default=0x70):
        """
        Initialize a Lidar Sensor
        :param port: Port the lidar sensor is connected to on the i2c multiplexer
        :param threshold: Threshold distance, object is considered to be detected if distance is less
        than or equal to the threshold distance
        :param address_offset: i2c address offset, defaults to 0b000
        :param address_default: i2c address default of the i2c multiplexer, defaults to 0x70
        """
        self.port = port
        self.threshold = threshold
        self.delay_time = 0.001
        self.address = address_offset + address_default
        self.detected = False
        self.last_read = self.threshold + 10

        self.i2c_smbus = Bus(1)
        self.port_select(port=self.port)
        self.i2c_circuit_python = busio.I2C(board.SCL, board.SDA)  # creates circuit python i2c instance
        self.sensor = adafruit_vl6180x.VL6180X(self.i2c_circuit_python)  # creates sensor instance on circuit python i2c
예제 #18
0
# Simple demo of the VL6180X distance sensor.
# Will print the sensed range/distance every second.
import time

import board
import busio

import adafruit_vl6180x

# Initialize I2C bus and sensor.
i2c = busio.I2C(board.SCL, board.SDA)
vl61 = adafruit_vl6180x.VL6180X(i2c)

# Optionally adjust the measurement timing budget to change speed and accuracy.
vl61.measurement_timing_budget = 10000

# Main loop will read the range and print it every second.
while True:
    try:
        r = vl61.range
        if r:
            print('Range: {0}mm'.format(r))
    except:
        print('fail, retry..')
    time.sleep(1.0)
예제 #19
0
from Angle_to_Dist import dist_angle_foot
from Inv_Kinematics import InvKine_2D
from Inve import inverseKin2D
from big_leg import  Knee_Angle_To_Distance, Thigh_Angle_To_Distance

#Constants
#----------------------------------------------------------------------------
#I2C Bus Initialization
i2c = busio.I2C(board.SCL, board.SDA, frequency=5000000)

#MUX Object
tca = adafruit_tca9548a.TCA9548A(i2c)

#Sensors to be MUXed
#mpu = adafruit_mpu6050.MPU6050(tca[7])
tof_2 = adafruit_vl6180x.VL6180X(tca[7])
tof_1 = adafruit_vl6180x.VL6180X(tca[1])

#Calibrate Motor
#--------------------------------------------------------------
print("finding an odrive...")
my_drive = odrive.find_any(serial_number = "20623599524B")
time.sleep(0.1)

# # Full Calibration
print("starting calibration...")
my_drive.axis0.requested_state = AXIS_STATE_FULL_CALIBRATION_SEQUENCE
my_drive.axis1.requested_state = AXIS_STATE_FULL_CALIBRATION_SEQUENCE

# # Velocity Config
my_drive.axis0.controller.config.vel_limit = 130000
예제 #20
0
import board
import busio
#install beforehand with sudo pip3 install adafruit-circuitpython-vl6180x
import adafruit_vl6180x

#add adafruit multiplexer library
import adafruit_tca9548a
#install pip3 install adafruit-circuitpython-tca9548a

# Create I2C bus. (careful with 2 TOFs)
i2c = busio.I2C(board.SCL, board.SDA)

# Create the TCA9548A object and give it the I2C bus
tca = adafruit_tca9548a.TCA9548A(i2c)

sensor_tof1 = adafruit_vl6180x.VL6180X(tca[2])
sensor_tof2 = adafruit_vl6180x.VL6180X(tca[3])

# Create sensor instance.

# Main loop prints the range (and lux) every 0.25s
while True:
    # Read the range in millimeters and print it.
    range_mm_tof1 = sensor_tof1.range
    range_mm_tof2 = sensor_tof2.range
    print('Range TOF1: {0}mm'.format(range_mm_tof1))
    print('Range TOF2: {0}mm'.format(range_mm_tof2))

    # Delay for a second.
    time.sleep(0.250)
예제 #21
0
def search_haltesignal(tof_measurement_timeout_millis=310,
                       tof1_port=0,
                       tof1_threshold_max_distance_mm=170,
                       tof1_treshold_min_distance_mm=100,
                       tof2_port=1,
                       tof2_threshold_max_distance_mm=180,
                       tof2_treshold_min_distance_mm=100):
    """Searches Object
    
    Keyword Arguments:
    
    Returns:
        Boolean - Erkannt oder nicht
    """
    logger.info("DoubleTOF Check called (100% validated)")

    #TOF Port zuweisung
    global sensor_tof1, sensor_tof2, adafruit_vl6180x, tca

    # sensor_tof1 = adafruit_vl6180x.VL6180X(tca[int(tof1_port)])
    # sensor_tof2 = adafruit_vl6180x.VL6180X(tca[int(tof2_port)])
    sensor_tof1 = adafruit_vl6180x.VL6180X(tca[0])
    sensor_tof2 = adafruit_vl6180x.VL6180X(tca[1])

    #Calibrating TOFS
    calibrate_tofs()

    ##########################################
    # Measure Distance till Treshold reached #
    ##########################################

    #Init with basic values
    measured_distance = 666
    measure_time = 0
    treshold_tof1_reached_counter = 0  #success if 3 times under the treshold distance
    treshold_tof2_reached_counter = 0  #success if 3 times under the treshold distance

    while (measure_time <= tof_measurement_timeout_millis):
        measured_distance_tof1 = tof1_distanzmessung()
        measured_distance_tof2 = tof2_distanzmessung()

        measure_time += 1

        #Check Distanz1 Tof1 (etwas erkannt?)
        if (measured_distance_tof1 <= tof1_threshold_max_distance_mm
                and treshold_tof1_reached_counter < 3):
            treshold_tof1_reached_counter += 1
        elif (treshold_tof1_reached_counter >= 3):
            logger.info("[TOF1]: Signal 3 mal unter Treshold, erkannt!")
            #STOP Train
            mc.uart_send_stop()
            break

        #Check Distanz2 Tof2 (etwas erkannt?)
        if (measured_distance_tof2 <= tof2_threshold_max_distance_mm
                and treshold_tof2_reached_counter < 3):
            treshold_tof2_reached_counter += 1
        elif (treshold_tof2_reached_counter >= 3):
            logger.info("[TOF2]: Signal 3 mal unter Treshold, erkannt!")
            #STOP Train
            mc.uart_send_stop()
            break

    #########################################
    # Return result (erkannt oder Timeout?) #
    #########################################

    if (treshold_tof1_reached_counter >= 3
            or treshold_tof2_reached_counter >= 3):
        logger.info("Haltesignal erkannt, Treshold erreicht, Stop the train!")
        #stop train Signal senden!
        return True
    else:
        logger.error(
            "Timeout erreicht, Haltesignal Treshold nicht erreicht. Halte Zug an..."
        )
        mc.uart_send_stop()
        return False
예제 #22
0
def test_distance():
    i2c = busio.I2C(board.SCL, board.SDA)
    sensor = adafruit_vl6180x.VL6180X(i2c)
    print("\n\ntest_distance(): sensor range = " + str(sensor.range) + "mm")
    assert (0 < sensor.range <= 255)
예제 #23
0
LAD=20
LAS=16
LS=12
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(21,GPIO.OUT)
GPIO.setup(20,GPIO.OUT)
GPIO.setup(16,GPIO.OUT)
GPIO.setup(12,GPIO.OUT)
GPIO.output(21,GPIO.LOW)
GPIO.output(20,GPIO.LOW)
GPIO.output(12,GPIO.LOW)
GPIO.output(16,GPIO.LOW)
GPIO.output(21,GPIO.HIGH)
sleep(0.1)
i2c = busio.I2C(board.SCL, board.SDA)
LD = adafruit_vl6180x.VL6180X(i2c)
LD.set_address(i2c,0x50)
GPIO.output(20,GPIO.HIGH)
sleep(0.1)
LAD = adafruit_vl6180x.VL6180X(i2c)
LAD.set_address(i2c,0x51)
GPIO.output(16,GPIO.HIGH)
sleep(0.1)
LAS = adafruit_vl6180x.VL6180X(i2c)
LAS.set_address(i2c,0x52)
GPIO.output(12,GPIO.HIGH)
sleep(0.1)
LS = adafruit_vl6180x.VL6180X(i2c)
LS.set_address(i2c,0x53)
예제 #24
0
# Author: Michael Ruppen
import time

import board
import busio

import adafruit_vl6180x

# Create I2C bus.
i2c = busio.I2C(board.SCL, board.SDA)

# Create sensor instance.
#s = adafruit_vl6180x.VL6180X(i2c, adafruit_vl6180x.__VL6180X_I2C_SLAVE_DEVICE_ADDRESS = 0x0041)

sensor = adafruit_vl6180x._VL6180X_DEFAULT_I2C_ADDR = 0x0040
sensor1 = adafruit_vl6180x.VL6180X(i2c)
sensor1.__VL6180X_I2C_SLAVE_DEVICE_ADDRESS = 0x0040
sensor1.get_register(0x0040)
sensor_top = adafruit_vl6180x.VL6180X(i2c, 0x0029)

# sensor_bottom = adafruit_vl6180x.VL6180X(i2c, address=27)
# sensor_weight = adafruit_vl6180x.VL6180X(i2c, address=27)

# Main loop prints the range and lux every second:
while True:
    # Read the range in millimeters and print it.
    range_mm = sensor_top.range
    if (range_mm != 255):
        print("yeah got it")

    print('Range: {0}mm'.format(range_mm))
예제 #25
0
 def __init__(self):
     self.i2c = busio.I2C(board.SCL, board.SDA)
     self._address = 0x29
     self._sensor = adafruit_vl6180x.VL6180X(self.i2c, self._address)
import time
import board
import busio
import adafruit_vl6180x
import adafruit_tca9548a

#struct library (used for byte conversions)
import struct

#I2C Bus Initialization
i2c = busio.I2C(board.SCL, board.SDA, frequency=5000000)

#MUX Object
tca = adafruit_tca9548a.TCA9548A(i2c)

#Sensors to be MUXed
#mpu = adafruit_mpu6050.MPU6050(tca[7])
tof_1 = adafruit_vl6180x.VL6180X(tca[7])  #changed from [1]

while True:
    count = 0
    lst = []
    #convert to inches from mm
    mm_range = tof_1.range
    in_range = mm_range * 0.0393701
    count = count + 1
    lst.append(mm_range)
    print("Range in mm: " + str(mm_range))
    print("Range in inches: " + str(in_range))
    time.sleep(0.5)
예제 #27
0
파일: initialize.py 프로젝트: ubcbaja/eCVT
"""
Run this code first to verify that the Pi is capable of communicating with the sensor.
"""

import board
import digitalio
import busio
import adafruit_vl6180x

print(
    "Verifying that CircuitPython modules with VL6180X installed properly...")

# Create digital input
pin = digitalio.DigitalInOut(board.D4)
print("Digital IO ok!")

# Create I2C device
i2c = busio.I2C(board.SCL, board.SDA)
print("I2C ok!")

# Create SPI device
spi = busio.SPI(board.SCLK, board.MOSI, board.MISO)
print("SPI ok!")

# Create VL6180X sensor
try:
    sensor = adafruit_vl6180x.VL6180X(i2c)  # link to I2C
    print("VL6180X ok!")
except ValueError:
    print("Sensor not detected! Is an I2C device connected?")
예제 #28
0
def run_healthcheck(cargo="undefined"):
    """[Healthcheck starten]

    Arguments:
        cargo {String} -- Cargo Parameter (default: {undefined})

    Returns:
        Boolean --  True, falls Healtcheck OK.
                    False, falls Fehler beim Healthcheck (siehe Log).
    """

    print(
        "Class Healthcheck not productive yet (99 percent done, testing ausstehend)."
    )

    ##define flags for nice headers
    cpu_flag, ram_flag, sonic_flag, tof1_flag, tof2_flag, camera_flag, mc_flag, passed_flag = "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA"
    findings = 0

    #Getting CPU
    CPU_usage = getCPUuse()
    #Getting RAM
    RAM_stats = getRAMinfo()
    RAM_free = round(int(RAM_stats[2]) / 1000, 1)

    #Sollte kleiner als 10% sein
    if (float(CPU_usage) >= 10):
        logger.warn("CPU Usage too high!")
        findings += 1

    cpu_flag = CPU_usage
    logger.info("CPU Usage: %s", str(CPU_usage))

    #Sollte grösser als 300 sein
    if (RAM_free <= 300):
        logger.warn("Not enough RAM available!")
        findings += 1

    ram_flag = RAM_free
    logger.info("RAM Free: %s", str(RAM_free))

    #Get python prozesses
    python_procs = "NA"
    try:
        python_procs = get_pid("python")
        logger.warn("The follow Python-Processes are already running: ",
                    python_procs)
        findings += 1
    except:
        logger.info("No python running, good2go!")

    #Check if Camera Available
    camera_result = (subprocess.check_output(
        "vcgencmd get_camera",
        shell=True)).decode("utf-8").rstrip()  #decode and remove \n

    if ((camera_result.rsplit(" ", 2)[0].split("=", 1)[1]) == "1"
            and (camera_result.rsplit(" ", 2)[1].split("=", 1)[1]) == "1"):
        camera_flag = True
        logger.info("Camera ready! 📷")
    else:
        camera_flag = False
        logger.warn("Camera not available! �")
        findings += 1

    #Check sonic
    p = multiprocessing.Process(
        target=check_sonic,
        name="checksonic")  #remember, pass functions without ()
    p.start()
    p.join(3)

    if p.is_alive():
        logger.warn("Sonic Check takes too long")
        p.terminate()
        p.join()
        sonic_flag = False
        findings += 1
    else:
        sonic_flag = check_sonic()
        logger.info("Sonic test passed")

    #Check TOF Multiplexer
    try:
        i2c = busio.I2C(board.SCL, board.SDA)
        # Create the TCA9548A object and give it the I2C bus
        tca = adafruit_tca9548a.TCA9548A(i2c)
        logger.warn("I2C Multiplexer Device (0) Available (probably)")
        tca_flag = True
    except:
        logger.warn("I2C Multiplexer Device (0) Unavailable")
        findings += 1
        tca_flag = False

    #Check TOF 1
    try:
        i2c = busio.I2C(board.SCL, board.SDA)
        tca = adafruit_tca9548a.TCA9548A(i2c)

        sensor_tof1 = adafruit_vl6180x.VL6180X(tca[0])
        logger.info("I2C Device (1) Available")
        tof1_flag = True
    except:
        logger.warn("I2C Device (1) Unavailable")
        findings += 1
        tof1_flag = False

    #Check TOF 2
    try:
        i2c = busio.I2C(board.SCL, board.SDA)
        tca = adafruit_tca9548a.TCA9548A(i2c)

        sensor_tof2 = adafruit_vl6180x.VL6180X(tca[1])
        logger.info("I2C Device (2) Available")
        tof2_flag = True
    except:
        logger.warn("I2C Device (1) Unavailable")
        findings += 1
        tof2_flag = False

    #Check MC-COM

    #mc_flag = check_microcontroller()
    print("MC healtcheck bypassed!!")
    mc_flag = True

    if (mc_flag):
        logger.info("MC is online and well 🤖!")
    else:
        logger.warn("MC is offline!")
        findings += 1

    #Validating Findings
    if (findings > 0):
        passed_flag = False
    else:
        passed_flag = True

    logger.info("Healthcheck completed with '%s' findings", str(findings))

    #Print Header Message
    nice_headers.print_nice_headers(passed_flag, cpu_flag, ram_flag, tof1_flag,
                                    tof2_flag, sonic_flag, camera_flag,
                                    mc_flag)

    return passed_flag
예제 #29
0
     ser = serial.Serial(port, baudrate=9600, timeout=0.5)
     info = parseGPS(ser.readline())
     satelite_count = 16
 except OSError:  #Default to 0 if data not available
     info = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
     satelite_count = 0
 try:  #Try to read light sensor data
     GPIO.setmode(GPIO.BCM)
     GPIO.setwarnings(False)
     #Setup the GPIO pin number 22
     GPIO.setup(22, GPIO.OUT)
     GPIO.output(22, GPIO.HIGH)
     #Setup I2C connection
     i2c = busio.I2C(board.SCL, board.SDA)
     #Activate light sensor
     sensor = adafruit_vl6180x.VL6180X(i2c)
     #Read light sensor lux (luminosity index)
     lux = sensor.read_lux(adafruit_vl6180x.ALS_GAIN_1)
 except:  #Default to 100 if faliure to recieve data
     lux = lux
 try:  #Try to read in pitch and tilt data
     tilt = Gyroscope.GYRO(True)[0]
     pitch = Gyroscope.GYRO(True)[1]
 except OSError:  #If error set to level
     tilt = 0
     pitch = 0
 try:  #Try to go through headlight algorithm
     if ((tilt > 25) or
         (tilt < -25)):  #Blink headlights if tilt is over -25 or 25 degrees
         if Lights_on == 0:
             #Activates headlights if currently off
예제 #30
0
 def init_TOF_sensor(self, switch, address):
     switch.value = True
     time.sleep(0.05)
     sensor = adafruit_vl6180x.VL6180X(self.i2c)
     sensor.set_address(self.i2c, address)
     return sensor