Skip to content

Commit

Permalink
Add selectable scanmode for RPLIDAR
Browse files Browse the repository at this point in the history
Testing if scanmode could be used to better detect tires etc.

Also testing if the strange "tails" (when there is an object nearby, objects farther away get some measurement nearer or farther than they are (hard to explain in words...)) as mentioned in #7 could be somehow prevented. Quick tests showed very strange behavior:
- If using "standard" (4 ksps)-mode and 20 rpm, there are no tails.
- Lowering RPM to about 5 the tails appear
- If using "express" (8 ksps)-mode and 20 rpm there are no tails
- Lowering RPM to 10 the tails appear
- Any 16 ksps mode seems to have tails whatever the RPM (can not get more than 20 RPM)

Doesn't make much sense. Seems like the RPLIDAR starts to mangle the measured points if "angular resolution" is good enough... But anyway, using "express" (8 ksps)-mode and 20 RPM there are no tails. So maybe use that and forget the strangeness...

Scanmode affects sampling rate and max distance (found from https://download.slamtec.com/api/download/rplidar-protocol/2.2?lang=en , page 12):
Standard: 4 ksps, 16m
Express: 8 ksps, 25m
Boost: 16 ksps, 25m
Sensitivity: 16 ksps, 25m
Stability: 16 ksps, 25m

"Sensitivity" mode does not work. "Stability" seems to be 10 ksps so maybe it is the so much advertised "outdoor-mode"(?)
  • Loading branch information
GNSS-Stylist committed Sep 20, 2021
1 parent 01bebfb commit 9f233c8
Show file tree
Hide file tree
Showing 4 changed files with 213 additions and 143 deletions.
17 changes: 13 additions & 4 deletions Lidar/rplidarthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@

#include "rplidarthread.h"

RPLidarThread::RPLidarThread(const QString& serialPortFileName, const unsigned int serialPortBPS, const unsigned short motorPWM)
RPLidarThread::RPLidarThread(const QString& serialPortFileName, const unsigned int serialPortBPS, const unsigned short motorPWM, const short scanMode)
{
this->serialPortFileName = serialPortFileName;
this->serialPortBPS = serialPortBPS;
this->motorPWM = motorPWM;
this->scanMode = scanMode;

terminateRequest = false;
suspended = false;
Expand Down Expand Up @@ -177,9 +178,17 @@ void RPLidarThread::run()
{
suspendIfNeeded();

emit infoMessage("Starting scan...");

rpResult = lidarDriver->startScan(false, true);
if (scanMode == -1)
{
// Use startScan-call when scanmode is "standard"
emit infoMessage("Starting scan using startScan-call...");
rpResult = lidarDriver->startScan(false, true);
}
else
{
emit infoMessage("Starting scan using startScanExpress-call, mode: " + QString::number(scanMode) + "...");
rpResult = lidarDriver->startScanExpress(false, scanMode);
}

if (IS_FAIL(rpResult))
{
Expand Down
4 changes: 3 additions & 1 deletion Lidar/rplidarthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ class RPLidarThread : public QThread
* @brief Constructor
* @param serialPortFileName File name of com port to open
* @param serialPortBPS Speed (Bits Per Second) of the serial port
* @param scanMode Value used in startScanExpress-call's scanMode-parameter or -1 (use startScan-call instead)
*/
RPLidarThread(const QString& serialPortFileName, const unsigned int serialPortBPS, const unsigned short motorPWM = 660);
RPLidarThread(const QString& serialPortFileName, const unsigned int serialPortBPS, const unsigned short motorPWM = 660, const short scanMode = -1);
~RPLidarThread() override;

void run() override; //!< Thread code
Expand All @@ -56,6 +57,7 @@ class RPLidarThread : public QThread
QString serialPortFileName;
unsigned int serialPortBPS;
unsigned short motorPWM = 0;
short scanMode = -1;

bool terminateRequest = false;
bool suspended = false;
Expand Down
6 changes: 5 additions & 1 deletion mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ MainWindow::MainWindow(QWidget *parent) :
ui->lineEdit_SerialPort_RPLidar->setText(settings.value("SerialPort_RPLidar", "\\\\.\\COM").toString());
ui->spinBox_SerialSpeed_RPLidar->setValue(settings.value("SerialSpeed_RPLidar", "256000").toInt());
ui->spinBox_MotorPWM_RPLidar->setValue(settings.value("MotorPWM_RPLidar", "660").toInt());
ui->comboBox_ExpressScanMode->setCurrentIndex(settings.value("ExpressScanMode_RPLidar", "0").toInt());

// Why is this needed? Q_ENUM should do the job? Different threads causing the need for this?
qRegisterMetaType<SerialThread::DataReceivedEmitReason>();
Expand All @@ -188,6 +189,7 @@ MainWindow::~MainWindow()
settings.setValue("SerialPort_RPLidar", ui->lineEdit_SerialPort_RPLidar->text());
settings.setValue("SerialSpeed_RPLidar", ui->spinBox_SerialSpeed_RPLidar->value());
settings.setValue("MotorPWM_RPLidar", ui->spinBox_MotorPWM_RPLidar->value());
settings.setValue("ExpressScanMode_RPLidar", ui->comboBox_ExpressScanMode->currentIndex());

delete messageMonitorForm_Base_Serial;
delete messageMonitorForm_Base_NTRIP;
Expand Down Expand Up @@ -1086,7 +1088,7 @@ void MainWindow::on_pushButton_StartThread_RPLidar_clicked()
{
if (!thread_RPLidar)
{
thread_RPLidar = new RPLidarThread(ui->lineEdit_SerialPort_RPLidar->text(), ui->spinBox_SerialSpeed_RPLidar->value(), ui->spinBox_MotorPWM_RPLidar->value());
thread_RPLidar = new RPLidarThread(ui->lineEdit_SerialPort_RPLidar->text(), ui->spinBox_SerialSpeed_RPLidar->value(), ui->spinBox_MotorPWM_RPLidar->value(), ui->comboBox_ExpressScanMode->currentIndex() - 1);
if (ui->checkBox_SuspendThread_RPLidar->isChecked())
{
thread_RPLidar->suspend();
Expand All @@ -1113,6 +1115,7 @@ void MainWindow::on_pushButton_StartThread_RPLidar_clicked()
ui->lineEdit_SerialPort_RPLidar->setEnabled(false);
ui->spinBox_SerialSpeed_RPLidar->setEnabled(false);
ui->spinBox_MotorPWM_RPLidar->setEnabled(false);
ui->comboBox_ExpressScanMode->setEnabled(false);
ui->pushButton_StartThread_RPLidar->setEnabled(false);
ui->pushButton_TerminateThread_RPLidar->setEnabled(true);
}
Expand Down Expand Up @@ -1150,6 +1153,7 @@ void MainWindow::on_pushButton_TerminateThread_RPLidar_clicked()
ui->lineEdit_SerialPort_RPLidar->setEnabled(true);
ui->spinBox_SerialSpeed_RPLidar->setEnabled(true);
ui->spinBox_MotorPWM_RPLidar->setEnabled(true);
ui->comboBox_ExpressScanMode->setEnabled(true);
ui->pushButton_StartThread_RPLidar->setEnabled(true);
ui->pushButton_TerminateThread_RPLidar->setEnabled(false);
}
Expand Down
Loading

0 comments on commit 9f233c8

Please sign in to comment.