Hello there,
I'm trying to use an RPLIDAR A1 with my Arduino Due. I used the Robopeaks Arduino Library and started coding with the "simple connect" example out of this library.
I copied the measurements out of the serial monitor and tried to plot in in Excel but the results are a bit frustrating, as you can see. There are many incorrect points, even 20 m far away. Zooming in, I get my room but still many wrong points.
There is also something wrong with the angles because they aren't increasing as they should...
Distance | Angle |
---|---|
5839,50 | 150,83 |
5077,75 | 124,16 |
12495,50 | 42,36 |
14613,25 | 370,16 |
3973,50 | 40,67 |
1395,00 | 180,36 |
5932,25 | 124,17 |
6179,25 | 125,23 |
1568,75 | 194,34 |
1601,00 | 198,19 |
1665,00 | 202,00 |
8911,50 | 54,86 |
1592,25 | 211,00 |
1500,00 | 212,31 |
Maybe someone could look at my code and give me a hint...
Thanks
/*
USAGE:
---------------------------------
1. Download this sketch code to your Arduino board
2. Connect the RPLIDAR's serial port (RX/TX/GND) to your Arduino board (Pin 0 and Pin1)
3. Connect the RPLIDAR's motor ctrl pin to the Arduino board pin 3
*/
// 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;
// The PWM pin for control the speed of RPLIDAR's motor.
// This pin should connected with the RPLIDAR's MOTOCTRL signal
#define RPLIDAR_MOTOR 2
bool transmit = false;
byte incomingByte;
int x = 0;
int y = 0;
void setup()
{
// bind the RPLIDAR driver to the arduino hardware serial
Serial1.begin(115200);
lidar.begin(Serial1);
// initialize both serial ports:
Serial.begin(115200); // Initialize Native USB port
// set pin modes
pinMode(RPLIDAR_MOTOR, OUTPUT);
analogWrite(RPLIDAR_MOTOR, 255);
}
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.print("dist: ");
Serial.print(distance);
Serial.print(";");
//Serial.print("\tangle: ");
Serial.print(angle);
Serial.print(";");
//Serial.print("\tsbit: ");
//Serial.print(startBit);
//Serial.print(";");
//Serial.print("\tquality: ");
Serial.print(quality);
Serial.print("\n");
}
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();
// start motor rotating at max allowed speed
analogWrite(RPLIDAR_MOTOR, 255);
delay(1000);
}
}
}
rplidar_arduino_library.zip (21.6 KB)
rplidar_a1_connect.ino (2.2 KB)