当前位置: 首页 > news >正文

QT实现固高运动控制卡示波器

目录

一、固高示波器

二、基于QCustomPlot实现示波器

三、完整源码


一、固高示波器

        固高运动控制卡自带的软件有一个示波器功能,可以实时显示速度的波形,可辅助分析电机的运行状态。但是我们基于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.h"namespace 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_H

OscilloscopeFrame.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);}
}

相关文章:

QT实现固高运动控制卡示波器

目录 一、固高示波器 二、基于QCustomPlot实现示波器 三、完整源码 一、固高示波器 固高运动控制卡自带的软件有一个示波器功能&#xff0c;可以实时显示速度的波形&#xff0c;可辅助分析电机的运行状态。但是我们基于sdk开发了自己的软件&#xff0c;无法再使用该功能&…...

洛谷P1157详解(两种解法,一看就会)

一、问题引出 组合的输出 题目描述 排列与组合是常用的数学方法&#xff0c;其中组合就是从 n n n 个元素中抽出 r r r 个元素&#xff08;不分顺序且 r ≤ n r \le n r≤n&#xff09;&#xff0c;我们可以简单地将 n n n 个元素理解为自然数 1 , 2 , … , n 1,2,\dot…...

JavaScript异步编程和回调

目录 1、编程语言中的异步 2、JavaScript 3、回调 &#xff13;.&#xff11;在回调中处理错误 &#xff13;.&#xff12;回调的问题 &#xff13;.&#xff12;回调的替代方案 1、编程语言中的异步 默认情况下&#xff0c;JavaScript是同步的&#xff0c;并且是单线程…...

Qt开发笔记(Qt5.9.9下载安装环境搭建win10)

#1 Qt下载网站&#xff08;国内、国外镜像&#xff09; #2 Qt5.9.9安装选项 #3 配置系统环境变量 #4 创建测试项目 #1 Qt下载网站&#xff08;国内、国外镜像&#xff09; 官方下载地址&#xff08;慢&#xff09;&#xff1a;http://download.qt.io/ 国内镜像网站 这里给大家…...

使用Plist编辑器——简单入门指南

本指南将介绍如何使用Plist编辑器。您将学习如何打开、编辑和保存plist文件&#xff0c;并了解plist文件的基本结构和用途。跟随这个简单的入门指南&#xff0c;您将掌握如何使用Plist编辑器轻松管理您的plist文件。 plist文件是一种常见的配置文件格式&#xff0c;用于存储应…...

Python常用的开发工具合集

​ Python是一种功能强大且易于学习的编程语言&#xff0c;被广泛应用于数据科学、机器学习、Web开发等领域。随着Python在各个领域的应用越来越广泛&#xff0c;越来越多的Python开发工具也涌现出来。但是&#xff0c;对于新手来说&#xff0c;选择一款合适的Python开发工具可…...

机器学习之线性回归

往期目录 python在线性规划中的应用 文章目录 一、线性回归算法概述1.1 什么是线性回归&#xff1f;1.2 线性回归算法原理1.3 线性回归的应用场景 二、线性回归算法Python实现2.1 导入必要的库2.2 随机生成数据集2.3 拟合模型2.4 预测结果2.5 结果可视化 三、完整代码 线性回归…...

中国系统正式发声!所有用户永久免费,网友:再见了,CentOS!

点关注公众号&#xff0c;回复“1024”获取2TB学习资源&#xff01; 如果说&#xff1a;没有操作系统会怎么样&#xff1f; 对于个PC来说&#xff0c;无论是台式机、笔记本、平板等等&#xff0c;一切都变的一无是处&#xff0c;这些硬件对我们来说&#xff0c;和一堆废铁没什么…...

Oracle数据库坏块类故障

正常的数据块有其特有的固定格式&#xff0c;如果某数据块内部出现了混乱而导致Oracle无法读取&#xff0c;则可称其为坏块。数据库坏块的影响范围可大可小&#xff0c;严重时会导致数据库无法打开。当数据库出现坏块时&#xff0c;一般出现ORA-01578错误、ORA-10632错误或者OR…...

andorid之摄像头驱动流程--MTK平台

camera成像原理&#xff1a; 景物通过镜头生产光学图像投射到sensor表面上&#xff0c;然后转为模拟电信号&#xff0c;经过数模变成数字图像信号&#xff0c;在经过DSP加工出来&#xff0c;然后在通过IO接口传输到CPU处理。 由于摄像头满足总线、驱动、设备模型&#xff0c;…...

Android9.0 iptables用INetd实现屏蔽ip黑名单的实现

1.前言 在9.0的系统rom定制化开发中,在system中netd网络这块的产品需要中,会要求设置屏蔽ip地址之内的功能,liunx中iptables命令也是比较重要的,接下来就来在INetd这块实现屏蔽ip黑名单的的相关功能,就是在app中只能屏蔽某个网址,就是除了这个网址,其他的都能上网,最后…...

介绍一下json

目录 介绍一下json Elasticsearch7.6学习指南 介绍一下json JSON&#xff08;JavaScript Object Notation&#xff09;是一种轻量级的数据交换格式&#xff0c;它以易于阅读和编写的文本形式表示结构化数据。JSON最初是由Douglas Crockford在2001年提出的&#xff0c;它在we…...

DI依赖注入环境

1.构造器注入 上一章节已经说过了&#xff1a; <?xml version"1.0" encoding"UTF-8"?> <beans xmlns"http://www.springframework.org/schema/beans"xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLoca…...

《程序员面试金典(第6版)》面试题 16.18. 模式匹配(暴力破解 + 剪枝)

题目描述 你有两个字符串&#xff0c;即pattern和value。 pattern字符串由字母"a"和"b"组成&#xff0c;用于描述字符串中的模式。 例如&#xff0c;字符串"catcatgocatgo"匹配模式"aabab"&#xff08;其中"cat"是"a&q…...

一天吃透SpringCloud面试八股文

1、什么是Spring Cloud &#xff1f; Spring cloud 流应用程序启动器是基于 Spring Boot 的 Spring 集成应用程序&#xff0c;提供与外部系统的集成。Spring cloud Task&#xff0c;一个生命周期短暂的微服务框架&#xff0c;用于快速构建执行有限数据处理的应用程序。 Sprin…...

java生成图片缩略图

目录 前言一、使用Base64编码方式1、基本方法2、压缩本地图片保存到本地3、压缩网络图片到图片服务器 二、使用thumbnailator工具方式1、导入依赖2、压缩本地图片保存到本地 前言 下面介绍了两种获取图片缩略图的方式&#xff0c;全都不是一次性压缩&#xff0c;如果没有达到设…...

《统计学习方法》——隐马尔可夫模型(下)

学习算法 HMM的学习&#xff0c;在有观测序列的情况下&#xff0c;根据训练数据是否包含状态序列&#xff0c;可以分别由监督学习算法和无监督学习算法实现。 监督学习算法 监督学习算法就比较简单&#xff0c;基于已有的数据利用极大似然估计法来估计隐马尔可夫模型的参数。…...

Liunx top 命令详解

文章目录 top补充说明语法选项top交互命令实例 top 显示或管理执行中的程序 补充说明 top命令 可以实时动态地查看系统的整体运行情况&#xff0c;是一个综合了多方信息监测系统性能和运行信息的实用工具。通过top命令所提供的互动式界面&#xff0c;用热键可以管理。 语法…...

基于 SpringBoot 的医院固定资产系统

本文将介绍基于 SpringBoot 技术的医院固定资产系统的设计和实现。医院固定资产管理是医疗机构管理工作的重要组成部分&#xff0c;它对医院的正常运营和管理具有重要的意义。本系统的设计和实现将有助于医疗机构更好地管理和维护其固定资产。 1. 系统需求分析 医院固定资产管…...

【企业信息化】第2集 免费开源ERP: Odoo 16 销售管理系统

文章目录 前言一、概览二、使用功能1.通过清晰报价提高销售效率2.创建专业报价单3.管理订单及合同4.简化沟通5.维护产品&价格6.直观的报告7.集成 三、总结 前言 世界排名第一的免费开源ERP: Odoo 16 销售管理系统。通过Odoo Sign应用程序和在线支付&#xff0c;发送报价。…...

【Axure高保真原型】引导弹窗

今天和大家中分享引导弹窗的原型模板&#xff0c;载入页面后&#xff0c;会显示引导弹窗&#xff0c;适用于引导用户使用页面&#xff0c;点击完成后&#xff0c;会显示下一个引导弹窗&#xff0c;直至最后一个引导弹窗完成后进入首页。具体效果可以点击下方视频观看或打开下方…...

Chapter03-Authentication vulnerabilities

文章目录 1. 身份验证简介1.1 What is authentication1.2 difference between authentication and authorization1.3 身份验证机制失效的原因1.4 身份验证机制失效的影响 2. 基于登录功能的漏洞2.1 密码爆破2.2 用户名枚举2.3 有缺陷的暴力破解防护2.3.1 如果用户登录尝试失败次…...

IT供电系统绝缘监测及故障定位解决方案

随着新能源的快速发展&#xff0c;光伏电站、储能系统及充电设备已广泛应用于现代能源网络。在光伏领域&#xff0c;IT供电系统凭借其持续供电性好、安全性高等优势成为光伏首选&#xff0c;但在长期运行中&#xff0c;例如老化、潮湿、隐裂、机械损伤等问题会影响光伏板绝缘层…...

嵌入式学习笔记DAY33(网络编程——TCP)

一、网络架构 C/S &#xff08;client/server 客户端/服务器&#xff09;&#xff1a;由客户端和服务器端两个部分组成。客户端通常是用户使用的应用程序&#xff0c;负责提供用户界面和交互逻辑 &#xff0c;接收用户输入&#xff0c;向服务器发送请求&#xff0c;并展示服务…...

怎么让Comfyui导出的图像不包含工作流信息,

为了数据安全&#xff0c;让Comfyui导出的图像不包含工作流信息&#xff0c;导出的图像就不会拖到comfyui中加载出来工作流。 ComfyUI的目录下node.py 直接移除 pnginfo&#xff08;推荐&#xff09;​​ 在 save_images 方法中&#xff0c;​​删除或注释掉所有与 metadata …...

永磁同步电机无速度算法--基于卡尔曼滤波器的滑模观测器

一、原理介绍 传统滑模观测器采用如下结构&#xff1a; 传统SMO中LPF会带来相位延迟和幅值衰减&#xff0c;并且需要额外的相位补偿。 采用扩展卡尔曼滤波器代替常用低通滤波器(LPF)&#xff0c;可以去除高次谐波&#xff0c;并且不用相位补偿就可以获得一个误差较小的转子位…...

MyBatis中关于缓存的理解

MyBatis缓存 MyBatis系统当中默认定义两级缓存&#xff1a;一级缓存、二级缓存 默认情况下&#xff0c;只有一级缓存开启&#xff08;sqlSession级别的缓存&#xff09;二级缓存需要手动开启配置&#xff0c;需要局域namespace级别的缓存 一级缓存&#xff08;本地缓存&#…...

Modbus RTU与Modbus TCP详解指南

目录 1. Modbus协议基础 1.1 什么是Modbus? 1.2 Modbus协议历史 1.3 Modbus协议族 1.4 Modbus通信模型 🎭 主从架构 🔄 请求响应模式 2. Modbus RTU详解 2.1 RTU是什么? 2.2 RTU物理层 🔌 连接方式 ⚡ 通信参数 2.3 RTU数据帧格式 📦 帧结构详解 🔍…...

区块链技术概述

区块链技术是一种去中心化、分布式账本技术&#xff0c;通过密码学、共识机制和智能合约等核心组件&#xff0c;实现数据不可篡改、透明可追溯的系统。 一、核心技术 1. 去中心化 特点&#xff1a;数据存储在网络中的多个节点&#xff08;计算机&#xff09;&#xff0c;而非…...

倒装芯片凸点成型工艺

UBM&#xff08;Under Bump Metallization&#xff09;与Bump&#xff08;焊球&#xff09;形成工艺流程。我们可以将整张流程图分为三大阶段来理解&#xff1a; &#x1f527; 一、UBM&#xff08;Under Bump Metallization&#xff09;工艺流程&#xff08;黄色区域&#xff…...