Giter VIP home page Giter VIP logo

adafruit_circuitpython_rplidar's Introduction

Introduction

Documentation Status Discord Build Status Code Style: Black

Dependencies

Install with PyPy: pip install Adafruit_CircuitPython_RPLIDAR This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

Usage Example

import os
from math import floor
from adafruit_rplidar import RPLidar


# Setup the RPLidar
PORT_NAME = '/dev/ttyUSB0'
lidar = RPLidar(None, PORT_NAME, timeout=3)

# used to scale data to fit on the screen
max_distance = 0

def process_data(data):
    print(data)

scan_data = [0]*360

try:
#    print(lidar.get_info())
    for scan in lidar.iter_scans():
        for (_, angle, distance) in scan:
            scan_data[min([359, floor(angle)])] = distance
        process_data(scan_data)

except KeyboardInterrupt:
    print('Stopping.')
lidar.stop()
lidar.disconnect()

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

adafruit_circuitpython_rplidar's People

Contributors

askpatrickw avatar dastels avatar evaherrada avatar foamyguy avatar jepler avatar kattni avatar kevin-balkoski-enview avatar ladyada avatar makermelissa avatar sommersoft avatar tekktrik avatar zlite avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_circuitpython_rplidar's Issues

Seems to be functioning just fine on desktop ubuntu?

The package description on PyPi for adafruit_rplidar (at https://pypi.org/project/adafruit-rplidar/) states

Eventual goal is for the single module to work with both Linux (via /dev/USB0, etc) and CircuitPython (via a UART instance)

Is there any reason to suspect this goal isn't yet achieved? I'm prototyping a project for eventual raspberry pi deployment in a Ubuntu 18.04 VM, and this seems to work just fine - haven't run into any compatibility problems yet.

As usual, thanks for being awesome!

Latest RPLidar firmware has broken this library

Starting in 2021, all RPLidar hardware is shipping with firmware 1.29, which breaks this library (error shown is "Incorrect descriptor starting bytes", but that just means that it got no data). Slamtec says that this may be due to the default scan mode being changed to boost mode. They say that they do not support Python(!) and are not intending to fix these libraries. They say it's up to us to fix them ourselves :-(

AFAIK there is no way to downgrade the firmware to a previous version (last known good was 1.27), so I think that until distributors can get Slamtec to help fix these libraries, we have to now consider the RPLidar devices unsupported in Python

Missing Type Annotations

There are missing type annotations for some functions in this library.

The typing module does not exist on CircuitPython devices so the import needs to be wrapped in try/except to catch the error for missing import. There is an example of how that is done here:

try:
    from typing import List, Tuple
except ImportError:
    pass

Once imported the typing annotations for the argument type(s), and return type(s) can be added to the function signature. Here is an example of a function that has had this done already:

def wrap_text_to_pixels(
    string: str, max_width: int, font=None, indent0: str = "", indent1: str = ""
) -> List[str]:

If you are new to Git or Github we have a guide about contributing to our projects here: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

There is also a guide that covers our CI utilities and how to run them locally to ensure they will pass in Github Actions here: https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code In particular the pages: Sharing docs on ReadTheDocs and Check your code with pre-commit contain the tools to install and commands to run locally to run the checks.

If you are attempting to resolve this issue and need help, you can post a comment on this issue and tag both @FoamyGuy and @kattni or reach out to us on Discord: https://adafru.it/discord in the #circuitpython-dev channel.

The following locations are reported by mypy to be missing type annotations:

  • adafruit_rplidar.py:86
  • adafruit_rplidar.py:101
  • adafruit_rplidar.py:128
  • adafruit_rplidar.py:159
  • adafruit_rplidar.py:164
  • adafruit_rplidar.py:194
  • adafruit_rplidar.py:200
  • adafruit_rplidar.py:227
  • adafruit_rplidar.py:238
  • adafruit_rplidar.py:255
  • adafruit_rplidar.py:329
  • adafruit_rplidar.py:394
  • adafruit_rplidar.py:477
  • adafruit_rplidar.py:486
  • adafruit_rplidar.py:525

Library seems to still be broken for firmware 1.29

Cant get this library to work with the example code, it just outputs

adafruit_rplidar.RPLidarException: Incorrect descriptor starting bytes

I could just be being an idiot and its my fault, I've tried all the other library's as well with no luck either it throws an exception or it infinitely tells me the buffer is full while outputting no data. has anyone got this library to work on a slamtec A1 with 1.29 firmware.

Still not sure how to fix the "Descriptor length mismatch" A1M8-R6 firmware issue

I see other users are asking this still, and their questions are just being closed.

But it would be nice to use the RPLidar (A1M8-R6)

The results of running the example (all required python libs installed)

pi@raspberrypi:~/Adafruit_CircuitPython_RPLIDAR/examples $ python3 rplidar_simpletest.py
Traceback (most recent call last):
File "/home/pi/Adafruit_CircuitPython_RPLIDAR/examples/rplidar_simpletest.py", line 24, in
for scan in lidar.iter_scans():
File "/home/pi/.local/lib/python3.9/site-packages/adafruit_rplidar.py", line 540, in iter_scans
for new_scan, quality, angle, distance in iterator:
File "/home/pi/.local/lib/python3.9/site-packages/adafruit_rplidar.py", line 445, in iter_measurements
self.start(scan_type)
File "/home/pi/.local/lib/python3.9/site-packages/adafruit_rplidar.py", line 360, in start
status, error_code = self.health
File "/home/pi/.local/lib/python3.9/site-packages/adafruit_rplidar.py", line 328, in health
dsize, is_single, dtype = self._read_descriptor()
File "/home/pi/.local/lib/python3.9/site-packages/adafruit_rplidar.py", line 268, in _read_descriptor
raise RPLidarException("Descriptor length mismatch")
adafruit_rplidar.RPLidarException: Descriptor length mismatch

Any ideas? Thanks

Problem resizing window

Howdy I've been using this code to run my slamtec rplidar, works well except I'm trying to run it with small display. Therefor, I'm trying to resize the window however, the image doesn't change size, just the window. Please help.

Pylint: global-statement, no-else-raise, unneccessary-pass

Here's pylint's output:

************* Module adafruit_rplidar
adafruit_rplidar.py:108:0: R0205: Class 'RPLidar' inherits from object, can be safely removed from bases in python3 (useless-object-inheritance)
adafruit_rplidar.py:143:12: W0603: Using the global statement (global-statement)
adafruit_rplidar.py:144:12: C0415: Import outside toplevel (serial) (import-outside-toplevel)
adafruit_rplidar.py:239:8: R1720: Unnecessary "elif" after "raise" (no-else-raise)
adafruit_rplidar.py:314:8: W0107: Unnecessary pass statement (unnecessary-pass)

As far as the useless-object-inheritance goes, @brentru I should be able to do the same thing you did in adafruit/Adafruit_CircuitPython_CursorControl#17, correct?

For global-statement and import-outside-toplevel, here's the offending code:

140        if self.is_CP:
141            _serial_port = port
142        else:
143           global serial
144           import serial

If I understand correctly, this checks if the board is a circuitpython board and if it isn't, it imports serial, although I'm not sure why line 143 is necessary.

For no-else-raise:

239        if len(descriptor) != DESCRIPTOR_LEN:
240            raise RPLidarException("Descriptor length mismatch")
241        elif not descriptor.startswith(SYNC_BYTE + SYNC_BYTE2):
242            raise RPLidarException("Incorrect descriptor starting bytes")

I'm not sure why this is an issue, it makes sense to me why this would be done, although I don't understand this code well enough to make an informed decision on that.

For unneccessary-pass

314    def clear_input(self):
315       """Clears input buffer by reading all available data"""
316       pass

Unless there's some weird python mechanic I don't understand going on here, I think that this would be the right place to raise a NotImplementedError.

Referencing main issue: adafruit/Adafruit_CircuitPython_Bundle#232

Get single scan?

Hello. I'm building a robot with the RPLidar, and in every library i use, when i call next(lidar.iter_scans()) it only fetches the scan once, then for the second iteration it just freezes. Any help?

Poor Reaction Time

I have RPLIDAR A1M8, but reaction time is extremely poor.
It's kind of usable if an object gets closer. However, if the object gets further away, the reading increases very slowly.
Sometimes it even never recovers if the objects moves quickly.
I'm not sure if I received a defective unit, or it's a library problem.
Has anyone experienced this?

Change motor speed with A1 model

According to Slamtec's website, the motor can operate on variable speeds, however I have seen nowhere where this speed can be changed.

image

Is this false advertisement, or is there something missing? Furthermore, the motor never stops spinning, even when the .stop() and .disconnect() methods are called.

Rplidar does not support A1M8-R6 firmware version

SBC: Rpi 3B+
OS: Latest Buster Desktop

I have both a Slamtec A1M8-R5 and a A1M8-R6 which is the latest hardware and firmware (v 1.29)

When I run "display_lidar_pi" using my A1M8-R5, I get the expected Lidar display on my LCD display.

When I run "display_lidar_pi.py" using my A1M8-R6, I get the following error message: "adafruit_rplidar .rplidar exception: wrong body size"

I have searched the IoT for a possible solution to the "adafruit_rplidar .rplidar exception: wrong body size" error, but have experienced no joy.

The A1M8-R5 is two years old and is running an early version of the A1M8 firmware. The A1M8-R6 is running the latest firmware.

Obviously the Adafruit RPLidar module is taking an exception to the latest A1M8-R6 firmware, but has no issue with the A1M8-R5 firmware.

I am using the Adafruit RPLidar module with both the A1M8-R5 and R6 on my Donkey Car platform and have no issues connecting with either A1M8 and collecting data.

Is there a line of code in the "display_lidar_pi.py" program that can be adjusted to overcome the dreaded "adafruit_rplidar .rplidar exception: wrong body size" error?

Here is the complete error message when using the A1M8-R6:

pygame 1.9.4.post1
Hello from the pygame community. https://www.pygame.org/contribute.html
{'model': 24, 'firmware': (1, 29), 'hardware': 7, 'serialnumber': '14342370f79ce5c5d49ae5c9f699f18c'}
Traceback (most recent call last):
File "display_lidar_pi.py", line 55, in
for scan in lidar.iter_scans():
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_rplidar.py", line 508, in iter_scans
for new_scan, quality, angle, distance in iterator:
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_rplidar.py", line 433, in iter_measurements
raw = self._read_response(dsize)
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_rplidar.py", line 261, in _read_response
raise RPLidarException("Wrong body size")
adafruit_rplidar.RPLidarException: Wrong body size

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.