Created
June 5, 2025 11:13
-
-
Save sw8744/fdf765295ea9202f98a926bbca061881 to your computer and use it in GitHub Desktop.
RPLidar A1M8 Python Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from rplidar import RPLidar | |
lidar = RPLidar('COM7', baudrate=115200, timeout=3) #2560000 | |
try: | |
iterator = lidar.iter_scans() | |
time.sleep(3) | |
for i, scan in enumerate(lidar.iter_scans()): | |
for quality, angle, distance in scan: | |
if distance > 0 and quality > 0: | |
print(f"Angle: {angle:.2f}, Distance: {distance}mm, Quality: {quality}") | |
print("-----------------------------------") | |
except KeyboardInterrupt: | |
print("Stopping due to keyboard interrupt...") | |
except Exception as e: | |
print(e) | |
finally: | |
print("Stopping lidar...") | |
lidar.stop_motor() | |
lidar.stop() | |
lidar.disconnect() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment