robopeak / rplidar_arduino Goto Github PK
View Code? Open in Web Editor NEWRoboPeak RPLIDAR driver for Arduino and Arduino-compatible devices
License: GNU General Public License v2.0
RoboPeak RPLIDAR driver for Arduino and Arduino-compatible devices
License: GNU General Public License v2.0
Hello,
I currently am facing some issues when using this library with the Lidar A2. So, I was wondering if there was any support specific for the A2.
Hallo
Hello
I need your help please I work with ardouino Mega 250 and RPLidar A1 during compilation my said this error knowing that I try to add the yib file for the binlioteck
in between I notice that there is no librery file for this project
than what I want to do and thank you
so the thing is working its turning but which baud raid I need to use to see the result because now there are only "?" marks
Does the library provide esp32? I want to read rplidar data with esp 32. But when I upload simple_connect, my esp32 keep reseting.
Hi.
I want to connect RPLIDAR with arduino leonardo.
So I tried to use below code.
#include <RPLidar.h>
// You need to create an driver instance
RPLidar lidar;
#define RPLIDAR_MOTOR 3 // The PWM pin for control the speed of RPLIDAR's motor.
// This pin should connected with the RPLIDAR's MOTOCTRL signal
bool transmit = false;
byte incomingByte;
void setup() {
// bind the RPLIDAR driver to the arduino hardware serial
Serial.begin(9600);
lidar.begin(Serial1);
Serial.begin(115200);
while (!Serial) {
; //
}
// set pin modes
pinMode(RPLIDAR_MOTOR, OUTPUT);
}
void loop() {
if (IS_OK(lidar.waitPoint())) {
float distance = lidar.getCurrentPoint().distance; //distance value in mm unit
float angle = lidar.getCurrentPoint().angle; //anglue value in degree
bool startBit = lidar.getCurrentPoint().startBit; //whether this point is belong to a new scan
byte quality = lidar.getCurrentPoint().quality; //quality of the current measurement
if (Serial.available() > 0) {
incomingByte = Serial.read();
transmit = !transmit;
}
Serial.println(distance);
//perform data processing here...
} else {
analogWrite(RPLIDAR_MOTOR, 0); //stop the rplidar motor
// try to detect RPLIDAR...
rplidar_response_device_info_t info;
if (IS_OK(lidar.getDeviceInfo(info, 100))) {
Serial.println("Detected");
// detected...
lidar.startScan();
analogWrite(RPLIDAR_MOTOR, 255);
delay(1000);
}
}
}
When I executed this program, RPLIDAR didn't work.
The code is stuck in the "else" part.
When I did "analogWrite(RPLIDAR_MOTOR, 255);" motor rotated well but data was empty.
Maybe RPLIDAR didn't connected... "if (IS_OK(lidar.getDeviceInfo(info, 100)))" this part is "False".
How can I fix this problem??
I have tried the simple_connect example with Arduino Mega. Because I can't use Arduino UNO for checking results. Here, I have tried to use Serial1 for checking lidar data, but the data is improper.
Output:
theta: 200.25 Dist: 01659.00 Q: 47
theta: 50.80 Dist: 01700.00 Q: 47
theta: 340.80 Dist: 02213.00 Q: 47
theta: 73.33 Dist: 02208.00 Q: 47
theta: 211.89 Dist: 02222.00 Q: 47
theta: 111.44 Dist: 02229.00 Q: 47
theta: 79.00 Dist: 02234.00 Q: 47
theta: 204.55 Dist: 02238.00 Q: 47
Is there any way to solve this problem?
Hello,
I'm using Arduino UNO with RPLIDAR A1 and Stepper motor. I'm trying to run both together and get the output in this way:
Step no:
Angle:
Distance:
Step no:
Angle:
Distance:
and so on.
When I run the code, stepper runs for some time and then LIDAR comes into motion along with stepper after some rotations finished by stepper motor.
On the serial monitor also I'm not seeing in the format that I want to see.
How do I run both simultaneously and get the LIDAR's angle and distance output for each step of the stepper motor? I need help with running both together.
I've researched some resources online and I've got to know that delay function should not be used in stepper mode code. micros() function is used in my code.
How do I approach this issue such that I can make both LIDAR and my motor run at once and fetch data together? Please help me with this situation.
RPLIDAR A1 code is from https://github.com/robopeak/rplidar_arduino
I've edited the distance_to_color.ino file from the examples section in the above URL according to my requirement. Let me know how I can solve this problem.
`
/*
RoboPeak RPLIDAR Arduino Example
This example shows how to control an RGB led based on the scan data of the RPLIDAR
The RGB led will change its hue based on the direction of the closet object RPLIDAR has been detected.
Also, the light intensity changes according to the object distance.
/*
Copyright (c) 2014, RoboPeak
All rights reserved.
RoboPeak.com
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// This sketch code is based on the RPLIDAR driver library provided by RoboPeak
#include <RPLidar.h>
// You need to create an driver instance
RPLidar lidar;
// define pin used
const int stepPin = 9;
const int dirPin = 8;
long previoustime = 0;
long interval = 1000;
float distance, angle;
/////////////////////////////////////////////////////////////////////////////
#define RPLIDAR_MOTOR 3 // The PWM pin for control the speed of RPLIDAR's motor.
// This pin should connected with the RPLIDAR's MOTOCTRL signal
//////////////////////////////////////////////////////////////////////////////
void setup() {
// bind the RPLIDAR driver to the arduino hardware serial
lidar.begin(Serial);
// set pin mode for LIDAR Motor
pinMode(RPLIDAR_MOTOR, OUTPUT);
// set the two pins for Stepper motor as outputs
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
}
// digitalWrite(dirPin,HIGH); //Enables the motor to move in a cw direction
// // for one full rotation required 960 pulses
// for(int x = 0; x < 960; x++){
// digitalWrite(stepPin,HIGH);
// delayMicroseconds(1000);
// digitalWrite(stepPin,LOW);
// delayMicroseconds(1000);
// }
//
// digitalWrite(dirPin, LOW); //Enables the motor to move in the opposite direction
// for(int x = 0; x < 960; x++){
// digitalWrite(stepPin,HIGH);
// delayMicroseconds(1000);
// digitalWrite(stepPin,LOW);
// delayMicroseconds(1000);
// }
void loop() {
digitalWrite(dirPin, HIGH); //Enables the motor to move in a cw direction
// for one full rotation required 960 pulses
for (int x = 0; x < 960; x++) {
unsigned long currenttime = micros();
if (currenttime - previoustime > interval)
{
digitalWrite(stepPin, LOW);
digitalWrite(stepPin, HIGH);
distance = lidar.getCurrentPoint().distance;
angle = lidar.getCurrentPoint().angle;
Serial.println("1Angle is:" + String(angle));
Serial.println("1Distance is:" + String(distance));
previoustime = currenttime;
}
Serial.println("Step:" + String(x));
}
digitalWrite(dirPin, LOW); //Enables the motor to move in the opposite direction
// for one full rotation required 960 pulses
for (int x = 0; x < 960; x++) {
unsigned long currenttime = micros();
if (currenttime - previoustime > interval)
{
digitalWrite(stepPin, LOW);
digitalWrite(stepPin, HIGH);
distance = lidar.getCurrentPoint().distance;
angle = lidar.getCurrentPoint().angle;
Serial.println("2Angle is:" + String(angle));
Serial.println("2Distance is:" + String(distance));
previoustime = currenttime;
}
Serial.println("Step:" + String(x));
}
if (IS_OK(lidar.waitPoint())) {
//perform data processing here...
distance = lidar.getCurrentPoint().distance;
angle = lidar.getCurrentPoint().angle;
Serial.println("3Angle is:" + String(angle));
Serial.println("3Distance is:" + String(distance));
}
else {
analogWrite(RPLIDAR_MOTOR, 0); //stop the rplidar motor
// try to detect RPLIDAR...
rplidar_response_device_info_t info;
if (IS_OK(lidar.getDeviceInfo(info, 100))) {
//detected...
lidar.startScan();
analogWrite(RPLIDAR_MOTOR, 255);
delay(1000);
}
}
}`
Hi,
an example on how to record one frame and send it by serial port would be nice. (It is clear that some data may be lost during the serial output)
I tried it with my Arduino Mega. Lidar on UART3, PC on USB.
I tried to record one frame in an int array[359] and send it as soon as the next frame starts. But this results in very strange output. After two hours of try and error I concluded that I must run into a memory overflow. I don't know how much memory gets allocated during runtime - but this may be the issue.
Long story short request:
A demo for grabing and sending one frame woulde be nice.
Thanks
Robert
i following robopeak example "simple_connent"
but that protocol send measuring samples very little
⸮P⸮%⸮ angle : 40.36, distance : 217.50
angle : 34.48, distance : 227.25
angle : 36.42, distance : 222.75
angle : 37.09, distance : 221.50
angle : 37.77, distance : 221.00
angle : 38.42, distance : 220.00
angle : 39.09, distance : 219.50
angle : 40.02, distance : 0.00
angle : 40.44, distance : 208.00
angle : 40.06, distance : 218.50
angle : 41.77, distance : 217.75
angle : 42.41, distance : 217.25
angle : 41.97, distance : 4687.50
⸮P⸮%⸮ angle : 287.13, distance : 392.00
angle : 272.73, distance : 431.00
angle : 273.47, distance : 427.75
angle : 278.63, distance : 0.00
angle : 279.36, distance : 0.00
angle : 280.02, distance : 0.00
angle : 276.97, distance : 370.25
angle : 277.13, distance : 370.50
angle : 278.25, distance : 370.50
angle : 278.73, distance : 370.00
angle : 279.67, distance : 349.00
angle : 279.94, distance : 347.50
angle : 281.02, distance : 5306.25
⸮P⸮%⸮
how to recieve samples like roslaunch rplidar_ros rplidarNodeClient?
#include <RPLidar.h>
RPLidar lidar;
#define RPLIDAR_MOTOR 3
void setup() {
lidar.begin(Serial);
pinMode(RPLIDAR_MOTOR, OUTPUT);
}
void Count() {
time += 0.1;
}
int a=0;
void loop() {
while(IS_OK(lidar.waitPoint())) {
//perform data processing here...
float distance = lidar.getCurrentPoint().distance;
float angle = lidar.getCurrentPoint().angle;
Serial.print("angle : ");
Serial.print(angle);
Serial.print(", distance : ");
Serial.println(distance);
}
rplidar_response_device_info_t info;
if (IS_OK(lidar.getDeviceInfo(info, 100)) && !IS_OK(lidar.waitPoint())) {
//detected...
lidar.startScan();
analogWrite(RPLIDAR_MOTOR, 255);
delay(500);
}
}
Through the code i am not able to detect objects at a distance greater than 0.5 metres although i tried changing some values in the code like in the 109th line i changed the 500 to 1000 to detect objects in a range of 1 metres,but nothing happened and the rplidar was not able to detect objects at a range of greater than 0.5 metres.
Kindly Help.
Nevermind lol
Hi,
I would like to know how to use the following variables:
bool startBit = lidar.getCurrentPoint().startBit; //whether this point is belong to a new scan
byte quality = lidar.getCurrentPoint().quality; //quality of the current measurement
Hello,
I buyed RPLIDAR A2 and I want to implement the 4K frame reading on the powerfull arduino compatible PIC32MX795 (Diligent ChipKit)
This lib support 4K express scan mode ?
Thanks.
my hardware serial pin 0 and 1 have already been used,so what can I do to use the software serial?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.