#include "lhywidget.h" #include "ui_lhywidget.h" #include<vector> #include<QFileDialog> #include<QDebug> #include <QTimer> #include<sstream> #include<fstream> //构造 lhyWidget::lhyWidget(QWidget *parent) : QWidget(parent) , ui(new Ui::lhyWidget) { ui->setupUi(this); //ADS初始化 nPort = AdsPortOpen(); //打开ADS通讯端口 AdsGetLocalAddress(pAddr); //自动获取本地地址 pAddr->port = 851; //TC3的通讯端口为851 //计时器 fTimer=new QTimer; fTimer->stop(); fTimer->setInterval (200) ;//设置定时周期,单位:毫秒 connect(fTimer,SIGNAL(timeout()),this,SLOT(on_ftimerTimeout())); fTimer->start () ; //override int override = 5; AdsSyncWriteReq(pAddr, 0x4020, 32, 4, &override);//设置初始override //从plc中读取数据类 readPlcData = new ReadPlcData(pAddr); //运动学 Kin = new kinematics(200); ///scalepara ///config ui->lineEdit_a->setText(Kin->iniFile->value("/RadiusOfSP&MP/a").toString()); ui->lineEdit_b->setText(Kin->iniFile->value("/RadiusOfSP&MP/b").toString()); ui->lineEdit_Xmax->setText(Kin->iniFile->value("/LimitOfXY/Xmax").toString()); ui->lineEdit_Xmin->setText(Kin->iniFile->value("/LimitOfXY/Xmin").toString()); ui->lineEdit_Ymax->setText(Kin->iniFile->value("/LimitOfXY/Ymax").toString()); ui->lineEdit_Ymin->setText(Kin->iniFile->value("/LimitOfXY/Ymin").toString()); ui->lineEdit_ToolType->setText(Kin->iniFile->value("/Tool/Type").toString()); ui->lineEdit_ToolLength->setText(Kin->iniFile->value("/Tool/Length").toString()); ui->lineEdit_le_Length->setText(Kin->iniFile->value("/Tool/le_Length").toString()); ui->lineEdit_R1_min->setText(Kin->iniFile->value("/PassiveJoint/R1_min").toString()); ui->lineEdit_R1_max->setText(Kin->iniFile->value("/PassiveJoint/R1_max").toString()); ui->lineEdit_R2_min->setText(Kin->iniFile->value("/PassiveJoint/R2_min").toString()); ui->lineEdit_R2_max->setText(Kin->iniFile->value("/PassiveJoint/R2_max").toString()); ui->lineEdit_R3_min->setText(Kin->iniFile->value("/PassiveJoint/R3_min").toString()); ui->lineEdit_R3_max->setText(Kin->iniFile->value("/PassiveJoint/R3_max").toString()); ui->lineEdit_R4_min->setText(Kin->iniFile->value("/PassiveJoint/R4_min").toString()); ui->lineEdit_R4_max->setText(Kin->iniFile->value("/PassiveJoint/R4_max").toString()); ui->lineEdit_U1_min->setText(Kin->iniFile->value("/PassiveJoint/U1_min").toString()); ui->lineEdit_U1_max->setText(Kin->iniFile->value("/PassiveJoint/U1_max").toString()); ui->lineEdit_U2_min->setText(Kin->iniFile->value("/PassiveJoint/U2_min").toString()); ui->lineEdit_U2_max->setText(Kin->iniFile->value("/PassiveJoint/U2_max").toString()); ui->lineEdit_S3_min->setText(Kin->iniFile->value("/PassiveJoint/S3_min").toString()); ui->lineEdit_S3_max->setText(Kin->iniFile->value("/PassiveJoint/S3_max").toString()); ui->lineEdit_S4_min->setText(Kin->iniFile->value("/PassiveJoint/S4_min").toString()); ui->lineEdit_S4_max->setText(Kin->iniFile->value("/PassiveJoint/S4_max").toString()); ui->lineEdit_U12_min->setText(Kin->iniFile->value("/PassiveJoint/U12_min").toString()); ui->lineEdit_U12_max->setText(Kin->iniFile->value("/PassiveJoint/U12_max").toString()); ui->lineEdit_U22_min->setText(Kin->iniFile->value("/PassiveJoint/U22_min").toString()); ui->lineEdit_U22_max->setText(Kin->iniFile->value("/PassiveJoint/U22_max").toString()); ui->lineEdit_S32_min->setText(Kin->iniFile->value("/PassiveJoint/S32_min").toString()); ui->lineEdit_S32_max->setText(Kin->iniFile->value("/PassiveJoint/S32_max").toString()); ui->lineEdit_S42_min->setText(Kin->iniFile->value("/PassiveJoint/S42_min").toString()); ui->lineEdit_S42_max->setText(Kin->iniFile->value("/PassiveJoint/S42_max").toString()); ui->lineEdit_d1_min->setText(Kin->iniFile->value("/ActiveJoint/d1_min").toString()); ui->lineEdit_d1_max->setText(Kin->iniFile->value("/ActiveJoint/d1_max").toString()); ui->lineEdit_d2_min->setText(Kin->iniFile->value("/ActiveJoint/d2_min").toString()); ui->lineEdit_d2_max->setText(Kin->iniFile->value("/ActiveJoint/d2_max").toString()); ui->lineEdit_d3_min->setText(Kin->iniFile->value("/ActiveJoint/d3_min").toString()); ui->lineEdit_d3_max->setText(Kin->iniFile->value("/ActiveJoint/d3_max").toString()); ui->lineEdit_d4_min->setText(Kin->iniFile->value("/ActiveJoint/d4_min").toString()); ui->lineEdit_d4_max->setText(Kin->iniFile->value("/ActiveJoint/d4_max").toString()); //运动学仿真 Pkm = new pkm3d(ui->coin3dWidget); ///初始化pkm3d Pkm->Leg1_Rot->angle = -(Kin->R1_-1.570796); Pkm->U1_Rot->angle = Kin->U12_-1.570796; Pkm->Leg2_Rot->angle = -(Kin->R2_-1.570796); Pkm->U2_Rot->angle = Kin->U22_-1.570796; Pkm->R3_Rot->angle = Kin->R3_-1.570796; Pkm->S32_Rot->angle = Kin->S3_-1.570796; Pkm->S3_Rot->angle = Kin->S32_-1.570796; Pkm->R4_Rot->angle = Kin->R4_-1.570796; Pkm->S42_Rot->angle = -(Kin->S4_-1.570796); Pkm->S4_Rot->angle = (Kin->S42_-1.570796); Pkm->U12_form->translation.setValue(0,Kin->d1/1000.0,0); Pkm->U22_form->translation.setValue(0,Kin->d2/1000.0,0); Pkm->Leg3_form->translation.setValue(0,-Kin->d3/1000.0,0); Pkm->Leg4_form->translation.setValue(0,-Kin->d4/1000.0,0); Pkm->Mplane_form->translation.setValue(0,-Kin->ZO_/1000.0, Kin->XO_/1000.0 ); //Pkm->Mplane_Rotp->angle = Kin->PSI; //Pkm->Mplane_Rott->angle = -Kin->THETA; Pkm->Mplane_Rotp->rotation.setValue(SbVec3f(0,0,1),Kin->PSI); Pkm->Mplane_Rott->rotation.setValue(SbVec3f(cos(Kin->PSI),-sin(Kin->PSI),0),-Kin->THETA); ////XY绘图 ui->qwtPlot->setTitle("TrajectorySimulation"); ui->qwtPlot->setAxisScale(0,-100,100);//y轴尺度 ui->qwtPlot->setAxisScale(2,-100,100);//x轴尺度 ui->qwtPlot->setAxisTitle(0,"Y/(mm)"); ui->qwtPlot->setAxisTitle(2,"X/(mm)"); //实例化曲线 curve = new QwtPlotCurve("Acc_X"); curve->setPen(Qt::blue,2);//设置曲线颜色 粗细 curve->setRenderHint(QwtPlotItem::RenderAntialiased,true);//线条光滑化 //加到plot,plot由IDE创建 curve->attach(ui->qwtPlot); //----------------设置栅格线-------------------// QwtPlotGrid *grid = new QwtPlotGrid; grid->enableX( true );//设置网格线 grid->enableY( true ); grid->setMajorPen( Qt::black, 0, Qt::DotLine ); grid->attach( ui->qwtPlot ); //析构 lhyWidget::~lhyWidget() { delete ui; delete readPlcData; AdsPortClose(); //关闭ADS通讯端口 } //使能 void lhyWidget::on_clickPOWER_clicked() { bool rtBool; AdsSyncReadReq(pAddr, 0x4020, 192, 0x1, &rtBool); if(rtBool) ui->clickPOWER->setStyleSheet(""); else ui->clickPOWER->setStyleSheet("background-color: green;"); rtBool=!rtBool; AdsSyncWriteReq(pAddr, 0x4020, 192, 0x1, &rtBool); } //重置 void lhyWidget::on_clickRESET_pressed() { bool rtBool=1; AdsSyncWriteReq(pAddr, 0x4020, 196, 0x1, &rtBool); //ui->clickRESET->setStyleSheet("background-color: green;"); } void lhyWidget::on_clickRESET_released() { bool rtBool=0; AdsSyncWriteReq(pAddr, 0x4020, 196, 0x1, &rtBool); //ui->clickRESET->setStyleSheet(""); } //回零 void lhyWidget::on_clickGOZERO_clicked() { pointAfter[0].clear();pointAfter[1].clear();pointAfter[2].clear();pointAfter[3].clear();pointAfter[4].clear();pointAfter[5].clear(); pointBefore[0].clear();pointBefore[1].clear();pointBefore[2].clear();pointBefore[3].clear();pointBefore[4].clear();pointBefore[5].clear(); ui->tableDisplayCAMPoint->clear(); ui->tableDisplayITPPoint->clear(); Kin->InverseZ0_ = Kin->ZO_; double tem = Kin->InverseZ0_; //z for (double i = 400.0;i>=0;i--) { Kin->InverseZ0_ = (tem-200.0)*i/400.0+200.0; Kin->Inverse0(Kin->PSI,Kin->THETA); pointAfter[0].push_back(Kin->q[0]);//d1 pointAfter[1].push_back(Kin->q[1]);//d2 pointAfter[2].push_back(Kin->q[2]);//d3 pointAfter[3].push_back(Kin->q[3]);//d4 ui->tableDisplayITPPoint->setRowCount(ui->tableDisplayITPPoint->rowCount() + 1);//总行数增加1 ui->tableDisplayITPPoint->setItem(400-i,0,new QTableWidgetItem(QString::number(Kin->q[0]))); ui->tableDisplayITPPoint->setItem(400-i,1,new QTableWidgetItem(QString::number(Kin->q[1]))); ui->tableDisplayITPPoint->setItem(400-i,2,new QTableWidgetItem(QString::number(Kin->q[2]))); ui->tableDisplayITPPoint->setItem(400-i,3,new QTableWidgetItem(QString::number(Kin->q[3]))); } //psi for (double i = 400.0;i>=0;i--) { Kin->Inverse0(Kin->PSI*i/400.0,Kin->THETA); pointAfter[0].push_back(Kin->q[0]);//d1 pointAfter[1].push_back(Kin->q[1]);//d2 pointAfter[2].push_back(Kin->q[2]);//d3 pointAfter[3].push_back(Kin->q[3]);//d4 ui->tableDisplayITPPoint->setRowCount(ui->tableDisplayITPPoint->rowCount() + 1);//总行数增加1 ui->tableDisplayITPPoint->setItem(801-i,0,new QTableWidgetItem(QString::number(Kin->q[0]))); ui->tableDisplayITPPoint->setItem(801-i,1,new QTableWidgetItem(QString::number(Kin->q[1]))); ui->tableDisplayITPPoint->setItem(801-i,2,new QTableWidgetItem(QString::number(Kin->q[2]))); ui->tableDisplayITPPoint->setItem(801-i,3,new QTableWidgetItem(QString::number(Kin->q[3]))); } //theta for (double i = 400.0;i>=0;i--) { Kin->Inverse0(0,Kin->THETA*i/400.0); pointAfter[0].push_back(Kin->q[0]);//d1 pointAfter[1].push_back(Kin->q[1]);//d2 pointAfter[2].push_back(Kin->q[2]);//d3 pointAfter[3].push_back(Kin->q[3]);//d4 ui->tableDisplayITPPoint->setRowCount(ui->tableDisplayITPPoint->rowCount() + 1);//总行数增加1 ui->tableDisplayITPPoint->setItem(1202-i,0,new QTableWidgetItem(QString::number(Kin->q[0]))); ui->tableDisplayITPPoint->setItem(1202-i,1,new QTableWidgetItem(QString::number(Kin->q[1]))); ui->tableDisplayITPPoint->setItem(1202-i,2,new QTableWidgetItem(QString::number(Kin->q[2]))); ui->tableDisplayITPPoint->setItem(1202-i,3,new QTableWidgetItem(QString::number(Kin->q[3]))); } int a=1203; AdsSyncWriteReq(pAddr, 0x4020, 36, 4, &a);//传入plcFeedpoint数目 do{//MAIN.pArrayLreal1 unsigned long lHdlVar2; //创建句柄 double* array = pointAfter[0].data(); //定义数组 // for(int i = 0;i<10;i++) // { // qDebug()<<"pointBefore[0]["<<i<<"] = "<<array[i]; // } char szVar3[]={"MAIN.pArrayLreal1"}; //得到Array1的句柄 AdsSyncReadWriteReq(pAddr, ADSIGRP_SYM_HNDBYNAME, 0x0, sizeof(lHdlVar2), &lHdlVar2, sizeof(szVar3), szVar3); //通过句柄向PLC写入数组 AdsSyncWriteReq(pAddr, ADSIGRP_SYM_VALBYHND, lHdlVar2, pointAfter[0].size()*8, &array[0]); }while(0); do{//MAIN.pArrayLreal2 unsigned long lHdlVar2; //创建句柄 double* array = pointAfter[1].data(); //定义数组 // for(int i = 0;i<10;i++) // { // qDebug()<<"pointBefore[1]["<<i<<"] = "<<array[i]; // } char szVar3[]={"MAIN.pArrayLreal2"}; //得到Array1的句柄 AdsSyncReadWriteReq(pAddr, ADSIGRP_SYM_HNDBYNAME, 0x0, sizeof(lHdlVar2), &lHdlVar2, sizeof(szVar3), szVar3); //通过句柄向PLC写入数组 AdsSyncWriteReq(pAddr, ADSIGRP_SYM_VALBYHND, lHdlVar2, pointAfter[1].size()*8, &array[0]); }while(0); do{//MAIN.pArrayLreal3 unsigned long lHdlVar2; //创建句柄 double* array = pointAfter[2].data(); //定义数组 // for(int i = 0;i<10;i++) // { // qDebug()<<"pointBefore[3]["<<i<<"] = "<<array[i]; // } char szVar3[]={"MAIN.pArrayLreal3"}; //得到Array1的句柄 AdsSyncReadWriteReq(pAddr, ADSIGRP_SYM_HNDBYNAME, 0x0, sizeof(lHdlVar2), &lHdlVar2, sizeof(szVar3), szVar3); //通过句柄向PLC写入数组 AdsSyncWriteReq(pAddr, ADSIGRP_SYM_VALBYHND, lHdlVar2, pointAfter[2].size()*8, &array[0]); }while(0); do{//MAIN.pArrayLreal4 unsigned long lHdlVar2; //创建句柄 double* array = pointAfter[3].data(); //定义数组 char szVar3[]={"MAIN.pArrayLreal4"}; //得到Array1的句柄 AdsSyncReadWriteReq(pAddr, ADSIGRP_SYM_HNDBYNAME, 0x0, sizeof(lHdlVar2), &lHdlVar2, sizeof(szVar3), szVar3); //通过句柄向PLC写入数组 AdsSyncWriteReq(pAddr, ADSIGRP_SYM_VALBYHND, lHdlVar2, pointAfter[3].size()*8, &array[0]); }while(0); //interpolationEnable bool rtBool=1; AdsSyncWriteReq(pAddr, 0x4020, 200, 0x1, &rtBool); Sleep(1000); rtBool=0; AdsSyncWriteReq(pAddr, 0x4020, 200, 0x1, &rtBool); //allPointOver AdsSyncWriteReq(pAddr, 0x4020, 240, 0x1, &rtBool);//allPointOver=false } //Z+ void lhyWidget::on_clickZF_pressed() { bool rtBool=1; AdsSyncWriteReq(pAddr, 0x4020, 204, 0x1, &rtBool); //ui->clickZF->setStyleSheet("background-color: green;"); } void lhyWidget::on_clickZF_released() { bool rtBool=0; AdsSyncWriteReq(pAddr, 0x4020, 204, 0x1, &rtBool); //ui->clickZF->setStyleSheet(""); } //Z- void lhyWidget::on_clickZB_pressed() { bool rtBool=1; AdsSyncWriteReq(pAddr, 0x4020, 208, 0x1, &rtBool); //ui->clickZB->setStyleSheet("background-color: green;"); } void lhyWidget::on_clickZB_released() { bool rtBool=0; AdsSyncWriteReq(pAddr, 0x4020, 208, 0x1, &rtBool); //ui->clickZB->setStyleSheet(""); } //X+ void lhyWidget::on_clickXF_pressed() { bool rtBool=1; AdsSyncWriteReq(pAddr, 0x4020, 212, 0x1, &rtBool); //ui->clickXF->setStyleSheet("background-color: green;"); } void lhyWidget::on_clickXF_released() { bool rtBool=0; AdsSyncWriteReq(pAddr, 0x4020, 212, 0x1, &rtBool); //ui->clickXF->setStyleSheet(""); } //X- void lhyWidget::on_clickXB_pressed() { bool rtBool=1; AdsSyncWriteReq(pAddr, 0x4020, 216, 0x1, &rtBool); //ui->clickXB->setStyleSheet("background-color: green;"); } void lhyWidget::on_clickXB_released() { bool rtBool=0; AdsSyncWriteReq(pAddr, 0x4020, 216, 0x1, &rtBool); //ui->clickXB->setStyleSheet(""); } //Y+ void lhyWidget::on_clickYF_pressed() { bool rtBool=1; AdsSyncWriteReq(pAddr, 0x4020, 220, 0x1, &rtBool); //ui->clickYF->setStyleSheet("background-color: green;"); } void lhyWidget::on_clickYF_released() { bool rtBool=0; AdsSyncWriteReq(pAddr, 0x4020, 220, 0x1, &rtBool); //ui->clickYF->setStyleSheet(""); } //Y- void lhyWidget::on_clickYB_pressed() { bool rtBool=1; AdsSyncWriteReq(pAddr, 0x4020, 224, 0x1, &rtBool); //ui->clickYB->setStyleSheet("background-color: green;"); } void lhyWidget::on_clickYB_released() { bool rtBool=0; AdsSyncWriteReq(pAddr, 0x4020, 224, 0x1, &rtBool); //ui->clickYB->setStyleSheet(""); } //SETOVERRIDE void lhyWidget::on_setOverride_valueChanged(int value) { AdsSyncWriteReq(pAddr, 0x4020, 32, 4, &value); //qDebug()<<value; } //导入点txt((导入txt到pointBefore并告诉plc pointBefore.size() )) void lhyWidget::on_clickFile_clicked() { pointAfter[0].clear();pointAfter[1].clear();pointAfter[2].clear();pointAfter[3].clear();pointAfter[4].clear();pointAfter[5].clear(); pointBefore[0].clear();pointBefore[1].clear();pointBefore[2].clear();pointBefore[3].clear();pointBefore[4].clear();pointBefore[5].clear(); file_name = QFileDialog::getOpenFileName(nullptr,"标题",".","*.txt"); //qDebug() << "点位文件路径" << file_name; if(!file_name.isEmpty()) { ui->tableDisplayCAMPoint->clear(); ui->tableDisplayITPPoint->clear(); QByteArray file_name_ = file_name.toLatin1(); std::ifstream is(file_name_.data()); //QString printTem;(txtBrower) int i;//plc中pArrayLreal要new的长度 for (i = 0; !is.eof(); i++) { std::string tem; getline(is, tem); std::istringstream aa(tem); double t; ui->tableDisplayCAMPoint->setRowCount(ui->tableDisplayCAMPoint->rowCount() + 1);//总行数增加1 ui->tableDisplayITPPoint->setRowCount(ui->tableDisplayITPPoint->rowCount() + 1);//总行数增加1 for (int j = 0; j < 6; j++) { aa >> t; pointBefore[j].push_back(t); //printTem.append(QString::number(t));(txtBrower) if(j!=5) ui->tableDisplayCAMPoint->setItem(i,j,new QTableWidgetItem(QString::number(t))); } //printTem.append('\n');(txtBrower) for (int j = 0; j < 6; j++) { Kin->Inverse(pointBefore[0][i],pointBefore[1][i],pointBefore[2][i],pointBefore[3][i],pointBefore[4][i]); pointAfter[j].push_back(Kin->q[j]);//d1 // pointAfter[1].push_back(Kin->q[1]);//d2 // pointAfter[2].push_back(Kin->q[2]);//d3 // pointAfter[3].push_back(Kin->q[3]);//d4 // pointAfter[4].push_back(Kin->q[4]);//x // pointAfter[5].push_back(Kin->q[5]);//y ui->tableDisplayITPPoint->setItem(i,j,new QTableWidgetItem(QString::number(Kin->q[j]))); } } //ui->txtDisplay->setText(printTem);(txtBrower) Length = i; AdsSyncWriteReq(pAddr, 0x4020, 36, 4, &i);//传入plcFeedpoint数目 qDebug()<< "length" <<i; } ////pointAfter传入plc..........。。。。。。。。。。。。。。。。。。 do{//MAIN.pArrayLreal1 unsigned long lHdlVar2; //创建句柄 double* array = pointAfter[0].data(); //定义数组 // for(int i = 0;i<10;i++) // { // qDebug()<<"pointBefore[0]["<<i<<"] = "<<array[i]; // } char szVar3[]={"MAIN.pArrayLreal1"}; //得到Array1的句柄 AdsSyncReadWriteReq(pAddr, ADSIGRP_SYM_HNDBYNAME, 0x0, sizeof(lHdlVar2), &lHdlVar2, sizeof(szVar3), szVar3); //通过句柄向PLC写入数组 AdsSyncWriteReq(pAddr, ADSIGRP_SYM_VALBYHND, lHdlVar2, pointAfter[0].size()*8, &array[0]); }while(0); do{//MAIN.pArrayLreal2 unsigned long lHdlVar2; //创建句柄 double* array = pointAfter[1].data(); //定义数组 // for(int i = 0;i<10;i++) // { // qDebug()<<"pointBefore[1]["<<i<<"] = "<<array[i]; // } char szVar3[]={"MAIN.pArrayLreal2"}; //得到Array1的句柄 AdsSyncReadWriteReq(pAddr, ADSIGRP_SYM_HNDBYNAME, 0x0, sizeof(lHdlVar2), &lHdlVar2, sizeof(szVar3), szVar3); //通过句柄向PLC写入数组 AdsSyncWriteReq(pAddr, ADSIGRP_SYM_VALBYHND, lHdlVar2, pointAfter[1].size()*8, &array[0]); }while(0); do{//MAIN.pArrayLreal3 unsigned long lHdlVar2; //创建句柄 double* array = pointAfter[2].data(); //定义数组 // for(int i = 0;i<10;i++) // { // qDebug()<<"pointBefore[3]["<<i<<"] = "<<array[i]; // } char szVar3[]={"MAIN.pArrayLreal3"}; //得到Array1的句柄 AdsSyncReadWriteReq(pAddr, ADSIGRP_SYM_HNDBYNAME, 0x0, sizeof(lHdlVar2), &lHdlVar2, sizeof(szVar3), szVar3); //通过句柄向PLC写入数组 AdsSyncWriteReq(pAddr, ADSIGRP_SYM_VALBYHND, lHdlVar2, pointAfter[2].size()*8, &array[0]); }while(0); do{//MAIN.pArrayLreal4 unsigned long lHdlVar2; //创建句柄 double* array = pointAfter[3].data(); //定义数组 // for(int i = 0;i<10;i++) // { // qDebug()<<"pointBefore[3]["<<i<<"] = "<<array[i]; // } char szVar3[]={"MAIN.pArrayLreal4"}; //得到Array1的句柄 AdsSyncReadWriteReq(pAddr, ADSIGRP_SYM_HNDBYNAME, 0x0, sizeof(lHdlVar2), &lHdlVar2, sizeof(szVar3), szVar3); //通过句柄向PLC写入数组 AdsSyncWriteReq(pAddr, ADSIGRP_SYM_VALBYHND, lHdlVar2, pointAfter[3].size()*8, &array[0]); }while(0); do{//MAIN.pArrayLrealX unsigned long lHdlVar2; //创建句柄 double* array = pointAfter[4].data(); //定义数组 char szVar3[]={"MAIN.pArrayLrealx"}; //得到Array1的句柄 AdsSyncReadWriteReq(pAddr, ADSIGRP_SYM_HNDBYNAME, 0x0, sizeof(lHdlVar2), &lHdlVar2, sizeof(szVar3), szVar3); //通过句柄向PLC写入数组 AdsSyncWriteReq(pAddr, ADSIGRP_SYM_VALBYHND, lHdlVar2, pointBefore[4].size()*8, &array[0]); }while(0); do{//MAIN.pArrayLrealY unsigned long lHdlVar2; //创建句柄 double* array = pointAfter[5].data(); //定义数组 char szVar3[]={"MAIN.pArrayLrealy"}; //得到Array1的句柄 AdsSyncReadWriteReq(pAddr, ADSIGRP_SYM_HNDBYNAME, 0x0, sizeof(lHdlVar2), &lHdlVar2, sizeof(szVar3), szVar3); //通过句柄向PLC写入数组 AdsSyncWriteReq(pAddr, ADSIGRP_SYM_VALBYHND, lHdlVar2, pointBefore[5].size()*8, &array[0]); }while(0); } //开始interpolation并且令allPointOver=false void lhyWidget::on_clickINTERPOLATION_clicked() { //interpolationEnable bool rtBool=1; AdsSyncWriteReq(pAddr, 0x4020, 228, 0x1, &rtBool); Sleep(1000); rtBool=0; AdsSyncWriteReq(pAddr, 0x4020, 228, 0x1, &rtBool); //allPointOver AdsSyncWriteReq(pAddr, 0x4020, 240, 0x1, &rtBool);//allPointOver=false } //HALT void lhyWidget::on_clickHALT_clicked() { bool rtBool; AdsSyncReadReq(pAddr, 0x4020, 244, 0x1, &rtBool); if(rtBool) ui->clickHALT->setStyleSheet(""); else ui->clickHALT->setStyleSheet("background-color: green;"); rtBool=!rtBool; AdsSyncWriteReq(pAddr, 0x4020, 244, 0x1, &rtBool); } //对刀点记录 void lhyWidget::on_clickZPoint_clicked() { Kin->InverseZ0_ = Kin->ZO_;//调用inverse用InverseZ0_ Kin->ZPoint = Kin->Zp;//ZPoint记录对刀点刀尖的z QString a = "ZP="; a = a+QString::number(Kin->ZPoint); ui->clickZPoint->setText(a); } void lhyWidget::on_clickXPoint_clicked() { Kin->XPoint = readPlcData->plc_Data_axisX; QString a = "XP="; a = a+QString::number(Kin->XPoint); ui->clickXPoint->setText(a); } void lhyWidget::on_clickYPoint_clicked() { Kin->YPoint = -readPlcData->plc_Data_axisY; QString a = "YP="; a = a+QString::number(Kin->YPoint); ui->clickYPoint->setText(a); } //示教psi void lhyWidget::on_teachTextEdit_A_textChanged() { teachPSI = ui->teachTextEdit_A->toPlainText().toDouble()*Kin->con; } //示教theta void lhyWidget::on_teachTextEdit_B_textChanged() { teachTHETA = ui->teachTextEdit_B->toPlainText().toDouble()*Kin->con; } //示教z void lhyWidget::on_teachTextEdit_Z_textChanged() { teachZ = ui->teachTextEdit_Z->toPlainText().toDouble(); } //示教触发 void lhyWidget::on_clickTEACH_clicked() { pointAfter[0].clear();pointAfter[1].clear();pointAfter[2].clear();pointAfter[3].clear();pointAfter[4].clear();pointAfter[5].clear(); pointBefore[0].clear();pointBefore[1].clear();pointBefore[2].clear();pointBefore[3].clear();pointBefore[4].clear();pointBefore[5].clear(); ui->tableDisplayCAMPoint->clear(); ui->tableDisplayITPPoint->clear(); Kin->InverseZ0_ = Kin->ZO_; double tem = Kin->InverseZ0_; //z for (double i = 400.0;i>=0;i--) { Kin->InverseZ0_ = (tem-teachZ)*i/400.0+teachZ; Kin->Inverse0(Kin->PSI,Kin->THETA); pointAfter[0].push_back(Kin->q[0]);//d1 pointAfter[1].push_back(Kin->q[1]);//d2 pointAfter[2].push_back(Kin->q[2]);//d3 pointAfter[3].push_back(Kin->q[3]);//d4 ui->tableDisplayITPPoint->setRowCount(ui->tableDisplayITPPoint->rowCount() + 1);//总行数增加1 ui->tableDisplayITPPoint->setItem(400-i,0,new QTableWidgetItem(QString::number(Kin->q[0]))); ui->tableDisplayITPPoint->setItem(400-i,1,new QTableWidgetItem(QString::number(Kin->q[1]))); ui->tableDisplayITPPoint->setItem(400-i,2,new QTableWidgetItem(QString::number(Kin->q[2]))); ui->tableDisplayITPPoint->setItem(400-i,3,new QTableWidgetItem(QString::number(Kin->q[3]))); } //psi for (double i = 0.0;i<=400;i++) { Kin->Inverse0((teachPSI-Kin->PSI)*i/400.0+Kin->PSI,Kin->THETA); pointAfter[0].push_back(Kin->q[0]);//d1 pointAfter[1].push_back(Kin->q[1]);//d2 pointAfter[2].push_back(Kin->q[2]);//d3 pointAfter[3].push_back(Kin->q[3]);//d4 ui->tableDisplayITPPoint->setRowCount(ui->tableDisplayITPPoint->rowCount() + 1);//总行数增加1 ui->tableDisplayITPPoint->setItem(401+i,0,new QTableWidgetItem(QString::number(Kin->q[0]))); ui->tableDisplayITPPoint->setItem(401+i,1,new QTableWidgetItem(QString::number(Kin->q[1]))); ui->tableDisplayITPPoint->setItem(401+i,2,new QTableWidgetItem(QString::number(Kin->q[2]))); ui->tableDisplayITPPoint->setItem(401+i,3,new QTableWidgetItem(QString::number(Kin->q[3]))); } //theta for (double i = 0.0;i<=400;i++) { Kin->Inverse0(teachPSI,(teachTHETA-Kin->THETA)*i/400.0+Kin->THETA); pointAfter[0].push_back(Kin->q[0]);//d1 pointAfter[1].push_back(Kin->q[1]);//d2 pointAfter[2].push_back(Kin->q[2]);//d3 pointAfter[3].push_back(Kin->q[3]);//d4 ui->tableDisplayITPPoint->setRowCount(ui->tableDisplayITPPoint->rowCount() + 1);//总行数增加1 ui->tableDisplayITPPoint->setItem(802+i,0,new QTableWidgetItem(QString::number(Kin->q[0]))); ui->tableDisplayITPPoint->setItem(802+i,1,new QTableWidgetItem(QString::number(Kin->q[1]))); ui->tableDisplayITPPoint->setItem(802+i,2,new QTableWidgetItem(QString::number(Kin->q[2]))); ui->tableDisplayITPPoint->setItem(802+i,3,new QTableWidgetItem(QString::number(Kin->q[3]))); } int a=1203; AdsSyncWriteReq(pAddr, 0x4020, 36, 4, &a);//传入plcFeedpoint数目 do{//MAIN.pArrayLreal1 unsigned long lHdlVar2; //创建句柄 double* array = pointAfter[0].data(); //定义数组 // for(int i = 0;i<10;i++) // { // qDebug()<<"pointBefore[0]["<<i<<"] = "<<array[i]; // } char szVar3[]={"MAIN.pArrayLreal1"}; //得到Array1的句柄 AdsSyncReadWriteReq(pAddr, ADSIGRP_SYM_HNDBYNAME, 0x0, sizeof(lHdlVar2), &lHdlVar2, sizeof(szVar3), szVar3); //通过句柄向PLC写入数组 AdsSyncWriteReq(pAddr, ADSIGRP_SYM_VALBYHND, lHdlVar2, pointAfter[0].size()*8, &array[0]); }while(0); do{//MAIN.pArrayLreal2 unsigned long lHdlVar2; //创建句柄 double* array = pointAfter[1].data(); //定义数组 // for(int i = 0;i<10;i++) // { // qDebug()<<"pointBefore[1]["<<i<<"] = "<<array[i]; // } char szVar3[]={"MAIN.pArrayLreal2"}; //得到Array1的句柄 AdsSyncReadWriteReq(pAddr, ADSIGRP_SYM_HNDBYNAME, 0x0, sizeof(lHdlVar2), &lHdlVar2, sizeof(szVar3), szVar3); //通过句柄向PLC写入数组 AdsSyncWriteReq(pAddr, ADSIGRP_SYM_VALBYHND, lHdlVar2, pointAfter[1].size()*8, &array[0]); }while(0); do{//MAIN.pArrayLreal3 unsigned long lHdlVar2; //创建句柄 double* array = pointAfter[2].data(); //定义数组 // for(int i = 0;i<10;i++) // { // qDebug()<<"pointBefore[3]["<<i<<"] = "<<array[i]; // } char szVar3[]={"MAIN.pArrayLreal3"}; //得到Array1的句柄 AdsSyncReadWriteReq(pAddr, ADSIGRP_SYM_HNDBYNAME, 0x0, sizeof(lHdlVar2), &lHdlVar2, sizeof(szVar3), szVar3); //通过句柄向PLC写入数组 AdsSyncWriteReq(pAddr, ADSIGRP_SYM_VALBYHND, lHdlVar2, pointAfter[2].size()*8, &array[0]); }while(0); do{//MAIN.pArrayLreal4 unsigned long lHdlVar2; //创建句柄 double* array = pointAfter[3].data(); //定义数组 char szVar3[]={"MAIN.pArrayLreal4"}; //得到Array1的句柄 AdsSyncReadWriteReq(pAddr, ADSIGRP_SYM_HNDBYNAME, 0x0, sizeof(lHdlVar2), &lHdlVar2, sizeof(szVar3), szVar3); //通过句柄向PLC写入数组 AdsSyncWriteReq(pAddr, ADSIGRP_SYM_VALBYHND, lHdlVar2, pointAfter[3].size()*8, &array[0]); }while(0); //interpolationEnable bool rtBool=1; AdsSyncWriteReq(pAddr, 0x4020, 200, 0x1, &rtBool); Sleep(1000); rtBool=0; AdsSyncWriteReq(pAddr, 0x4020, 200, 0x1, &rtBool); //allPointOver AdsSyncWriteReq(pAddr, 0x4020, 240, 0x1, &rtBool);//allPointOver=false } //定时器 void lhyWidget::on_ftimerTimeout() { //定时器中断响 //ActPos ui->textEdit_q1->setText(QString::number(readPlcData->plc_Data_axis1)); ui->textEdit_q2->setText(QString::number(readPlcData->plc_Data_axis2)); ui->textEdit_q3->setText(QString::number(readPlcData->plc_Data_axis3)); ui->textEdit_q4->setText(QString::number(readPlcData->plc_Data_axis4)); ui->textEdit_x ->setText(QString::number(readPlcData->plc_Data_axisX)); ui->textEdit_y ->setText(QString::number(readPlcData->plc_Data_axisY)); //监视interpolation完成情况 if(readPlcData->allPointOver!=0) ui->clickINTERPOLATION->setStyleSheet("background-color: green;"); else { ui->clickINTERPOLATION->setStyleSheet(""); ui->ITPProgress->reset(); } //qDebug()<<q1->plc_Data; ///更新pkm3d if(readPlcData->plc_Data_axis1!=0) { Kin->Forward(readPlcData->plc_Data_axis1,readPlcData->plc_Data_axis2,readPlcData->plc_Data_axis3,readPlcData->plc_Data_axis4); Kin->rotation(); Pkm->Leg1_Rot->angle = -(Kin->R1_-1.570796); Pkm->U1_Rot->angle = Kin->U12_-1.570796; Pkm->Leg2_Rot->angle = -(Kin->R2_-1.570796); Pkm->U2_Rot->angle = Kin->U22_-1.570796; Pkm->R3_Rot->angle = Kin->R3_-1.570796; Pkm->S32_Rot->angle = Kin->S3_-1.570796; Pkm->S3_Rot->angle = Kin->S32_-1.570796; Pkm->R4_Rot->angle = Kin->R4_-1.570796; Pkm->S42_Rot->angle = -(Kin->S4_-1.570796); Pkm->S4_Rot->angle = (Kin->S42_-1.570796); Pkm->U12_form->translation.setValue(0,Kin->d1/1000.0,0); Pkm->U22_form->translation.setValue(0,Kin->d2/1000.0,0); Pkm->Leg3_form->translation.setValue(0,-Kin->d3/1000.0,0); Pkm->Leg4_form->translation.setValue(0,-Kin->d4/1000.0,0); //动平台 Pkm->Mplane_form->translation.setValue(0,-Kin->ZO_/1000.0, Kin->XO_/1000.0 );//位置-Kin->ZO_/1000.0 //Pkm->Mplane_Rotp->angle = Kin->PSI;//Rot PSI //Pkm->Mplane_Rott->angle = -Kin->THETA;//Rot THETA Pkm->Mplane_Rotp->rotation.setValue(SbVec3f(0,0,1),Kin->PSI);//位姿psi Pkm->Mplane_Rott->rotation.setValue(SbVec3f(cos(Kin->PSI),-sin(Kin->PSI),0),-Kin->THETA);//位姿theta Pkm->Y_form->translation.setValue(0,0,readPlcData->plc_Data_axisX/1000.0);//X Pkm->Obj_form->translation.setValue(-readPlcData->plc_Data_axisY/1000.0,0,0);//Y ui->textEdit_X ->setText(QString::number(Kin->XO_)); ui->textEdit_Y ->setText(QString::number(Kin->YO_)); ui->textEdit_Z ->setText(QString::number(Kin->ZO_)); ui->textEdit_A ->setText(QString::number(Kin->PSI/Kin->con)+"°"); ui->textEdit_B ->setText(QString::number(Kin->THETA/Kin->con)+"°"); } curve->setSamples(pointAfter[4].data(),pointAfter[5].data(),readPlcData->plc_Data_pointK) ; //QwtPlot重绘,重要,没有这句不起作用 ui->qwtPlot->replot(); //进度条 ui->ITPProgress->setValue(readPlcData->plc_Data_pointK/Length*100); } ///RadiusOfSP&MP void lhyWidget::on_lineEdit_a_textChanged(const QString &arg1) { Kin->iniFile->setValue("/RadiusOfSP&MP/a", arg1.toDouble()); Kin->la = arg1.toDouble(); } void lhyWidget::on_lineEdit_b_textChanged(const QString &arg1) { Kin->iniFile->setValue("/RadiusOfSP&MP/b", arg1.toDouble()); Kin->lb = arg1.toDouble(); } ///LimitOfXY void lhyWidget::on_lineEdit_Xmax_textChanged(const QString &arg1) { Kin->iniFile->setValue("/LimitOfXY/Xmax", arg1.toDouble()); Kin->Xmax = arg1.toDouble(); } void lhyWidget::on_lineEdit_Xmin_textChanged(const QString &arg1) { Kin->iniFile->setValue("/LimitOfXY/Xmin", arg1.toDouble()); Kin->Xmin = arg1.toDouble(); } void lhyWidget::on_lineEdit_Ymax_textChanged(const QString &arg1) { Kin->iniFile->setValue("/LimitOfXY/Ymax", arg1.toDouble()); Kin->Ymax = arg1.toDouble(); } void lhyWidget::on_lineEdit_Ymin_textChanged(const QString &arg1) { Kin->iniFile->setValue("/LimitOfXY/Ymin", arg1.toDouble()); Kin->Ymin = arg1.toDouble(); } ///Tool void lhyWidget::on_lineEdit_ToolType_textChanged(const QString &arg1) { Kin->iniFile->setValue("/Tool/Type", arg1.toDouble()); Kin->Type = arg1.toDouble(); } void lhyWidget::on_lineEdit_ToolLength_textChanged(const QString &arg1) { Kin->iniFile->setValue("/Tool/Length", arg1.toDouble()); Kin->Length = arg1.toDouble(); } void lhyWidget::on_lineEdit_le_Length_textChanged(const QString &arg1) { Kin->iniFile->setValue("/Tool/le_Length", arg1.toDouble()); Kin->le_Length = arg1.toDouble(); } ///PassiveJoint void lhyWidget::on_lineEdit_R1_min_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/R1_min", arg1.toDouble()); Kin->R1_min = arg1.toDouble(); } void lhyWidget::on_lineEdit_R1_max_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/R1_max", arg1.toDouble()); Kin->R1_max = arg1.toDouble(); } void lhyWidget::on_lineEdit_R2_min_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/R2_min", arg1.toDouble()); Kin->R2_min = arg1.toDouble(); } void lhyWidget::on_lineEdit_R2_max_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/R2_max", arg1.toDouble()); Kin->R2_max = arg1.toDouble(); } void lhyWidget::on_lineEdit_R3_min_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/R3_min", arg1.toDouble()); Kin->R3_min = arg1.toDouble(); } void lhyWidget::on_lineEdit_R3_max_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/R3_max", arg1.toDouble()); Kin->R3_max = arg1.toDouble(); } void lhyWidget::on_lineEdit_R4_min_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/R4_min", arg1.toDouble()); Kin->R4_min = arg1.toDouble(); } void lhyWidget::on_lineEdit_R4_max_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/R4_max", arg1.toDouble()); Kin->R4_max = arg1.toDouble(); } void lhyWidget::on_lineEdit_U1_min_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/U1_min", arg1.toDouble()); Kin->U1_min = arg1.toDouble(); } void lhyWidget::on_lineEdit_U1_max_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/U1_max", arg1.toDouble()); Kin->U1_max = arg1.toDouble(); } void lhyWidget::on_lineEdit_U2_min_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/U2_min", arg1.toDouble()); Kin->U2_min = arg1.toDouble(); } void lhyWidget::on_lineEdit_U2_max_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/U2_max", arg1.toDouble()); Kin->U2_max = arg1.toDouble(); } void lhyWidget::on_lineEdit_S3_min_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/S3_min", arg1.toDouble()); Kin->S3_min = arg1.toDouble(); } void lhyWidget::on_lineEdit_S3_max_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/S3_max", arg1.toDouble()); Kin->S3_max = arg1.toDouble(); } void lhyWidget::on_lineEdit_S4_min_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/S4_min", arg1.toDouble()); Kin->S4_min = arg1.toDouble(); } void lhyWidget::on_lineEdit_S4_max_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/S4_max", arg1.toDouble()); Kin->S4_max = arg1.toDouble(); } void lhyWidget::on_lineEdit_U12_min_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/U12_min", arg1.toDouble()); Kin->U12_min = arg1.toDouble(); } void lhyWidget::on_lineEdit_U12_max_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/U12_max", arg1.toDouble()); Kin->U12_max = arg1.toDouble(); } void lhyWidget::on_lineEdit_U22_min_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/U22_min", arg1.toDouble()); Kin->U22_min = arg1.toDouble(); } void lhyWidget::on_lineEdit_U22_max_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/U22_max", arg1.toDouble()); Kin->U22_max = arg1.toDouble(); } void lhyWidget::on_lineEdit_S32_min_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/S32_min", arg1.toDouble()); Kin->S32_min = arg1.toDouble(); } void lhyWidget::on_lineEdit_S32_max_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/S32_max", arg1.toDouble()); Kin->S32_max = arg1.toDouble(); } void lhyWidget::on_lineEdit_S42_min_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/S42_min", arg1.toDouble()); Kin->S42_min = arg1.toDouble(); } void lhyWidget::on_lineEdit_S42_max_textChanged(const QString &arg1) { Kin->iniFile->setValue("/PassiveJoint/S42_max", arg1.toDouble()); Kin->S42_max = arg1.toDouble(); } ///ActiveJoint void lhyWidget::on_lineEdit_d1_min_textChanged(const QString &arg1) { Kin->iniFile->setValue("/ActiveJoint/d1_min", arg1.toDouble()); Kin->d1_min = arg1.toDouble(); } void lhyWidget::on_lineEdit_d1_max_textChanged(const QString &arg1) { Kin->iniFile->setValue("/ActiveJoint/d1_max", arg1.toDouble()); Kin->d1_max = arg1.toDouble(); } void lhyWidget::on_lineEdit_d2_min_textChanged(const QString &arg1) { Kin->iniFile->setValue("/ActiveJoint/d2_min", arg1.toDouble()); Kin->d2_min = arg1.toDouble(); } void lhyWidget::on_lineEdit_d2_max_textChanged(const QString &arg1) { Kin->iniFile->setValue("/ActiveJoint/d2_max", arg1.toDouble()); Kin->d2_max = arg1.toDouble(); } void lhyWidget::on_lineEdit_d3_min_textChanged(const QString &arg1) { Kin->iniFile->setValue("/ActiveJoint/d3_min", arg1.toDouble()); Kin->d3_min = arg1.toDouble(); } void lhyWidget::on_lineEdit_d3_max_textChanged(const QString &arg1) { Kin->iniFile->setValue("/ActiveJoint/d3_max", arg1.toDouble()); Kin->d3_max = arg1.toDouble(); } void lhyWidget::on_lineEdit_d4_min_textChanged(const QString &arg1) { Kin->iniFile->setValue("/ActiveJoint/d4_min", arg1.toDouble()); Kin->d4_min = arg1.toDouble(); } void lhyWidget::on_lineEdit_d4_max_textChanged(const QString &arg1) { Kin->iniFile->setValue("/ActiveJoint/d4_max", arg1.toDouble()); Kin->d4_max = arg1.toDouble(); }