Git Product home page Git Product logo

esp-rplidars2's Introduction

ESP32_Arduino_RPLIDAR_S2

Gerneral Information

This Library is not supporting all features of the sensor. Do read the below lines what's supported and tested!

It can be used to interface between an RPLIDAR S2 and an ESP32.

Supported and tested boards and frameworks

  • ESP32 with Arduino IDE At the moment is only the ESP32 tested. Should be possible to use every microcontroller with serial port supported baud rate of 1M and enough storage. Other 2D 360° Lidars could also work if they have the same protocol as the S2 got.

Whats implemented

Currently, there are the following functions implemented in the library

  • Start and Stop scanning
  • Standard Scan frame reads from sensor
  • Express Scan reads from sensor
  • read of sensor status
  • read of sensor information

That's it for now.

Library usage

Create an instance of the library with the following parameters

  • Address to the serial port of the port where the sensor is connected to
  • uint32_t baud rate of 1000000 for the S2

Read Sensorinformation

getDeviceInfo() gets the Device address and Software Information of the sensor and returns the struct stDeviceInfo_t with the following informations.

struct rp_stDeviceInfo
{
  uint8_t model;
  uint8_t firmware_minor;
  uint8_t firmware_major;
  uint8_t hardware;
  uint8_t serialnumber[16];
}stDeviceInfo_t;

read sensor status

getDeviceHealth() The Status is not mentioned in the datasheet. If status is 0 the sensor is good. If the status equals 2 it's not ready for run

typedef struct deviceHealtStatus
{
	uint8_t status;
	uint8_t errorCode_low;
	uint8_t errorCode_high;
}stDeviceStatus_t;

start and stop scan

A scan of the Sensor can be started with start(uint8_t _mode). You have to pass the scan mode which the sensor should run

enum enMode
{
	stop,
	standard,
	express
};

To stop the scan mode stopDevice() can be used.

read scan data

The data of a scan can be read with readMeasurePoints() (after a scan is initiated with startScan()) the measure points are saved to a data buffer.

stScanDataPoint_t DataBuffer[1500]` //is used for standard mode
point_t Data[1540]` //is used for express mode

The struct point_t is shown below

typedef struct Point
{
	double angle; 
	uint16_t distance; 
}point_t;

The buffer can be accessed with your program. The express mode is in most cases the better option because of the higher angle resolution and faster scans. The amount of time for refreshing the buffer Data is about 100ms. Standard mode is much slower.

Debug

There are some debug functions implemented to show data to the serial monitor of your Computer

	void DebugPrintMeasurePoints(int16_t _count);	///< prints Standard Data in normal Format in Serial Monitor
	void DebugPrintDeviceErrorStatus(stDeviceStatus_t _status); ///< prints Status of lidar in Serial Monitor
	void DebugPrintDeviceInfo(stDeviceInfo_t _info);	///< prints Device Info in Serial Monitor
	void DebugPrintDescriptor(rp_descriptor_t _descriptor); ///< prints descriptor in Serial Monitor
	void DebugPrintBufferAsHex();				///< prints Standard Data as Hex splitted with ","  in Serial Monitor

esp-rplidars2's People

Contributors

kkest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

esp-rplidars2's Issues

Standard Mode not working

Hi,

is there also a test-program for the standard mode available. I do not get it running when I change the mode to standard in the example program:
`#include "rpLidar.h"
#include "rpLidarTypes.h"

rpLidar lidar(&Serial2,1000000);

void setup() {
Serial.begin(115200);
lidar.resetDevice(); //reset the device to be sure that the status is good
lidar.setAngleOfInterest(5,175); //Set the field of view that is saved to Data
lidar.start(standard); //start the express scan of the lidar
}

void loop()
{
lidar.readMeasurePoints();// reads a full scan and save it to Data
for(int i=0;i<sizeof(lidar.Data)/sizeof(point_t);i++)
{
Serial.print(lidar.Data[i].angle);
Serial.print("deg\t|\t");
Serial.print(lidar.Data[i].distance);
Serial.println("mm");
}
}`

My problem is that I need the data continuously and save it in a background task to a buffer where I can get the newest measurements. They should be overwritten at least all 200ms that they are real time.
How can I solve this?

Compatibilty with Arduin Nano ESP32?

Is Arduino ESP32 board compatible with the presented code?

I connected the RPLidar S2 Rx to Tx (D0) of Arduino board, TX tot the RX (D1) of the Arduino board. RPLidar S2 Power from external power supply, Arduino power from USB port. Common grounds. Installing the library in Arduino IDE 2.x went OK. Uploading the expres_scan.ino to Arduino Nano ESP32 went OK (only after upgrade In Arduino IDE of the Arduino_ESP32 board to version 2.0.12). RPLidar is active ( power take up 0.34 A) .
But, the serial monitor displays only "0.00 deg | 0 mm". After some 10-15 seconds there migth be some activity noted in the first line of the Serial Monitor, but no data.
I changed in the sketch Serial2 tot Serial0, Serial1 without results.

Is this a case of pin-confusion at the ArduinoESP32? How to resolve?

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.