深圳市建设注册执业资格中心网站,建立企业网站的详细步骤,上海做网站报价,百度文库官网入口目录
一、固高示波器
二、基于QCustomPlot实现示波器
三、完整源码 一、固高示波器 固高运动控制卡自带的软件有一个示波器功能#xff0c;可以实时显示速度的波形#xff0c;可辅助分析电机的运行状态。但是我们基于sdk开发了自己的软件#xff0c;无法再使用该功能可以实时显示速度的波形可辅助分析电机的运行状态。但是我们基于sdk开发了自己的软件无法再使用该功能原因是2个软件不能同时与控制卡通信故此需要我们自己再开发一个示波器。
固高示波器功能展示功能包括多条曲线的显示、继续/暂停、左移、右移、设置、轴选择等。 二、基于QCustomPlot实现示波器
GCustomPlot简介与使用看官网就可以了
简介, Qt Plotting Widget QCustomPlot - Introduction
下载, Qt Plotting Widget QCustomPlot - Download
需要注意的是需要在pro文件中加入printsuppot模块源码中使用该模块做pdf打印功能
QT printsupport 参考固高的功能实现速度示波器效果如下 QCustomPlot初始化设置 m_customPlot new QCustomPlot(this);m_customPlot-setObjectName(QLatin1String(customPlot));ui-vlyPlot-addWidget(m_customPlot);m_customPlot-setBackground(QBrush(QColor(#474848)));m_customPlot-setInteractions(QCP::iRangeDrag | QCP::iRangeZoom |QCP::iSelectPlottables); /* 可拖拽可滚轮缩放 */m_customPlot-legend-setVisible(true);
添加两条曲线图addGraph m_customPlot-addGraph();m_customPlot-graph(0)-setPen(QPen(Qt::green, 3));m_customPlot-graph(0)-setName(QStringLiteral(实际速度));m_customPlot-addGraph();m_customPlot-graph(1)-setPen(QPen(Qt::yellow, 3));m_customPlot-graph(1)-setName(QStringLiteral(规划速度)); 左右移动通过设置X轴的范围来改变再使用replot函数更新视图
m_customPlot-xAxis-setRange(m_customPlot-xAxis-range().lower - ui-spbStep-value(),m_customPlot-xAxis-range().upper - ui-spbStep-value());m_customPlot-replot();
网格线显示与隐藏 m_customPlot-xAxis-grid()-setVisible(checked);m_customPlot-yAxis-grid()-setVisible(checked);m_customPlot-replot();
添加数据示波器有向左自动滚动的效果也是通过设置范围来实现
void OscilloscopeFrame::addData(double key, double actVel, double prfVel)
{m_customPlot-graph(0)-addData(key, actVel);m_customPlot-graph(1)-addData(key, prfVel);m_customPlot-xAxis-rescale();m_customPlot-graph(0)-rescaleValueAxis(false, true);m_customPlot-graph(1)-rescaleValueAxis(false, true);m_customPlot-xAxis-setRange(m_customPlot-xAxis-range().upper,m_fixedLength, Qt::AlignRight);m_customPlot-replot(QCustomPlot::rpQueuedReplot); /* 实现重绘 */
}
实时显示数据通过定时器实现 m_timer new QTimer();connect(m_timer, QTimer::timeout, updateData);m_timer-start(OSCILLOSCOPE_UPDATE_MSEC);
鼠标放在曲线上显示当前值关联鼠标移动信号映射坐标pixelToCoord connect(m_customPlot, SIGNAL(mouseMove(QMouseEvent *)), this,SLOT(plotMouseMoveEvent(QMouseEvent *)));
void OscilloscopeFrame::plotMouseMoveEvent(QMouseEvent *event)
{if ( Qt::ControlModifier event-modifiers()){int x_pos event-pos().x();int x_val m_customPlot-xAxis-pixelToCoord(x_pos);float y m_customPlot-graph(0)-data()-at(x_val)-value;QString strToolTip QString(%1,%2).arg(x_val).arg(y);QToolTip::showText(cursor().pos(), strToolTip, m_customPlot);}
} 三、完整源码
OscilloscopeFrame.h
#ifndef OSCILLOSCOPEFRAME_H
#define OSCILLOSCOPEFRAME_H#include QFrame
#include oscilloscopelib_global.hnamespace Ui
{class OscilloscopeFrame;
}class QCustomPlot;class AbstractRobot;class OSCILLOSCOPELIBSHARED_EXPORT OscilloscopeFrame : public QFrame
{Q_OBJECTpublic:explicit OscilloscopeFrame(QWidget *parent 0);~OscilloscopeFrame();void setFixedLength(double length);void addData(double key, double actVel, double prfVel);void installController(AbstractRobot *controller);private slots:void plotMouseMoveEvent(QMouseEvent *event);private:Ui::OscilloscopeFrame *ui;QCustomPlot *m_customPlot nullptr;QTimer *m_timer nullptr;double m_fixedLength;AbstractRobot *m_controller nullptr;double m_actPos 0;double m_count 0;
};#endif // OSCILLOSCOPEFRAME_HOscilloscopeFrame.cpp
#include OscilloscopeFrame.h
#include qcustomplot.h
#include ui_OscilloscopeFrame.h
#include QtMath
#include QDebug
#include device/AbstractRobot.h#define OSCILLOSCOPE_UPDATE_MSEC 60OscilloscopeFrame::OscilloscopeFrame(QWidget *parent) :QFrame(parent),ui(new Ui::OscilloscopeFrame)
{ui-setupUi(this);ui-spbStep-setValue(1);for(int i 1; i 8; i){ui-cmbAxisId-addItem(QString::number(i));}m_customPlot new QCustomPlot(this);m_customPlot-setObjectName(QLatin1String(customPlot));ui-vlyPlot-addWidget(m_customPlot);m_customPlot-setBackground(QBrush(QColor(#474848)));m_customPlot-setInteractions(QCP::iRangeDrag | QCP::iRangeZoom |QCP::iSelectPlottables); /* 可拖拽可滚轮缩放 */m_customPlot-legend-setVisible(true);m_customPlot-addGraph();m_customPlot-graph(0)-setPen(QPen(Qt::green, 3));m_customPlot-graph(0)-setName(QStringLiteral(实际速度));m_customPlot-addGraph();m_customPlot-graph(1)-setPen(QPen(Qt::yellow, 3));m_customPlot-graph(1)-setName(QStringLiteral(规划速度));m_customPlot-axisRect()-setupFullAxesBox();m_customPlot-yAxis-setRange(0, 3.3);ui-btnPause2Continue-setCheckable(true);setFixedLength(100);/* 暂停/继续 */connect(ui-btnPause2Continue, QPushButton::clicked, this, [ ](){if(!m_timer){return;}bool isCheckable ui-btnPause2Continue-isCheckable();if(isCheckable){m_timer-stop();ui-btnPause2Continue-setText(QStringLiteral(继续));}else{m_timer-start(OSCILLOSCOPE_UPDATE_MSEC);ui-btnPause2Continue-setText(QStringLiteral(暂停));}ui-btnPause2Continue-setCheckable(!isCheckable);});/* 左移 */connect(ui-btnLeftMove, QPushButton::clicked, this, [ ](){m_customPlot-xAxis-setRange(m_customPlot-xAxis-range().lower - ui-spbStep-value(),m_customPlot-xAxis-range().upper - ui-spbStep-value());m_customPlot-replot();});/* 右移 */connect(ui-btnRightMove, QPushButton::clicked, this, [ ](){m_customPlot-xAxis-setRange(m_customPlot-xAxis-range().lower ui-spbStep-value(),m_customPlot-xAxis-range().upper ui-spbStep-value());m_customPlot-replot();});/* 显示表格 */connect(ui-chkGrid, QCheckBox::toggled, this, [ ](bool checked){m_customPlot-xAxis-grid()-setVisible(checked);m_customPlot-yAxis-grid()-setVisible(checked);m_customPlot-replot();});auto updateData [ ](){if(m_controller){int axis ui-cmbAxisId-currentText().toInt();T_AxisStatus status;int ec m_controller-readAxisStatus(axis, status);if(0 ec){ui-lblActVel-setText(QString::number(status.dEncVel));ui-lblPrfVel-setText(QString::number(status.dPrfVel));ui-lblActPos-setText(QString::number(status.dEncPos));ui-lblPrfPos-setText(QString::number(status.dPrfPos));if(m_actPos ! status.dEncPos){m_actPos status.dEncPos;addData(m_count, status.dEncVel, status.dPrfVel);m_count ;}}else{ui-lblActVel-setText(error QString::number(ec));ui-lblPrfVel-setText(error QString::number(ec));ui-lblActPos-setText(error QString::number(ec));ui-lblPrfPos-setText(error QString::number(ec));}}};m_timer new QTimer();connect(m_timer, QTimer::timeout, updateData);m_timer-start(OSCILLOSCOPE_UPDATE_MSEC);connect(m_customPlot, SIGNAL(mouseMove(QMouseEvent *)), this,SLOT(plotMouseMoveEvent(QMouseEvent *)));for(int i 0; i 500; i){double x qDegreesToRadians((double)i);addData(i, sin(x), cos(x));}
}OscilloscopeFrame::~OscilloscopeFrame()
{m_timer-stop();delete m_timer;m_timer nullptr;delete ui;
}void OscilloscopeFrame::setFixedLength(double length)
{/* 显示固定长度 */m_fixedLength length;
}void OscilloscopeFrame::addData(double key, double actVel, double prfVel)
{m_customPlot-graph(0)-addData(key, actVel);m_customPlot-graph(1)-addData(key, prfVel);m_customPlot-xAxis-rescale();m_customPlot-graph(0)-rescaleValueAxis(false, true);m_customPlot-graph(1)-rescaleValueAxis(false, true);m_customPlot-xAxis-setRange(m_customPlot-xAxis-range().upper,m_fixedLength, Qt::AlignRight);m_customPlot-replot(QCustomPlot::rpQueuedReplot); /* 实现重绘 */
}void OscilloscopeFrame::installController(AbstractRobot *controller)
{m_controller controller;
}void OscilloscopeFrame::plotMouseMoveEvent(QMouseEvent *event)
{if ( Qt::ControlModifier event-modifiers()){int x_pos event-pos().x();int x_val m_customPlot-xAxis-pixelToCoord(x_pos);float y m_customPlot-graph(0)-data()-at(x_val)-value;QString strToolTip QString(%1,%2).arg(x_val).arg(y);QToolTip::showText(cursor().pos(), strToolTip, m_customPlot);}
}
文章转载自: http://www.morning.yskhj.cn.gov.cn.yskhj.cn http://www.morning.kcbml.cn.gov.cn.kcbml.cn http://www.morning.ljbm.cn.gov.cn.ljbm.cn http://www.morning.rhqn.cn.gov.cn.rhqn.cn http://www.morning.zljqb.cn.gov.cn.zljqb.cn http://www.morning.nwrzf.cn.gov.cn.nwrzf.cn http://www.morning.dtpqw.cn.gov.cn.dtpqw.cn http://www.morning.myfwb.cn.gov.cn.myfwb.cn http://www.morning.btjyp.cn.gov.cn.btjyp.cn http://www.morning.pcrzf.cn.gov.cn.pcrzf.cn http://www.morning.hdlhh.cn.gov.cn.hdlhh.cn http://www.morning.xdqrz.cn.gov.cn.xdqrz.cn http://www.morning.paxkhqq.cn.gov.cn.paxkhqq.cn http://www.morning.qtltg.cn.gov.cn.qtltg.cn http://www.morning.tdqhs.cn.gov.cn.tdqhs.cn http://www.morning.kfcfq.cn.gov.cn.kfcfq.cn http://www.morning.rhchr.cn.gov.cn.rhchr.cn http://www.morning.kbynw.cn.gov.cn.kbynw.cn http://www.morning.mqss.cn.gov.cn.mqss.cn http://www.morning.xnnxp.cn.gov.cn.xnnxp.cn http://www.morning.mhfbp.cn.gov.cn.mhfbp.cn http://www.morning.tfsyk.cn.gov.cn.tfsyk.cn http://www.morning.kdlzz.cn.gov.cn.kdlzz.cn http://www.morning.mqfw.cn.gov.cn.mqfw.cn http://www.morning.bfcxf.cn.gov.cn.bfcxf.cn http://www.morning.xswrb.cn.gov.cn.xswrb.cn http://www.morning.fwgnq.cn.gov.cn.fwgnq.cn http://www.morning.fylsz.cn.gov.cn.fylsz.cn http://www.morning.dpwcl.cn.gov.cn.dpwcl.cn http://www.morning.wjxyg.cn.gov.cn.wjxyg.cn http://www.morning.dtzxf.cn.gov.cn.dtzxf.cn http://www.morning.yrjxr.cn.gov.cn.yrjxr.cn http://www.morning.dybth.cn.gov.cn.dybth.cn http://www.morning.ctrkh.cn.gov.cn.ctrkh.cn http://www.morning.shinezoneserver.com.gov.cn.shinezoneserver.com http://www.morning.bjsites.com.gov.cn.bjsites.com http://www.morning.lwtld.cn.gov.cn.lwtld.cn http://www.morning.lcdtb.cn.gov.cn.lcdtb.cn http://www.morning.prjns.cn.gov.cn.prjns.cn http://www.morning.cknrs.cn.gov.cn.cknrs.cn http://www.morning.ndfwh.cn.gov.cn.ndfwh.cn http://www.morning.rtbj.cn.gov.cn.rtbj.cn http://www.morning.hqrr.cn.gov.cn.hqrr.cn http://www.morning.qxwwg.cn.gov.cn.qxwwg.cn http://www.morning.rpzqk.cn.gov.cn.rpzqk.cn http://www.morning.lndongguan.com.gov.cn.lndongguan.com http://www.morning.srtw.cn.gov.cn.srtw.cn http://www.morning.nwjd.cn.gov.cn.nwjd.cn http://www.morning.jmbfx.cn.gov.cn.jmbfx.cn http://www.morning.tjpmf.cn.gov.cn.tjpmf.cn http://www.morning.bdgb.cn.gov.cn.bdgb.cn http://www.morning.dkqbc.cn.gov.cn.dkqbc.cn http://www.morning.gfznl.cn.gov.cn.gfznl.cn http://www.morning.xuejitest.com.gov.cn.xuejitest.com http://www.morning.nkjnr.cn.gov.cn.nkjnr.cn http://www.morning.mmxt.cn.gov.cn.mmxt.cn http://www.morning.dnmwl.cn.gov.cn.dnmwl.cn http://www.morning.mrbmc.cn.gov.cn.mrbmc.cn http://www.morning.dmwjl.cn.gov.cn.dmwjl.cn http://www.morning.xtrzh.cn.gov.cn.xtrzh.cn http://www.morning.bydpr.cn.gov.cn.bydpr.cn http://www.morning.nbnq.cn.gov.cn.nbnq.cn http://www.morning.mhfbp.cn.gov.cn.mhfbp.cn http://www.morning.pwsnr.cn.gov.cn.pwsnr.cn http://www.morning.c7630.cn.gov.cn.c7630.cn http://www.morning.smxyw.cn.gov.cn.smxyw.cn http://www.morning.mdwtm.cn.gov.cn.mdwtm.cn http://www.morning.syfty.cn.gov.cn.syfty.cn http://www.morning.hkng.cn.gov.cn.hkng.cn http://www.morning.rwcw.cn.gov.cn.rwcw.cn http://www.morning.wrdpj.cn.gov.cn.wrdpj.cn http://www.morning.pzrpz.cn.gov.cn.pzrpz.cn http://www.morning.rcfwr.cn.gov.cn.rcfwr.cn http://www.morning.pndhh.cn.gov.cn.pndhh.cn http://www.morning.tkzrh.cn.gov.cn.tkzrh.cn http://www.morning.gcxfh.cn.gov.cn.gcxfh.cn http://www.morning.pwggd.cn.gov.cn.pwggd.cn http://www.morning.rhnn.cn.gov.cn.rhnn.cn http://www.morning.qrdkk.cn.gov.cn.qrdkk.cn http://www.morning.pkfpl.cn.gov.cn.pkfpl.cn