基于opencv的图像分析,PID算法,串口发送,单片机接收,输出脉冲继而控制步进电机转动

该博客详细介绍了如何通过OpenCV进行图像分析,结合PID算法进行控制,并利用Qt实现串口通信,将数据发送到单片机,由单片机输出脉冲来控制步进电机的转动。主要涉及了图像处理、PID控制理论以及串口通信技术。
摘要由CSDN通过智能技术生成
基于opencv的图像分析串口发送,单片机接收,输出脉冲继而控制步进电机转动



mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QDebug>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#include "imagebuffer.h"
#include "wlinkusbcamera.h"
using namespace cv;
#include<QTimer>
namespace Ui {
   
class MainWindow;
}
class MainWindow : public QMainWindow
{
   
    Q_OBJECT
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    void Init() ;
    void PidControl(int,int,int,int);
    void sendSerialPortData(long , char,long );
    void handleSerialError(QSerialPort::SerialPortError error,bool &);
private slots:
    void on_clearButton_clicked();
    void on_sendButton_clicked();
    void on_openButton_clicked();
    void Read_Data();
    void slot1();
    void on_PidChange_valueChanged(int value);
    void on_PidChange_sliderReleased();
    void on_PidChange_sliderPressed();
    void on_pushButton_clicked();
    void on_pushButton_2_clicked();
    void on_pushButton_3_clicked();
private:
    Ui::MainWindow *ui;
    QSerialPort *serial;
    WLinkUsbCamera *tab ;
    QTimer *timer;
    int LastError;               //Error[-1]上一次
    int PrevError;               //Error[-2]上两次
    int Output;
};
#endif // MAINWINDOW_H


mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <opencv2/opencv.hpp>
#include "opencv2\highgui\highgui.hpp"
#include <QMessageBox>
#include<QDebug>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),LastError(0),PrevError(0),Output(0)
{
  
    ui->setupUi(this);
    Init();
    qDebug()<<"sioflong"<<sizeof(long)<<sizeof(int)<<sizeof(char);
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值