Exemple #1
0
    def main(self, config, log, local):
        from adafruit_rplidar import RPLidar

        from math import cos, sin, radians

        while True:
            try:
                lidar = RPLidar(None, config['lidarPort'])
                lidar.set_pwm(config['lidarSpeed'])

                try:  # Rear LIDAR failure will not impact main LIDAR
                    import adafruit_tfmini
                    import serial
                    uart = serial.Serial("/dev/ttyS0", timeout=1)
                    rearLidar = adafruit_tfmini.TFmini(uart)
                    rearLidar.mode = adafruit_tfmini.MODE_SHORT
                except Exception as exception:
                    log["exceptions"].append(str(exception))
                while True:
                    for scan in lidar.iter_scans():
                        local.scan = scan
                        try:
                            rearScan = (rearLidar.distance -
                                        config['rearLidarOverhang'],
                                        rearLidar.strength, rearLidar.mode)
                            if rearScan[0] <= 0:
                                rearScan = (None, rearScan.strength,
                                            rearScan.mode)
                            local.rearScan = rearScan
                        except Exception as exception:
                            log["exceptions"].append(str(exception))
            except Exception as exception:
                log["exceptions"].append(str(exception))
                if type(
                        exception
                ) == KeyboardInterrupt:  # This might not work because it runs it a separate process.
                    lidar.stop()
                    lidar.disconnect()
Exemple #2
0
## First, Do pip3 install adafruit-circuitpython-tfmini

import time
# import board  # comment this out if using pyserial
# import busio  # comment this out if using pyserial
import adafruit_tfmini

## Use hardware uart
# uart = busio.UART(board.TX, board.RX)

## Or, you can use pyserial on any computer
import serial
uart = serial.Serial("/dev/ttyS2", timeout=1)

## Simplest use, connect with the uart bus object
tfmini = adafruit_tfmini.TFmini(uart)

## You can put in 'short' or 'long' distance mode
tfmini.mode = adafruit_tfmini.MODE_SHORT
print("Now in mode", tfmini.mode)

while True:
    print("Distance: %d cm (strength %d, mode %x)" %
          (tfmini.distance, tfmini.strength, tfmini.mode))
    time.sleep(0.1)