|
| 1 | +## Introduction ## |
| 2 | + |
| 3 | +Provide an interface to the SlamTec RPLidar A1. |
| 4 | + |
| 5 | +Eventual goal is for the single module to work with both Linux (via /dev/USB0, etc) and CircuitPython (via a UART instance) |
| 6 | + |
| 7 | +## Usage Example ## |
| 8 | + |
| 9 | + import os |
| 10 | + from math import cos, sin, pi, floor |
| 11 | + import pygame |
| 12 | + from adafruit_circuitpython_rplidar import RPLidar |
| 13 | + |
| 14 | + # Set up pygame and the display |
| 15 | + os.putenv('SDL_FBDEV', '/dev/fb1') |
| 16 | + pygame.init() |
| 17 | + lcd = pygame.display.set_mode((320,240)) |
| 18 | + pygame.mouse.set_visible(False) |
| 19 | + lcd.fill((0,0,0)) |
| 20 | + pygame.display.update() |
| 21 | + |
| 22 | + # Setup the RPLidar |
| 23 | + PORT_NAME = '/dev/ttyUSB0' |
| 24 | + lidar = RPLidar(None, PORT_NAME) |
| 25 | + |
| 26 | + # used to scale data to fit on the screen |
| 27 | + max_distance = 0 |
| 28 | + |
| 29 | + def process_data(data): |
| 30 | + # Do something useful with the data |
| 31 | + pass |
| 32 | + |
| 33 | + scan_data = [0]*360 |
| 34 | + |
| 35 | + try: |
| 36 | + print(lidar.get_info()) |
| 37 | + for scan in lidar.iter_scans(): |
| 38 | + for (_, angle, distance) in scan: |
| 39 | + scan_data[min([359, floor(angle)])] = distance |
| 40 | + process_data(scan_data) |
| 41 | + |
| 42 | + except KeyboardInterrupt: |
| 43 | + print('Stoping.') |
| 44 | + lidar.stop() |
| 45 | + lidar.disconnect() |
| 46 | + |
| 47 | + |
| 48 | +## Contributing ## |
| 49 | + |
| 50 | +Contributions are welcome! Please read our [Code of Conduct](https://github.com/adafruit/Adafruit_circuitpython_CircuitPython_RPLIDAR/blob/master/CODE_OF_CONDUCT.md) |
| 51 | +before contributing to help this project stay welcoming. |
0 commit comments