- 工程文件
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES +=
main.cpp
widget.cpp
HEADERS +=
widget.h
FORMS +=
widget.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
RESOURCES +=
spiipldemo.qrc
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/SDK/ -lACSCL_x64
INCLUDEPATH += $$PWD/SDK
DEPENDPATH += $$PWD/SDK
LIBS +=-L$$PWD/SDK -lACSCL_x64
win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/SDK/ACSCL_x64.lib
- 主程序
#include "widget.h"
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
- 窗体程序
#ifndef WIDGET_H
#define WIDGET_H
#include "SDK/ACSC.h"
#include
#include
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
const int MAX_AXIS_COUNT = 128;服务器托管网
const int MAX_BUFF_COUNT = 64;
const int UPDATE_TIMER_INTERVAL = 500;
const int GPIO_PORT_NO = 0;
const int MAX_GPIO_COUNT = 8;
const int TIMEOUT_MOTOR_ENABLED = 3000;
const int TIMEOUT_MOTOR_DISABLE = 3000;
static int g_nTotalAxes, g_nTotalBuffer;
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
private slots:
void on_pushButtonConnect_clicked();
void on_pushButtonDisconnect_clicked();
void on_pushButtonEnable_clicked();
void on_pushButtonDisable_clicked();
void on_pushButtonDisableAll_clicked();
void on_pushButtonBuffStart_clicked();
void on_pushButtonBuffStop_clicked();
void on_pushButtonSetZeroAPOS_clicked();
void on_pushButtonStop_clicked();
void on_pushButtonStopAll_clicked();
void on_pushButtonMoveToPosition_clicked();
void on_pushButtonMoveDec_clicked();
void on_pushButtonMoveInc_clicked();
void on_pushButtonNegtive_clicked();
void on_pushButtonPositive_clicked();
void on_pushButtonMotinEnd_clicked();
void on_pushButtonProgramEnd_clicked();
void on_pushButtonInput_clicked();
void on_pushButtonSend_clicked();
void slotClickedBtnGroup();
public slots:
void timerOut();
private:
Ui::Widget *ui;
int m_nConnectType;
HANDLE m_hAcsComm; // ACS Communication handle
BOOL m_bConnected;
int m_nSelectedAxisNo;
double m_RPosition[MAX_AXIS_COUNT]; // Reference Position
double m_FPosition[MAX_AXIS_COUNT]; // Feedback Position
double m_FVelocity[MAX_AXIS_COUNT]; // Feedback Velocity
double m_PositionErr[MAX_AXIS_COUNT]; // Position Error
int m_MotorStatus[MAX_AXIS_COUNT]; // Motor Status
int m_MotorError[MAX_AXIS_COUNT]; // Motor Error
int m_nTimerID;
QTimer* m_Timer;
void initImageLabel();
void initRadioButton();
void terminatePrevConnect();
void updateParameters(int nAxisIndex);
};
#endif // WIDGET_H
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
,m_nSelectedAxisNo(0)
{
ui->setupUi(this);
initImageLabel();
initRadioButton();
m_Timer = new QTimer(this);
m_Timer->start(UPDATE_TIMER_INTERVAL);
connect(m_Timer,&QTimer::timeout, this, &Widget::timerOut);
}
Widget::~Widget()
{
delete ui;
}
void Widget::initRadioButton()
{
ui->buttonGroup->addButton(ui->radioButtonSimulator,0);
ui->buttonGroup->addButton(ui->radioButtonTcpIp ,1);
connect(ui->radioButtonSimulator, SIGNAL(clicked()), this,SLOT(slotClickedBtnGroup()));
connect(ui->radioButtonTcpIp, SIGNAL(clicked()), this,SLOT(slotClickedBtnGroup()));
}
void Widget::initImageLabel()
{
QString filename(":/images/Images/Off.bmp");
QImage* img=new QImage;
img->load(filename);
ui->lbl_sys_left0->setPixmap(QPixmap::fromImage(*img));
ui->lbl_sys_left1->setPixmap(QPixmap::fromImage(*img));
ui->lbl_sys_left2->setPixmap(QPixmap::fromImage(*img));
ui->lbl_sys_left3->setPixmap(QPixmap::fromImage(*img));
ui->lbl_sys_left4->setPixmap(QPixmap::fromImage(*img));
ui->lbl_sys_left5->setPixmap(QPixmap::fromImage(*img));
ui->lbl_sys_left6->setPixmap(QPixmap::fromImage(*img));
ui->lbl_sys_left7->setPixmap(QPixmap::fromImage(*img));
ui->lbl_sys_right0->setPixmap(QPixmap::fromImage(*img));
ui->lbl_sys_right1->setPixmap(QPixmap::fromImage(*img));
ui->lbl_sys_right2->setPixmap(QPixmap::fromImage(*img));
ui->lbl_sys_right3->setPixmap(QPixmap::fromImage(*img));
ui->lbl_sys_right4->setPixmap(QPixmap::fromImage(*img));
ui->lbl_sys_right5->setPixmap(QPixmap::fromImage(*img));
ui->lbl_sys_right6->setPixmap(QPixmap::fromImage(*img));
ui->lbl_sys_right7->setPixmap(QPixmap::fromImage(*img));
ui->lbl_sys_emergency->setPixmap(QPixmap::fromImage(*img));
ui->lbl_gen_input0->setPixmap(QPixmap::fromImage(*img));
ui->lbl_gen_input1->setPixmap(QPixmap::fromImage(*img));
ui->lbl_gen_input2->setPixmap(QPixmap::fromImage(*img));
ui->lbl_gen_input3->setPixmap(QPixmap::fromImage(*img));
ui->lbl_gen_input4->setPixmap(QPixmap::fromImage(*img));
ui->lbl_gen_input5->setPixmap(QPixmap::fromImage(*img));
ui->lbl_gen_input6->setPixmap(QPixmap::fromImage(*img));
ui->lbl_gen_input7->setPixmap(QPixmap::fromImage(*img));
ui->lbl_gen_output0->setPixmap(QPixmap::fromImage(*img));
ui->lbl_gen_output1->setPixmap(QPixmap::fromImage(*img));
ui->lbl_gen_output2->setPixmap(QPixmap::fromImage(*img));
ui->lbl_gen_output3->setPixmap(QPixmap::fromImage(*img));
ui->lbl_gen_output4->setPixmap(QPixmap::fromImage(*img));
ui->lbl_gen_output5->setPixmap(QPixmap::fromImage(*img));
ui->lbl_gen_output6->setPixmap(QPixmap::fromImage(*img));
ui->lbl_gen_output7->setPixmap(QPixmap::fromImage(*img));
ui->lbl_motorStatus_moving->setPixmap(QPixmap::fromImage(*img));
ui->lbl_motorStatus_acceleration->setPixmap(QPixmap::fromImage(*img));
ui->lbl_motorStatus_inPosition->setPixmap(QPixmap::fromImage(*img));
ui->lbl_motorStatus_enabled->setPixmap(QPixmap::fromImage(*img));
delete img;
}
void Widget::on_pushButtonConnect_clicked()
{
double SysInfo = 0.0;
terminatePrevConnect();
switch(m_nConnectType)
{
// Simulation Mode
case 0:
m_hAcsComm = acsc_OpenCommSimulator();
break;
// Ethernet
case 1:
// Connect to the controller via TCP socket
int port = ui->lineEditPort->text().toInt() == 0 ? ACSC_SOCKET_STREAM_PORT:ui->lineEditPort->text().toInt();
m_hAcsComm = acsc_OpenCommEthernetTCP((char*)ui->lineEditIpAddr->text().toLatin1().data(), port);
// UDP Socket (ACS is supporting only 1 UDP channel)
//m_hAcsComm = acsc_OpenCommEthernetUDP((char*)LPCTSTR(m_strIPAddress), ACSC_SOCKET_DGRAM_PORT);
break;
}
// After connecting, if you got an inv服务器托管网alid handle
if(m_hAcsComm == ACSC_INVALID)
{
qDebug() comboBoxAxis->addItem(QString::number(i));
}
ui->comboBoxAxis->setCurrentIndex(0);
m_nSelectedAxisNo = 0;
// Get total number of buffers
SysInfo = 0.0;
acsc_SysInfo(m_hAcsComm, 10, &SysInfo, NULL);
g_nTotalBuffer = (int)SysInfo;
for(int i=0; icomboBoxBuffer->addItem(QString::number(i));
}
ui->comboBoxBuffer->setCurrentIndex(0);
updateParameters(0);
m_Timer->start(UPDATE_TIMER_INTERVAL);
}
void Widget::updateParameters(int nAxisIndex)
{
double Vel, Acc, Dec, Jerk, KDec; // , FPos, RPos, FVel, PE;
//==================================================================================
// Velocity
//==================================================================================
if(acsc_GetVelocity(m_hAcsComm, nAxisIndex, &Vel, NULL))
{
QString strVelocity = QString::number(Vel,'f',4);
ui->lineEditVeloccity->setText(strVelocity);
}
else
{
qDebug() lineEditAcceleration->setText(strAcc);
}
else
{
qDebug() lineEditDeceleration->setText(strDec);
}
else
{
qDebug() lineEditKillDeceleration->setText(strKillDec);
}
else
{
qDebug() lineEditJerk->setText(strJerk);
}
else
{
qDebug() buttonGroup->checkedId())
{
case 0:
m_nConnectType = 0;
qDebug() lineEditRPOS->setText(strTemp);
strTemp = QString::number(m_FPosition[m_nSelectedAxisNo] , 'f' ,4);
ui->lineEditApos->setText(strTemp);
strTemp = QString::number(m_FVelocity[m_nSelectedAxisNo] , 'f' ,4);
ui->lineEditAVelocity->setText(strTemp);
strTemp = QString::number(m_PositionErr[m_nSelectedAxisNo] , 'f' ,4);
ui->lineEditPositionError->setText(strTemp);
// //==================================================================================
// // Update dialog : Motor Status
// //==================================================================================
// if(m_MotorStatus[m_nSelectedAxisNo] & ACSC_MST_ENABLE) m_picEnable.SetBitmap(BITMAP_ON);
// else m_picEnable.SetBitmap(BITMAP_OFF);
// if(m_MotorStatus[m_nSelectedAxisNo] & ACSC_MST_MOVE) m_picMove.SetBitmap(BITMAP_ON);
// else m_picMove.SetBitmap(BITMAP_OFF);
// if(m_MotorStatus[m_nSelectedAxisNo] & ACSC_MST_ACC) m_picAcc.SetBitmap(BITMAP_ON);
// else m_picAcc.SetBitmap(BITMAP_OFF);
// if(m_MotorStatus[m_nSelectedAxisNo] & ACSC_MST_INPOS) m_picInpos.SetBitmap(BITMAP_ON);
// else m_picInpos.SetBitmap(BITMAP_OFF);
// //==================================================================================
// // Read General Input 8 bits, Output 8 bits at once (ACSPL Variable : IN(0), OUT(0))
// //==================================================================================
// acsc_GetInputPort(m_hAcsComm, GPIO_PORT_NO, &m_GeneralInput, NULL);
// acsc_GetOutputPort(m_hAcsComm, GPIO_PORT_NO, &m_GeneralOutput, NULL);
// UpdateGeneralIO();
// //==================================================================================
// // Left, Right Limit state
// // - ACSPL Variable : FAULT(MAX_AXIS_COUNT)
// // - acsc_GetFault : this function is reading fault informaton one by one
// // - if you are using acsc_ReadInteger function, you can read all informations at once
// //==================================================================================
// for(int iAxis = 0; iAxis stop();
if(m_hAcsComm != ACSC_INVALID)
{
if(acsc_CloseComm(m_hAcsComm))
{
m_hAcsComm = ACSC_INVALID;
m_bConnected = FALSE;
qDebug() 0)
{
if (acsc_GetErrorString(m_hAcsComm, Error, ErrorStr, 255, &Received))
{
ErrorStr[Received] = '';
sprintf_s(MsgsStr, "Error = % d ,%s", Error, ErrorStr);
qDebug() lineEditPosOrDistance->text().toDouble();
if(!acsc_ToPoint(m_hAcsComm, 0, m_nSelectedAxisNo, distance, NULL))
{
qDebug() lineEditPosOrDistance->text().toDouble();
// Move relative position (from current position)
if(!acsc_ToPoint(m_hAcsComm, ACSC_AMF_RELATIVE, m_nSelectedAxisNo, distance * (-1), NULL))
{
qDebug() lineEditPosOrDistance->text().toDouble();
// Move relative position (from current position)
if(!acsc_ToPoint(m_hAcsComm, ACSC_AMF_RELATIVE, m_nSelectedAxisNo, distance, NULL))
{
qDebug()
- 运行结果
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
由于我一直对搜索情有独钟,因此,如果能写记忆化搜索的绝不会写 for 循环 DP。 文章部分内容来自 (texttt{OI-Wiki}) 引入 记忆化搜索是一种通过记录已经遍历过的状态的信息,从而避免对同一状态重复遍历的搜索实现方式。 因为记忆化搜索确保了每个…