Qt思岚激光雷达_qt


Qt关于思岚激光雷达研究示例,本示例采用qt界面开发,可以串口也可以tcp进行设备连接。接收数据进行相关的数据进行绘图,

这种雷达可以用于大屏触摸场景,会场互动触摸场景开发。

#ifndef MAINWIDGET_H
#define MAINWIDGET_H

#include <QTimer>
#include <QWidget>
#include "lidarmgr.h"

namespace Ui {
class MainWidget;
}

class MainWidget : public QWidget
{
Q_OBJECT

public:
explicit MainWidget(QWidget *parent = nullptr);
~MainWidget();

protected:
void showEvent(QShowEvent *event);

private slots:
void on_pushButton_clicked();

void on_pushButton_2_clicked();

void on_pushButton_3_clicked();


void on_pushButton_4_clicked();

void mtimeout();

void on_pushButton_5_clicked();

private:
Ui::MainWidget *ui;
std::vector<RplidarScanMode> outModes;
RplidarScanMode usingScanMode;
int modelIndex;

QTimer *m_QTimer;
bool m_state;

int m_model_state;
};

#endif // MAINWIDGET_H

绘制雷达图采用QPainter实现

同时可以用鼠标滚轮进行缩放


void QScanLidarWidget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setBrush(QBrush(QColor(0,0,0)));
painter.drawRect(0,0,this->width()-1,this->height()-1);
//绘制文字
painter.setPen(QPen(QColor(255,255,255),5));
painter.drawText(10,30,QString::number(m_sample_duration) + " ts");
painter.drawText(100,30,QString::number(m_scan_speed) + " Hz");
//移动到中间
int m_step = (this->width()-50)/6;//圆步长
painter.translate(this->width()/2,this->height()/2);

//每30度画线
painter.setPen(QPen(QColor(128,128,128),1));
for(int i = 0; i < 12;i++){
double radian = 30*i * M_PI / 180;
double xMargin = cos(radian) * (m_step*3+10);
double yMargin = sin(radian) * (m_step*3+10);
QPoint t_point(xMargin,yMargin);
QPoint t_pointSrc(0,0);
painter.drawLine(t_pointSrc,t_point);
if(i==0){
painter.drawText(t_point,QString("%1").arg(0));
}else{
painter.drawText(t_point,QString("%1").arg(360-30*i));
}
}

//画圆
painter.setBrush(Qt::NoBrush);
painter.setPen(QPen(QColor(128,128,128)));
painter.drawEllipse(QPointF(0,0),m_step*1,m_step*1);
painter.drawEllipse(QPointF(0,0),m_step*2,m_step*2);
painter.drawEllipse(QPointF(0,0),m_step*3,m_step*3);
//绘制文本
double t_dist_step = m_max_dist/3;
painter.drawText(QPointF(m_step*1-20,0),QString::number(t_dist_step,'f',1));
painter.drawText(QPointF(m_step*2-20,0),QString::number(t_dist_step*2,'f',1));
painter.drawText(QPointF(m_step*3-20,0),QString::number(t_dist_step*3,'f',1));
painter.setPen(QPen(QColor( 220,20,60),2));

for(int i = 0;i < t_dis_points.size();i++){
painter.drawEllipse(t_dis_points.at(i),1,1);//画数据
}
}