Code Monkey home page Code Monkey logo

pyrplidar's Introduction

PyRPlidar PyPI - Python Version PyPI MIT License

61845532-a5413e80-aede-11e9-9eee-db8438055619

Introduction

PyRPlidar is a python library for Slamtec RPLIDAR series.

  • Supports all series (A1, A2 and A3)
  • Implement all features of the device
  • Simple code & Easy to use
  • Use generator pattern (for performance)

ezgif-5-3c5261a0b7fa

Installation

$ pip install pyrplidar

Example Code

from pyrplidar import PyRPlidar

lidar = PyRPlidar()
lidar.connect(port="/dev/ttyUSB0", baudrate=256000, timeout=3)
# Linux   : "/dev/ttyUSB0"
# MacOS   : "/dev/cu.SLAB_USBtoUART"
# Windows : "COM5"


info = lidar.get_info()
print("info :", info)

health = lidar.get_health()
print("health :", health)

samplerate = lidar.get_samplerate()
print("samplerate :", samplerate)


scan_modes = lidar.get_scan_modes()
print("scan modes :")
for scan_mode in scan_modes:
    print(scan_mode)


lidar.disconnect()

Documentation

This library implement full specifications on the protocol documentation of Slamtec.

pyrplidar's People

Contributors

hyun-je 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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

pyrplidar's Issues

IndexError: string index out of range

Hi there, thanks for the pyrplidar.
I was searching how begin with RPLIDAR A1M8. And I found your project. It's is very clear and well documented. Congratulations.
I have experiencing some issue when I try to connect to my lidar.
I got the follow crash in every example:

λ python check_connection.py PyRPlidar Info : device is connected Traceback (most recent call last): File "check_connection.py", line 33, check_connection() File "check_connection.py", line 13, info = lidar.get_info() File "C:\Python27\lib\site-packages\p discriptor = self.receive_discripto File "C:\Python27\lib\site-packages\p discriptor = PyRPlidarResponse(self File "C:\Python27\lib\site-packages\p self.sync_byte1 = raw_bytes[0] IndexError: string index out of range

Could you help me?
I tried on Windows and Linux already. No successs. Thanks in advance.

How to make library work is by doing the following:

In pylidarserial.py, change the dsrdtr to false:
dsrdtr=False

In your code make sure baudrate is changed to 256000 for A3, and that the COM port is correct (on windows), or the corresponding device on linux:

lidar = PyRPlidar()
lidar.connect(port="COM3", baudrate=256000, timeout=3) 
lidar.set_motor_pwm(660)
scan_generator = lidar.start_scan_express(3)

for scan in scan_generator():
    scan = vars(scan)
    angle = scan["angle"]
    distance = scan["distance"]
    print("Angle= " + str(angle) + ", Distance= " + str(distance))

In Windows force_scan does not work and start_scan mangles data after 20000 cycles

when i run the simple_scan example i get :

PyRPlidar Info : device is connected
Traceback (most recent call last):
File "pyrlidarneat.py", line 31, in
simple_scan()
File "pyrlidarneat.py", line 16, in simple_scan
scan_generator = lidar.force_scan()
File "C:\Users\user 67\AppData\Local\Programs\Python\Python36\lib\site-packages\pyrplidar.py", line 170, in force_scan
discriptor = self.receive_discriptor()
File "C:\Users\user 67\AppData\Local\Programs\Python\Python36\lib\site-packages\pyrplidar.py", line 42, in receive_discriptor
discriptor = PyRPlidarResponse(self.lidar_serial.receive_data(RPLIDAR_DESCRIPTOR_LEN))
File "C:\Users\user 67\AppData\Local\Programs\Python\Python36\lib\site-packages\pyrplidar_protocol.py", line 110, in init
self.sync_byte1 = raw_bytes[0]
IndexError: index out of range
PyRPlidar Info : device is disconnected

if i replace scan_generator = lidar.force_scan() with scan_generator = lidar.start_scan()
the program will run well for approximately 20,000 readings and then return start to return quality flags larger than 30 and distances larger than 16000.
tried the dtr solution to no avail
i have a hunch that the serial buffer is mangled but could not find how
any help will be greatly appreciated

IndexError: index out of range

I am trying to connect the RPLIDAR A1 to my windows laptop and am receiving this error:

PyRPlidar Info : device is connected
Traceback (most recent call last):
  File "c:\Users\Nate King\Documents\GitHub\Nate-Code\Vision Project\Lidar Test\Example.py", line 10, in <module>
    info = lidar.get_info()
  File "C:\Users\Nate King\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pyrplidar.py", line 73, in get_info
    discriptor = self.receive_discriptor()
  File "C:\Users\Nate King\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pyrplidar.py", line 42, in receive_discriptor
    discriptor = PyRPlidarResponse(self.lidar_serial.receive_data(RPLIDAR_DESCRIPTOR_LEN))
  File "C:\Users\Nate King\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pyrplidar_protocol.py", line 110, in __init__
    self.sync_byte1 = raw_bytes[0]
IndexError: index out of range
PyRPlidar Info : device is disconnected

Here is the code I am using:

from pyrplidar import PyRPlidar

lidar = PyRPlidar()

lidar.connect(port="COM3", baudrate=115200, timeout=3)
# Linux   : "/dev/ttyUSB0"
# MacOS   : "/dev/cu.SLAB_USBtoUART"
# Windows : "COM3"

info = lidar.get_info()
print("info :", info)

health = lidar.get_health()
print("health :", health)

samplerate = lidar.get_samplerate()
print("samplerate :", samplerate)

scan_modes = lidar.get_scan_modes()
print("scan modes :")
for scan_mode in scan_modes:
    print(scan_mode)

lidar.disconnect()

Anyone have an idea what could be causing this?

set/get motor speed and sampling rate

I know you can use set_motor_pwm() to se the motor rotation speed but
what do I send to the set_motor_pwm() function? the RPM or the sampling rate
is there a way to get current/min/max motor speed?
is there a way to get current/min/max Sampling rate?

thanks for the help.

lidar.connect() does not clear DTR and motor will stop

Testing on the A1M8 which is not set up for variable motor speed using the Slamtec USB adapter board I found that this initiating command leaves the CTRL_MOT line low, after which the motor comes to a stop. This line is actually DTR on the UART. Most example code for scanning immediately implements "lidar.set_motor_pwm(500)", which in turn clears DTR and the motor continues to run. I found that sending other commands did not fix this and only the set_motor_pwm() command corrected the state of DTR. Failure to use the set_motor_pwm() command after the connect() command will cause scans to fail. The use of no other command fixes DTR and it remains low. In the Slamtec C++ SDK in net_serial.cpp these lines of code are found which addresses the point.

//Clear the DTR bit to let the motor spin
clearDTR();

To demonstrate the issue here one can use the following test code but with a time delay.

from pyrplidar import PyRPlidar
import time

lidar = PyRPlidar()
lidar.connect(port="/dev/ttyUSB0", baudrate=115200, timeout=3)

info = lidar.get_info()
print("info :", info)

health = lidar.get_health()
print("health :", health)

samplerate = lidar.get_samplerate()
print("samplerate :", samplerate)

scan_modes = lidar.get_scan_modes()
print("scan modes :")
for scan_mode in scan_modes:
print(scan_mode)

time.sleep(6.0)

#now watch the motor come to a stop
#after disconnect() the motor starts again

lidar.disconnect()

RPLIDAR S1 doesn't work

Hello, why does the RPLIDAR S1 not work? the protocol is the same?

PyRPlidar Info : device is connected
Traceback (most recent call last):
  File "lara.py", line 31, in <module>
    simple_scan()
  File "lara.py", line 17, in simple_scan
    scan_generator = lidar.force_scan()
  File "/usr/local/lib/python3.7/dist-packages/pyrplidar.py", line 170, in force_scan
    discriptor = self.receive_discriptor()
  File "/usr/local/lib/python3.7/dist-packages/pyrplidar.py", line 42, in receive_discriptor
    discriptor = PyRPlidarResponse(self.lidar_serial.receive_data(RPLIDAR_DESCRIPTOR_LEN))
  File "/usr/local/lib/python3.7/dist-packages/pyrplidar_protocol.py", line 110, in __init__
    self.sync_byte1 = raw_bytes[0]
IndexError: index out of range
PyRPlidar Info : device is disconnected

How to set scan mode(s)?

There is a very clear example showing how to use get_scan_modes() to get the available scan modes for the device (although, strangely, all the max_distance values are always the same for me) - but how are you supposed to set the scan mode you want?

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.