LIDAR Scanner and Data Visualization in Python
Introduction
The purpose of this project was to empower novice programmers to use Python for analyzing data from microcontroller sensors placed in physical environments. It uses data collected from small LIDAR modules to generate point cloud data visualizations.
Microcontrollers, like those produced by Arduino and its derivatives, are frequently used by researchers and hobbyists to build custom sensor tools and applications. However, software for these devices tends to be written in the C++ programming language, which may be a barrier to use for non-professional software engineers.
Code for this project is open source and available here:
https://github.com/jamescoledesign/lidar-py
Small Brag: This was my final project for Python Programming for Social Science during the Fall 2023 semester at UTD. It was rated as the class favorite among all 24 final projects in the class.
Problem Statement
Emerging implementations of Python for microcontrollers, such as MicroPython [4] and CircuitPython [5], highlight an increasing interest in using high-level programming languages to control these devices. Since Python is the most widely used programming language for people who are not professional software developers [6], exposing data collected from microcontrollers via Python may expand access to low-cost hardware prototyping tools.
Methods and Materials
Microcontroller setup
- Connect microcontroller components to power and control a LIDAR module (3.3 V) and servo motors (5 V)
- Program microcontroller to scan the surrounding environment
- Get LIDAR distance measurement (cm), servo pitch (degrees), and servo yaw (degrees)
- Convert distance, pitch, and yaw from spherical coordinates to Cartesian coordinates
- Print spherical coordinates to serial monitor (via USB)
Data collection and analysis
- Read serial monitor in Python application
- Create DataFrame of spherical coordinates
- Convert spherical coordinates to point cloud
- Create point cloud data visualization
Apparatus
Results
The Python program was able to access the serial port to collect LIDAR distance measurements from the Arduino prototype.
Data was successfully converted into a point cloud and processed using PyVista, opening the possibility for robust spatial data streaming, analysis, and visualization from microcontroller sensors in Python applications.
Version 2
To address some the power limitations imposed by two servos, I moved the LIDAR module to a dedicated microcontroller and added a large capacitor to the servo circuit. I then modified my Python program to monitor two serial ports simultaneously, combining the data from each serial port into a single pandas DataFrame. These modifications dramatically increased the speed at which points can be collected.
Interactive point clouds with PyVistaQt
Different angles (brightness enhanced for web)
Version 3
For this version, I used a RPLidar A1 attached to a single servo. The Python program was able to collect and plot data from this device in much the same way by incorporating the RPLidar module. This device can collect many more points in a short amount of time than the Garmin device, but the arc of the servo and the formula for converting Cartesian coordinates to spherical coordinates still need to be adjusted to generate accurate point cloud visualizations.
Different angles (brightness enhanced for web)
Conclusions and Future Work
While Python libraries to analyze and visualize point cloud data are relatively straightforward to implement, the complexities of setting up microcontrollers with custom sensor configurations may present significant challenges for novice programmers. Nevertheless, this prototype successfully captured LIDAR data, passed the data to a Python application, and generated a point cloud. This demonstrates the possibility of integrating low-cost sensor components with open source Python libraries for data collection and analysis.
Despite the relative successes of this project, the LIDAR module initially used was limited by measurements taken in one direction. Generating point clouds that capture 3D aspects of an environment required the addition of servos to pan and tilt the LIDAR module. Adding more electrical components increased power load and reduced the efficiency of this analysis pipeline. Troubleshooting these types of problems might be a frustrating roadblock for a novice. Future work should explore alternative sensors, ways to visualize power draw on the system, and propose alternative tools and methods for generating point clouds.
Streaming data from sensors directly into Python applications may enable rapid creation of datasets to be used for machine learning (ML). Sensor data could then be interpreted using ML tools on a connected peripheral or via ML tools optimized for microcontrollers (e.g., TensorFlow Lite for Microcontrollers)[8]. Future work could allow users to label sensor data so that is useful for training ML models.
Data Used
- Data collected using the Garmin LIDAR-Lite v4 (Qwiic) module from SparkFun
- Example point cloud data from PyVista [2,3]
- Apparatus design inspired by Charles Grassin [1] and Travis Ledo [7]. Code for spherical coordinate conversion was copied from Charles Grassin’s open source project.
References
- Charles Grassin. 3D Lidar Scanner. Charles’ Labs. Retrieved November 14, 2023 from https://charleslabs.fr/en/project-3D+Lidar+Scanner
- PyVista. 2023. Create Point Cloud. PyVista Documentation. Retrieved November 14, 2023 from https://docs.pyvista.org/version/stable/examples/00-load/create-point- cloud.html#sphx-glr-examples-00-load-create-point-cloud-py
- C. Sullivan and Alexander Kaszynski. 2019. PyVista: 3D plotting and mesh analysis through a streamlined interface for the Visualization Toolkit (VTK). JOSS 4, 37 (May 2019), 1450. https://doi.org/10.21105/joss.01450
- MicroPython - Python for microcontrollers. Retrieved November 14, 2023 from http://micropython.org/
- CircuitPython. Retrieved November 14, 2023 from https://circuitpython.org/
- Stack Overflow Developer Survey 2023. Stack Overflow. Retrieved November 14, 2023 from https://survey.stackoverflow.co/2023/?utm_source=social- share&utm_medium=social&utm_campaign=dev-survey-2023
- Arduino Lidar Scanning & Java Rendering. projecthub.arduino.cc. Retrieved November 14, 2023 from https://projecthub.arduino.cc/TravisLedo/arduino-lidar-scanning-java-rendering-801369
- TensorFlow Lite for Microcontrollers. TensorFlow. Retrieved November 14, 2023 from https://www.tensorflow.org/lite/microcontrollers