凌华运动控制卡AMP_204C_Qt C++调试

运行效果图
在这里插入图片描述
**一、 调试前准备工作
1.硬件平台
1.工控机(本人使用Win7 64位系统) 2.凌华AMP-204C运动控制卡一套 3. 步进电机和驱动器一套

2.开发软件
1.AMP-204C驱动安装(驱动下载网址如下)
https://www.adlinktech.com/Products/Motion_Control/CentralizedMotionControllers/AMP-204C_AMP-208C?lang=zh-cn

2.Qt5.9.8软件(官网下载缓慢,可以在清华大学开源镜像站下载)
https://mirrors.tuna.tsinghua.edu.cn/qt/official_releases/qt/5.9/5.9.8/

运动控制卡驱动安装完成后,打开MotionCreatorPro2运动控制卡配置软件,完成每个轴的参数配置,最后保存参数到板卡Flash中(本人在调试过程中,在板卡初始化时,用的是从板卡的Flash初始化参数的方式。当然也可以将配置的参数保存为.ini文件,初始化板卡时,使用文件初始化板卡参数)。

二、开始程序的编写

1.打开安装的Qt Creater软件依次选择 文件 > 新建 > Qt Widget Application 输入项目名(我在这里命名为Motion) > 选择QWidget基类(默认创建类名为Widget)的窗体类。
创建的项目文件如下图:
在这里插入图片描述
2.打开安装运动控制卡驱动时创建的ADLINK文件夹(我的文件夹如下C:\Program Files (x86)\ADLINK\APS Library)找到如下几个文件
在这里插入图片描述
将这六个文件复制到Qt创建的Motion文件夹下
在这里插入图片描述
注意事项:(在导入APS168.h文件时,需要将该文件的内容转换为UTF-8格式,否则Qt编译时会报错)可以使用Notepad++软件将文件内容转换格式

3.返回Qt双击Motion.pro文件,在文件中添加下图两行代码
在这里插入图片描述
4.完成ui界面的设计
UI界面设计图
5.创建Motion类,用于封装板卡的库函数,实现相应的功能

Motion.h文件内容如下

#ifndef MOTION_H
#define MOTION_H

#include "type_def.h"
#include "ErrorCodeDef.h"
#include "APS_Define.h"
#include "APS168.h"

#define ON  (1)
#define OFF (0)
#define Step (0)
#define Cont (1)

class Motion
{
public:
    Motion(I32 board_id, I32 axis_id, I32 mode, I32 position);
    ~Motion();
    I32 Get_Board_ID();
    I32 Get_Axis_ID();
    I32 Get_Di_Data();

public:
    I32 Motion_Init();
    I32 Motion_Close();
    I32 Motion_Stop_Move();
    I32 Motion_Load_Parameter_From_Flash();
    I32 Motion_Servo_On();
    I32 Motion_Servo_Off();
    I32 Motion_Home(F64 ACC, F64 VM, I32 Direction);
    I32 Motion_Absolute_Move(I32 Position, I32 Max_Speed, I32 ACC);
    I32 Motion_Jog_P(F64 ACC, F64 VM, I32 Mode);
    I32 Motion_Jog_N(F64 ACC, F64 VM, I32 Mode);
    I32 Motion_Jog_Stop();
    I32 Motion_State(I32 Axis_ID);
    I32 Motion_Get_Current_Position();
    F64 Motion_Current_Position();
    I32 Motion_Set_Current_Position_Zero();
    I32 Motion_Write_D_Group_output(I32 Board_ID, I32 Do_Group, I32 Do_Data);
    I32 Motion_Write_D_Channel_Output(I32 Board_ID, I32 Do_Group, I32 Ch_No, I32 Do_Data);
    I32 Motion_Read_D_Input(I32 Board_ID, I32 Di_Group);

private:
    const I32 Board_ID;
    I32 Axis_ID;
    I32 Mode;
    F64 Position;
    I32 JogMode;
    I32 Di_Data;
};

#endif // MOTION_H

Motion.cpp文件如下:

#include "motion.h"

Motion::Motion(I32 board_id, I32 axis_id, I32 mode, I32 position ):Board_ID(board_id)
{
    Axis_ID = axis_id;
    Mode = mode;
    Position = position;
    Di_Data = 0;
}

Motion::~Motion()
{

}


I32 Motion::Get_Board_ID()
{
    return Board_ID;
}

I32 Motion::Get_Axis_ID()
{
    return Axis_ID;
}

I32 Motion::Get_Di_Data()
{
    return Di_Data;
}


I32 Motion::Motion_Init()
{
    I32 ret = 0;
    I32 board_id = Board_ID;
    APS_initial(&board_id, Mode);

    return ret;
}

I32 Motion::Motion_Close()
{
    I32 ret = 0;
    ret = APS_close();

    return ret;
}

I32 Motion::Motion_Stop_Move()
{
    I32 ret = 0;
    APS_stop_move(Axis_ID);

    return ret;
}

I32 Motion::Motion_Load_Parameter_From_Flash()
{
    I32 ret = 0;
    ret = APS_load_parameter_from_flash(Board_ID);

    return ret;
}

I32 Motion::Motion_Servo_On()
{
    I32 ret = 0;
    ret = APS_set_servo_on(Axis_ID, ON);

    return ret;
}

I32 Motion::Motion_Servo_Off()
{
    I32 ret = 0;
    ret = APS_set_servo_on(Axis_ID, OFF);

    return ret;
}

I32 Motion::Motion_Home(F64 ACC, F64 VM, I32 Direction)
{
    I32 ret = 0;

    APS_set_axis_param(Axis_ID, PRA_HOME_MODE, 0);
    APS_set_axis_param(Axis_ID, PRA_HOME_DIR, Direction);
    APS_set_axis_param_f(Axis_ID, PRA_HOME_CURVE, 0);
    APS_set_axis_param_f(Axis_ID, PRA_HOME_ACC, ACC);
    APS_set_axis_param_f(Axis_ID, PRA_HOME_VM, VM);
    APS_set_axis_param_f(Axis_ID, PRA_HOME_VO, 0);
    APS_set_axis_param(Axis_ID, PRA_HOME_EZA, 0);
    APS_set_axis_param_f(Axis_ID, PRA_HOME_SHIFT, 0);
    APS_set_axis_param_f(Axis_ID, PRA_HOME_POS, 0);

    Motion_Servo_On();
    Sleep(500);

    ret = APS_home_move(Axis_ID);
    if( ret != ERR_NoError )
    {
        /* Error handling */
    }

    return ret;
}

I32 Motion::Motion_Absolute_Move(I32 Position, I32 Max_Speed, I32 ACC)
{
    I32 ret = 0;
    APS_set_axis_param(Axis_ID, PRA_ACC, ACC);
    APS_set_axis_param(Axis_ID, PRA_DEC, ACC);
    APS_absolute_move(Axis_ID, Position, Max_Speed);

    return ret;
}

I32 Motion::Motion_Jog_P(F64 ACC, F64 VM, I32 JogMode)
{
    I32 ret = 0;

    APS_set_axis_param(Axis_ID, PRA_JG_MODE, JogMode);
    APS_set_axis_param(Axis_ID, PRA_JG_DIR, 1);

    APS_set_axis_param_f( Axis_ID, PRA_JG_CURVE, 0.0  );
    APS_set_axis_param_f( Axis_ID, PRA_JG_ACC, ACC );
    APS_set_axis_param_f( Axis_ID, PRA_JG_DEC, ACC );
    APS_set_axis_param_f( Axis_ID, PRA_JG_VM,  VM  );

    if( !( (APS_motion_io_status(Axis_ID) >> MIO_SVON) & 1) )
    {
        Motion_Servo_On();
    }

    Sleep(500);
    APS_jog_start(Axis_ID, OFF);
    ret = APS_jog_start(Axis_ID, ON);

    return ret;
}

I32 Motion::Motion_Jog_N(F64 ACC, F64 VM, I32 JogMode)
{
    I32 ret = 0;

    APS_set_axis_param(Axis_ID, PRA_JG_MODE, JogMode);
    APS_set_axis_param(Axis_ID, PRA_JG_DIR, 0);

    APS_set_axis_param_f( Axis_ID, PRA_JG_CURVE, 0.0  );
    APS_set_axis_param_f( Axis_ID, PRA_JG_ACC, ACC );
    APS_set_axis_param_f( Axis_ID, PRA_JG_DEC, ACC );
    APS_set_axis_param_f( Axis_ID, PRA_JG_VM,  VM  );

    if( !( (APS_motion_io_status(Axis_ID) >> MIO_SVON) & 1) )
    {
        Motion_Servo_On();
    }

    Sleep(500);
    APS_jog_start(Axis_ID, OFF);
    ret = APS_jog_start(Axis_ID, ON);

    return ret;
}

I32 Motion::Motion_Jog_Stop()
{
    I32 ret = 0;
    ret = APS_jog_start(Axis_ID, OFF);

    return ret;
}

I32 Motion::Motion_State(I32 Axis_ID)
{
    I32 ret = 0;
    ret = APS_motion_status(Axis_ID);

    return ret;
}

I32 Motion::Motion_Get_Current_Position()
{
    I32 ret = 0;
    ret = APS_get_position_f(Axis_ID, &Position);

    return ret;
}

F64 Motion::Motion_Current_Position()
{
    F64 postion;
    postion = this->Position;

    return postion;
}

I32 Motion::Motion_Set_Current_Position_Zero()
{
    I32 ret = 0;
    ret = APS_set_position(Axis_ID, 0);

    return ret;
}

I32 Motion::Motion_Write_D_Group_output(I32 Board_ID, I32 Do_Group, I32 Do_Data)
{
    I32 ret = 0;
    APS_write_d_output(Board_ID, Do_Group, Do_Data);

    return ret;
}

I32 Motion::Motion_Write_D_Channel_Output(I32 Board_ID, I32 Do_Group, I32 Ch_No, I32 Do_Data)
{
    I32 ret = 0;
    ret = APS_write_d_channel_output(Board_ID, Do_Group, Ch_No, Do_Data);

    return ret;
}

I32 Motion::Motion_Read_D_Input(I32 Board_ID, I32 Di_Group)
{
    I32 ret = 0;
    ret = APS_read_d_input(Board_ID, Di_Group, &(this->Di_Data));

    return ret;
}


6.Widget窗体主函数实现如下:

Widget.h文件:

#include "widget.h"
#include "ui_widget.h"
#include <QDebug>

bool Widget::m_OutputFlag = true;   // 初始化Output Flag

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    Fun_Init_Widget();
    Fun_Init_Motion();
    Fun_Motion_Action();
    Fun_Start_Thread_Position();
    Fun_Start_Thread_Working();
    Fun_Start_Thread_Input();
    Fun_Signal_Connect();
}

Widget::~Widget()
{
    delete ui;

    delete m_pMotion;
    m_pMotion = nullptr;

    delete m_pThreadPosition;
    m_pThreadPosition = nullptr;

    delete m_pThreadWorking;
    m_pThreadWorking = nullptr;

    delete m_pThreadInput;
    m_pThreadInput = nullptr;
}


/******系统函数实现******/
void Widget::closeEvent(QCloseEvent *event) //该函数系统函数,关闭窗口时执行
{
    Fun_Stop_Thread_Position();
    Fun_Stop_Thread_Working();
    Fun_Stop_Thread_Input();
    Fun_Motion_Close();

    event->accept();
}

void Widget::paintEvent(QPaintEvent *event) //该函数为系统函数,用于绘制窗口
{
    QPainter painter(this);

    QPen pen;
    pen.setColor(Qt::blue);
    painter.setPen(pen);

    QBrush brush;
    brush.setColor(Qt::blue);
    painter.setBrush(brush);

//    painter.setWindow(0, 0, this->width(), this->height());
//    painter.drawRect(rect());
//    painter.drawRect(10, 10, this->width(), this->height());
//    QPixmap pixmap;
//    pixmap.load(":/res/ADLINK.ico");
//    painter.drawPixmap(0, 0, this->width(), this->height(), pixmap);

    event->accept();
}


/******成员函数实现******/
void Widget::Fun_Init_Widget()  //窗口初始化函数
{
    ui->setupUi(this);

    //设置窗口标题、图标和各参数的默认值
    this->setWindowTitle("Motion");
    this->setWindowIcon( QIcon(":/Photo/ADLINK.ico") );
    ui->lineEditACC->setText("4000000");
    ui->lineEditVM->setText("400000");
    ui->lineEditAbsPos->setText("0");

    //设置背景色
    QPalette WinPat(this->palette());
    WinPat.setColor(QPalette::Background, QColor(128, 255, 255));
    this->setPalette(WinPat);

    //LCD的屏幕显示设置
    QPalette lcdpat = ui->lcdPosition->palette();
    lcdpat.setColor(QPalette::Normal, QPalette::WindowText, Qt::red);
    ui->lcdPosition->setPalette(lcdpat);

    bool isOK = false;
    QInputDialog input;
    m_Axis_ID = input.getInt(this, "Axis_ID", "Axis_ID Input", 0, 0, 3, 1, &isOK, Qt::WindowFlags(nullptr));
    if(!isOK)
    {
        m_Axis_ID = 0;
    }
}

void Widget::Fun_Init_Motion()  //轴初始化函数
{
    m_pMotion = new Motion(0, this->m_Axis_ID, 0, 0);
    m_pMotion->Motion_Init();
    m_pMotion->Motion_Load_Parameter_From_Flash();
    m_pMotion->Motion_Write_D_Group_output(0, 0, 0);
}

void Widget::Fun_Motion_Action()    //轴功能实现函数
{
    //Servo On实现
    connect(ui->btnMotorOn, &QPushButton::pressed, [=](){
        if(m_ServoFlag == false)
        {
            m_pMotion->Motion_Write_D_Channel_Output(m_pMotion->Get_Board_ID(), 0, 8, true);
            m_pMotion->Motion_Servo_On();
            m_ServoFlag = true;
            ui->btnMotorOn->setText("点击下电");
        }
        else
        {
            m_pMotion->Motion_Servo_Off();
            m_pMotion->Motion_Write_D_Channel_Output(m_pMotion->Get_Board_ID(), 0, 8, false);
            m_ServoFlag = false;
            ui->btnMotorOn->setText("点击上电");
        }
    });

    //Jog+实现
    connect(ui->btnJogP, &QPushButton::pressed, [=](){
        m_pMotion->Motion_Jog_P(ui->lineEditACC->text().toDouble(), ui->lineEditVM->text().toDouble(), ui->comboBoxJogMode->currentIndex());
        connect(ui->btnJogP, &QPushButton::released, [=](){
            m_pMotion->Motion_Jog_Stop();
        });
    });

    //Jog-实现
    connect(ui->btnJogN, &QPushButton::pressed, [=](){
        m_pMotion->Motion_Jog_N(ui->lineEditACC->text().toDouble(), ui->lineEditVM->text().toDouble(), ui->comboBoxJogMode->currentIndex());
        connect(ui->btnJogN, &QPushButton::released, [=](){
            m_pMotion->Motion_Jog_Stop();
        });
    });

    //AbsMove实现
    connect(ui->btnAbsMove, &QPushButton::pressed, [=](){
        m_pMotion->Motion_Absolute_Move(ui->lineEditAbsPos->text().toInt(), ui->lineEditVM->text().toInt(), ui->lineEditACC->text().toInt());
    });

    //GoHome实现
    connect(ui->btnGoHome, &QPushButton::pressed, [=](){
        m_pMotion->Motion_Home(ui->lineEditACC->text().toDouble(), ui->lineEditVM->text().toDouble(), ui->comboBoxHomeDir->currentIndex());
    });

    //Stop Move
    connect(ui->btnStop, &QPushButton::pressed, [=](){
        m_pMotion->Motion_Stop_Move();
    });

    //当前位置设置为该轴的0点
    connect(ui->btnSetCurPosIsZero, &QPushButton::pressed, [=](){
        m_pMotion->Motion_Set_Current_Position_Zero();
    });

    //Line单个端口输出
    connect(ui->btnOutput, &QPushButton::pressed, [=](){
        if(m_OutputFlag)
        {
            m_pMotion->Motion_Write_D_Channel_Output(0, 0, ui->comboBoxOutput->currentIndex()+8, 1);
            m_OutputFlag = false;
        }
        else
        {
            m_pMotion->Motion_Write_D_Channel_Output(0, 0, ui->comboBoxOutput->currentIndex()+8, 0);
            m_OutputFlag = true;
        }
    });
}

void Widget::Fun_Motion_Close()
{
    m_pMotion->Motion_Write_D_Group_output(0, 0, 0);
    m_pMotion->Motion_Close();
}

void Widget::Fun_Start_Thread_Position()    //Position点位实时显示开启线程
{
    m_pThreadPosition = new ThreadPosition(ui, m_pMotion);
    Fun_Stop_Thread_Position();
    m_pThreadPosition->Fun_Start_Thread();
    m_pThreadPosition->start();
}

void Widget::Fun_Stop_Thread_Position() //Position点位实时显示关闭线程
{
    if(m_pThreadPosition->isRunning())
    {
        m_pThreadPosition->Fun_Stop_Thread();
        m_pThreadPosition->quit();
        m_pThreadPosition->wait();
    }
}

void Widget::Fun_Start_Thread_Working() //Working线程开启函数
{
    m_pThreadWorking = new ThreadWorking(ui, m_pMotion);

    connect(ui->btnStartWorking, &QPushButton::clicked, [=](){
        if(m_pThreadWorking->isRunning())
        {
            return;
        }
        m_pThreadWorking->Slot_Start_Thread();
        m_pThreadWorking->start();
    });

    connect(ui->btnStopWorking, &QPushButton::clicked, [=](){
        Fun_Stop_Thread_Working();
    });
}

void Widget::Fun_Stop_Thread_Working()  //Working线程关闭函数
{
    if(m_pThreadWorking->isRunning())
    {
        m_pThreadWorking->Slot_Stop_Thread();
        m_pThreadWorking->quit();
        m_pThreadWorking->wait();
    }
}

void Widget::Fun_Start_Thread_Input()   //Input信号实时采集开启线程
{
    m_pThreadInput = new ThreadInput(m_pMotion, ui);
    m_pThreadInput->Fun_Start_Thread();
    m_pThreadInput->start();
}

void Widget::Fun_Stop_Thread_Input()    //Input信号实时采集关闭线程
{
    m_pThreadInput->Fun_Stop_Thread();
    m_pThreadInput->quit();
    m_pThreadInput->wait();
}

void Widget::Fun_Signal_Connect()   //用于Working线程的信号链接
{
    void (ThreadWorking::*pSignalMsg)(QString) = &ThreadWorking::Signal_Send_Move_OK;
    connect(m_pThreadWorking, pSignalMsg, this, &Widget::Slot_Msg_Show);
}

/******槽函数实现******/
void Widget::Slot_Msg_Show(QString str)
{
    QMessageBox msg(this);
    msg.setText(str);
    msg.exec();
}

7.各子线程的代码实现:

7.1点位实时采集:
ThreadPosition.h代码

#ifndef THREADPOSITION_H
#define THREADPOSITION_H

#include <QObject>
#include <QThread>
#include <QTimer>
#include "ui_widget.h"
#include "motion.h"

class ThreadPosition : public QThread
{
    Q_OBJECT
public:
    ThreadPosition(Ui::Widget* _ui, Motion* _motion);
    ~ThreadPosition();

    void Fun_Start_Thread();
    void Fun_Stop_Thread();

signals:

public slots:

protected:
    void run();

private:
    bool m_isStart = false;
    Ui::Widget* m_pUi = nullptr;
    Motion* m_pMotion = nullptr;
};

#endif // THREADPOSITION_H

ThreadPosition.cpp代码

#include "threadposition.h"
#include <QDebug>

ThreadPosition::ThreadPosition(Ui::Widget* _ui, Motion* _motion)
{
    m_pUi = _ui;
    m_pMotion = _motion;
}

ThreadPosition::~ThreadPosition()
{

}

void ThreadPosition::run()
{
    while(m_isStart)
    {
        m_pMotion->Motion_Get_Current_Position();
        msleep(10);
        m_pUi->lcdPosition->display(m_pMotion->Motion_Current_Position());
    }
}


/******成员函数实现******/
void ThreadPosition::Fun_Start_Thread()
{
    m_isStart = true;
}

void ThreadPosition::Fun_Stop_Thread()
{
    m_isStart = false;
}

7.2 Input输入端实时采集线程

ThreadInput.h

#ifndef THREADINPUT_H
#define THREADINPUT_H

#include <QObject>
#include <QThread>
#include <QTimer>
#include "motion.h"
#include "ui_widget.h"

class ThreadInput : public QThread
{
    Q_OBJECT
public:
    ThreadInput(Motion* _motion, Ui::Widget* _ui);
    ~ThreadInput();

    void Fun_Start_Thread();
    void Fun_Stop_Thread();

protected:
    void run();

private:
    bool m_isStart = false;
    Motion* m_pMotion = nullptr;
    Ui::Widget* m_pUi = nullptr;
};

#endif // THREADINPUT_H

ThreadInput.cpp代码

#include "threadinput.h"

ThreadInput::ThreadInput(Motion* _motion, Ui::Widget* _ui)
{
    m_pMotion = _motion;
    m_pUi = _ui;
}

ThreadInput::~ThreadInput()
{

}

void ThreadInput::run()
{
    while(m_isStart)
    {
        m_pMotion->Motion_Read_D_Input(m_pMotion->Get_Board_ID(), 0);
        msleep(10);
        m_pUi->Di01->setChecked((m_pMotion->Get_Di_Data() >> 8 ) & 1);
        m_pUi->Di02->setChecked((m_pMotion->Get_Di_Data() >> 9 ) & 1);
        m_pUi->Di03->setChecked((m_pMotion->Get_Di_Data() >> 10 ) & 1);
        m_pUi->Di04->setChecked((m_pMotion->Get_Di_Data() >> 11 ) & 1);
        m_pUi->Di05->setChecked((m_pMotion->Get_Di_Data() >> 12 ) & 1);
        m_pUi->Di06->setChecked((m_pMotion->Get_Di_Data() >> 13 ) & 1);
        m_pUi->Di07->setChecked((m_pMotion->Get_Di_Data() >> 14 ) & 1);
        m_pUi->Di08->setChecked((m_pMotion->Get_Di_Data() >> 15 ) & 1);

        m_pUi->Di09->setChecked((m_pMotion->Get_Di_Data() >> 16 ) & 1);
        m_pUi->Di10->setChecked((m_pMotion->Get_Di_Data() >> 17 ) & 1);
        m_pUi->Di11->setChecked((m_pMotion->Get_Di_Data() >> 18 ) & 1);
        m_pUi->Di12->setChecked((m_pMotion->Get_Di_Data() >> 19 ) & 1);
        m_pUi->Di13->setChecked((m_pMotion->Get_Di_Data() >> 20 ) & 1);
        m_pUi->Di14->setChecked((m_pMotion->Get_Di_Data() >> 21 ) & 1);
        m_pUi->Di15->setChecked((m_pMotion->Get_Di_Data() >> 22 ) & 1);
        m_pUi->Di16->setChecked((m_pMotion->Get_Di_Data() >> 23 ) & 1);
    }
}

void ThreadInput::Fun_Start_Thread()
{
    m_isStart = true;
}

void ThreadInput::Fun_Stop_Thread()
{
    m_isStart = false;
}

7.3 ThreadWorking线程(该线程用于实现相应的工作逻辑)
ThreadWorking.h文件

#ifndef THREADWORKING_H
#define THREADWORKING_H

#include <QObject>
#include <QThread>
#include <QTimer>
#include "ui_widget.h"
#include "motion.h"

class ThreadWorking : public QThread
{
    Q_OBJECT
public:
    ThreadWorking(Ui::Widget* _ui, Motion* _motion);
    ~ThreadWorking();
    void Fun_Start_Thread();
    void Fun_Stop_Thread();
    bool Fun_Check_Motion_Move_OK();

signals:
    void Signal_Send_Move_OK(QString str);

public slots:
    void Slot_Start_Thread();
    void Slot_Stop_Thread();

protected:
    void run();

private:
    bool m_isStart = false;
    Ui::Widget* m_pUi = nullptr;
    Motion* m_pMotion = nullptr;
};

#endif // THREADWORKING_H

ThreadWorking.cpp文件:

#include "threadworking.h"
#include <QDebug>

ThreadWorking::ThreadWorking(Ui::Widget* _ui, Motion* _motion)
{
    m_pUi = _ui;
    m_pMotion = _motion;
}

ThreadWorking::~ThreadWorking()
{

}


/******系统函数实现******/
void ThreadWorking::run()
{
    while(m_isStart)
    {
        m_pMotion->Motion_Read_D_Input(m_pMotion->Get_Axis_ID(), 0);
        msleep(10);
        if( ((m_pMotion->Get_Di_Data())>>8) & 1 )
        {
            m_pMotion->Motion_Absolute_Move(m_pUi->lineEditAbsPos->text().toInt(),
                                            m_pUi->lineEditVM->text().toInt(),
                                            m_pUi->lineEditACC->text().toInt());
            while(!Fun_Check_Motion_Move_OK()){msleep(1);}
        }
        if( ((m_pMotion->Get_Di_Data())>>9) & 1 )
        {
            m_pMotion->Motion_Absolute_Move(-m_pUi->lineEditAbsPos->text().toInt(),
                                            m_pUi->lineEditVM->text().toInt(),
                                            m_pUi->lineEditACC->text().toInt());
            while(!Fun_Check_Motion_Move_OK()){msleep(1);}
        }
    }
}

/******成员函数实现******/
void ThreadWorking::Fun_Start_Thread()
{
    this->m_isStart = true;
}

void ThreadWorking::Fun_Stop_Thread()
{
    this->m_isStart = false;
}

bool ThreadWorking::Fun_Check_Motion_Move_OK()
{
    bool flag = false;
    flag = (m_pMotion->Motion_State(m_pMotion->Get_Axis_ID()) >> 5) & 1;

    return flag;
}

/******槽函数实现******/
void ThreadWorking::Slot_Start_Thread()
{
    this->Fun_Start_Thread();
    qDebug() << "Start";
}

void ThreadWorking::Slot_Stop_Thread()
{
    this->Fun_Stop_Thread();
    qDebug() << "Stop";
}

该线程我只是简单实现了输入Di00有输入信号时,当前使用的轴移至主窗口的AbsMovPos所输入的点位;当Di01有输入信号时,该轴移至负的AbsMovPos所输入点位。

三. 窗体各区域介绍:
在这里插入图片描述
四.总结
该程序通过Qt软件实现了对AMP-204C运动控制卡的基本功能调试工作。可以实现板卡相应的Jog运动、Abs点位运动、回零运动,实现对板卡I/O的输入采集和输出控制。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值