75 lines
2.0 KiB
C++
75 lines
2.0 KiB
C++
#include "rotationstage.h"
|
|
|
|
RotationStage::RotationStage(QObject *parent)
|
|
: QObject{parent}
|
|
{
|
|
m_ConnectNum = 8;
|
|
m_strIPAdress = "192.168.5.11";
|
|
short num = dmc_board_init_eth(m_ConnectNum,m_strIPAdress);
|
|
qDebug()<<"dmc_board_init_eth返回值="<<num;
|
|
if(num != 0)
|
|
{
|
|
QMessageBox::question(NULL,"错误","初始化卡失败!",QMessageBox::Yes | QMessageBox::No,QMessageBox::Yes);
|
|
}
|
|
else
|
|
{
|
|
QMessageBox::question(NULL,"正确","初始化卡成功!",QMessageBox::Yes | QMessageBox::No,QMessageBox::Yes);
|
|
}
|
|
|
|
ushort CardNum;
|
|
DWORD CardTypeList[8];
|
|
ushort CardIdList[8];
|
|
rtn = dmc_get_CardInfList(&CardNum,CardTypeList,CardIdList);
|
|
if(rtn != 0)
|
|
{
|
|
QMessageBox::question(NULL,"错误","获取卡信息失败!",QMessageBox::Yes | QMessageBox::No,QMessageBox::Yes);
|
|
}
|
|
else
|
|
{
|
|
QMessageBox::question(NULL,"正确","获取卡信息成功!",QMessageBox::Yes | QMessageBox::No,QMessageBox::Yes);
|
|
CardNo = CardIdList[0];
|
|
}
|
|
state = false;
|
|
}
|
|
|
|
void RotationStage::open()
|
|
{
|
|
state = true;
|
|
|
|
task = new std::thread(&RotationStage::aquireData,this);
|
|
}
|
|
|
|
void RotationStage::aquireData()
|
|
{
|
|
double factor = 67108864/360;
|
|
while(state){
|
|
QVector<double> rData;
|
|
double rDataAxisZ = 0;
|
|
double rDataAxisU = 0;
|
|
dmc_get_position_unit(CardNo,2,&rDataAxisZ);
|
|
dmc_get_position_unit(CardNo,3,&rDataAxisU);
|
|
rData.append(rDataAxisZ/factor);
|
|
rData.append(rDataAxisU/factor);
|
|
// qDebug()<<rDataAxisZ;
|
|
// qDebug()<<rDataAxisU;
|
|
emit sendRotateData(rData);
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
|
}
|
|
}
|
|
|
|
void RotationStage::move(int mode, int axis, int dis) //mode:0, axis:2(z),3(u),dis
|
|
{
|
|
dmc_pmove_unit(CardNo,axis,dis,mode);//定长运动
|
|
}
|
|
|
|
void RotationStage::stop()
|
|
{
|
|
dmc_emg_stop(CardNo);
|
|
}
|
|
|
|
void RotationStage::close()
|
|
{
|
|
state=false;
|
|
task->join();
|
|
}
|