Giter VIP home page Giter VIP logo

rplidar_rpi's Introduction

Slamtec RPLIDAR A1 on an Alphabot with a Raspberry PI

alt tag

This project describes how to connect a Slamtech RPLIDAR A1 directly to a Raspberry PI by using its in-built serial port. So no need to use the supplied USB interface.

This repository contains a C++ class which reads the coordinates and also does the motor control via PWM of the RPI.

A 360 degree scan is provided by a callback at the sampling rate of the LIDAR which is kept at 300RPM (5Hz).

Wiring

There are two sockets on the LIDAR. One is for the serial communication and the other for the motor control. The serial data is transmitted via the Raspberry PI serial port and the speed is controlled with GPIO pin 18.

Use the cable which comes with the LIDAR and plug its two plugs into the two sockets on the LIDAR and chop off the single connector at the other end.

Solder the wires to the serial port of the Raspberry PI and port 18:

alt tag

The motor can be receiving the unregulated battery voltage (<10V) or the 5V from the raspberry PI but the serial interface requires 5V.

Rapberry PI config

  • Start raspi-config
  • Select Serial Port Enable/disable shell messages on the serial connection
  • Answer No: Would you like a login shell to be accessible over serial?
  • Answer Yes: Would you like the serial port hardware to be enabled?
  • Reboot when prompted

Software

Prerequisites

Install the pigpio package and development headers:

apt-get install libpigpio-dev

Installation

cmake .

make

sudo make install

This installs the library and can then be used in your application.

A1Lidar class

The class has start() and stop() functions which start and stop the data acquisition and also start and stop the motor of the range finder.

The data is transmitted via DataInterface where the abstract function newScanAvail(float rpm, A1LidarData (&)[A1Lidar::nDistance]) = 0 needs to be implemented which then receives both the polar and Cartesian coordinates after a successful 360 degree scan. Register your DataInterface with registerInterface.

Example program

printdata prints tab separated distance data as x <tab> y <tab> r <tab> phi <tab> strength until a key is pressed.

Pipe the data into a textfile and plot it with gnuplot:

sudo ./printdata > tt2.tsv
gnuplot> plot "tt2.tsv"

alt tag

printRPM prints the current RPM until you press ctrl-C.

Credits

The rplidarsdk folder is the sdk folder from the official Slamtec git (latest v1.x):

https://github.com/Slamtec/rplidar_sdk

rplidar_rpi's People

Contributors

berndporr avatar possibilia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rplidar_rpi's Issues

Trouble with ctypes import into python

Hello,
Thank you for uploading this project, it has been very helpful in getting my slamtec rplidar working with my raspberry pi. I've been attempting to compile the a1lidarrpi.cpp as a shared object output file and import it into python as I wish to manipulate the incoming data in python, however I'm running into issues with the linking.

The compile command I'm currently using is:
sudo g++ -fPIC -shared -o a1lidarrpi.so a1lidarrpi.cpp -lstdc++ -lpigpio

Which generates the a1lidarrpi.so and then I am attempting to load the library using the following two lines in python:

import ctypes
lidar = ctypes.CDLL("/home/admin/rplidar_rpi/a1lidarrpi.so")

When ran I receive the following error:
OSError: /home/admin/rplidar_rpi/a1lidarrpi.so: undefined symbol: _ZN2rp10standalone7rplidar13RPlidarDriver12CreateDriverEj

I ran into two previous undefined symbol errors which were solved by the addition of -lstdc++ -lpigpio on the compile command, however I am at a loss on how to approach this undefined symbol linking error. It appears to me to be looking for the driver for the RPLidar, is that referencing the driver in the rplidar_sdk? If so, how would I go about linking that?

Any help resolving this undefined symbol error would be much appreciated. Also if you know of a better way to implement python bindings to use your C++ program in python, I am open to that option as well.

Thanks for your time.

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.