From 9f233c82a7d19478b00614a69ba29c1cc6414f9c Mon Sep 17 00:00:00 2001 From: Pasi Nuutinmaki Date: Tue, 21 Sep 2021 00:03:31 +0300 Subject: [PATCH] Add selectable scanmode for RPLIDAR 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"(?) --- Lidar/rplidarthread.cpp | 17 ++- Lidar/rplidarthread.h | 4 +- mainwindow.cpp | 6 +- mainwindow.ui | 329 +++++++++++++++++++++++----------------- 4 files changed, 213 insertions(+), 143 deletions(-) diff --git a/Lidar/rplidarthread.cpp b/Lidar/rplidarthread.cpp index abd60fb..4952438 100644 --- a/Lidar/rplidarthread.cpp +++ b/Lidar/rplidarthread.cpp @@ -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; @@ -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)) { diff --git a/Lidar/rplidarthread.h b/Lidar/rplidarthread.h index dcedd6b..7d8e004 100644 --- a/Lidar/rplidarthread.h +++ b/Lidar/rplidarthread.h @@ -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 @@ -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; diff --git a/mainwindow.cpp b/mainwindow.cpp index 54e0ada..7246561 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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(); @@ -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; @@ -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(); @@ -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); } @@ -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); } diff --git a/mainwindow.ui b/mainwindow.ui index 3d77e33..938f0d5 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -7,7 +7,7 @@ 0 0 626 - 696 + 734 @@ -24,9 +24,9 @@ 0 - 0 + -438 589 - 1121 + 1131 @@ -994,6 +994,73 @@ 4 + + + + 8 + + + 8 + + + + + Serial port: + + + + + + + \\.\COM + + + 256 + + + + + + + Bps: + + + + + + + + 80 + 0 + + + + 300 + + + 10000000 + + + 115200 + + + + + + + Start thread + + + + + + + Terminate thread + + + + + @@ -1149,73 +1216,6 @@ - - - - 8 - - - 8 - - - - - Serial port: - - - - - - - \\.\COM - - - 256 - - - - - - - Bps: - - - - - - - - 80 - 0 - - - - 300 - - - 10000000 - - - 115200 - - - - - - - Start thread - - - - - - - Terminate thread - - - - - @@ -1525,74 +1525,129 @@ RPLidar - + - - - 8 - - - 8 - - - - - Serial port: - - - - - - - \\.\COM - - - 256 - - - - - - - Bps: - - - - - - - - 80 - 0 - - - - 300 - - - 10000000 - - - 256000 - - - - - - - Motor PWM: - - - + - - - 1023 - - - 660 - - + + + + + + + Serial port: + + + + + + + \\.\COM + + + 256 + + + + + + + Bps: + + + + + + + + 80 + 0 + + + + 300 + + + 10000000 + + + 256000 + + + + + + + Motor PWM: + + + + + + + 1023 + + + 660 + + + + + + + + + + + Express scan mode: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + None (use startScan-call instead of Express) + + + + + Standard (0) + + + + + Express (1) + + + + + HQ (2) + + + + + Boost (3) + + + + + Stability (4) + + + + + Sensitivity (5) + + + + + + + @@ -1636,7 +1691,7 @@ - + 8