theunkn0wn1 / rplidar_sdk_python

2 stars 0 forks source link

How to run this code? #3

Closed arjunskumar closed 3 years ago

arjunskumar commented 3 years ago

Could you give some hints to build and run this package?

theunkn0wn1 commented 3 years ago

I really need to spend some time and fix the build system, using bazel was probably a mistake..

Anyways, building: You are going to want to spin up a python docker container (or use a system interpreter, if you want to try your luck) for whatever cpython version (must match both major and minor release) your project is using, in theory it should support python >=3.6

This container is going to need bazel in it, because that was the build system I elected to use when i created this project.

Example dockerfile:

FROM python:3.6
RUN apt update && apt install -y sudo
RUN sudo apt install curl gnupg && \
  curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg && \
  sudo mv bazel.gpg /etc/apt/trusted.gpg.d/ && \
  echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list

run sudo apt update
run sudo apt install bazel
run pip install poetry
run poetry config virtualenvs.create false

WORKDIR build
copy . .
CMD ["/bin/bash"]

from there,

 bazel build //rplidar_python:build_wheel

and an installable wheel will be generated in bazel-bin/rplidar_python/rplidar_sdk-0.1.0-py3-none-any.whl

Things that could use improvement:

lidar = rplidar_sdk.Lidar()

connect to the lidar

lidar.connect()

get the device's info

info = lidar.get_device_info()

perform a lidar scan

scan = lidar.read()

arjunskumar commented 3 years ago

@theunkn0wn1 Thanks for the detailed steps. I was able to run the script but it is showing RuntimeError: scan failed! rplidar_sdk_issues1

theunkn0wn1 commented 3 years ago

Hrm, looks like the .connect call failed, all subsequent calls will fail if the connection fails.

Unfortunately the raw error code doesn't mean anything to me (its an opaque value).

Things to check:

arjunskumar commented 3 years ago
  1. is the lidar connected via USB Serial? - Yes
  2. is the lidar accessible via /dev/ttyUSB0? (this is configurable) - Yes, I was able to get data from slam_tech/rplidar_sdk
  3. is the lidar readable at 9600 baud (this is configurable) - Yes, but I set it as 115200(which we used to get data earlier)
  4. Daft question: is this lidar supported by the underlying rplidar sdk - Yes, I'm using Rplidar A1m8
  5. Is the lidar a new model(<= 6 months) ? No, it was an older version.
theunkn0wn1 commented 3 years ago

Aight so it does sound like something in this wrapper, which is odd.

This library is basically just:tm: a pybind11 wrapper around the underlying slam_tech/rplidar_sdk, so im not sure whats presently going wrong.

I don't happen to have a lidar on hand, though i should be getting access in the next few days so i can do some debugging. Will update once I have regained access to an applicable Lidar and done some debugging.

theunkn0wn1 commented 3 years ago

Ok. @arjunskumar My apologies for the delay.

Reacquired a Lidar (A2M8).

If your lidar is anything like what's on my desk: the default baud rate on .connect isn't actually sane.

try explicitly passing a baud rate to the call.

In [3]: driver.connect("/dev/ttyUSB0", baud=115200)
Out[3]: 0

In [4]: driver.get_device_info()
Out[4]: 
(0,
 DeviceInfo(model=40, firmware_version=281, hardware_version=5, serialnum=195))
theunkn0wn1 commented 3 years ago

You may also want to try building off #4 , where I completely reworked the build system (so now it works with pip install .)

arjunskumar commented 3 years ago

@theunkn0wn1 Thanks, I dont have access to the Rplidar now, will reopen the issues if I didnt get the expected output