?? p1240ptp.cpp
字號(hào):
else
printf("\nMoving......\n");
// Program wait when axis busy
while ( P1240MotAxisBusy( byBoard_ID, XY_Axis ) != ERROR_SUCCESS )
{
;
}
cout<<"If you want to restart,press r."<<endl;
cin>>back;
if((back == 'R') || (back == 'r'))
goto RESTART;
// else
// break;
}
else if(a==3)
{
lPulseX = 150000;
lPulseY = 100000;
dwDV = 20000;
dwReturnCode = P1240MotPtp(
byBoard_ID, // Board ID number
XY_Axis, // Assign the operation axis
byRA, // Assign movement operation is relative
// or absolute coordinate
lPulseX, // The movement pulses number for X axis
lPulseY, // The movement pulses number for Y axis
lPulseZ, // The movement pulses number for Z axis
lPulseU); // The movement pulses number for U axis
if ( dwReturnCode != ERROR_SUCCESS )
printf("\n\n Program Fail 0x%04x", dwReturnCode);
else
printf("\n Moving......\n");
LONG lCenter1 = 0;
LONG lCenter2 = 10000;
LONG lEnd1 = 0;
LONG lEnd2 = 20000;
cout<<"Please input the DV of the arc interpolation:"<<endl;
cin>>dwDV;
dwReturnCode = P1240MotAxisParaSet(
byBoard_ID, // Board ID number
0, // Set 0 for Arc Interpolation
byTS, // Assign the acceleration type T or S
dwSV, // Assign the initial speed
dwDV, // Assign the drive speed
dwMDV, // Assign the Maximum drive speed
dwAC, // Assign the acceleration speed
dwAK); // Assign the acceleration rate
if ( dwReturnCode != ERROR_SUCCESS )
printf("\n\n Program Fail 0x%04x", dwReturnCode);
else
printf("Setting parameter.......\n");
// Start arc function
//RESTART:
dwReturnCode = P1240MotArc(
byBoard_ID, // Board ID number
XY_Axis, // Assign the operation axis
byRA, // Assign movement operation is relative
// or absolute coordinate
byArcDirection, // Assign the movement direction
lCenter1, // The center position for first axis
lCenter2, // The center position for second axis
lEnd1, // The end position for first axis
lEnd2); // The end position for second axis
if ( dwReturnCode != ERROR_SUCCESS )
printf("\n\n Program Fail 0x%04x", dwReturnCode);
else
printf("\nMoving......\n");
// Program wait when axis busy
while ( P1240MotAxisBusy(byBoard_ID, XYZ_Axis) != ERROR_SUCCESS )
{
;
}
cout<<"If you want to restart,press r."<<endl;
cin>>back;
if((back == 'R') || (back == 'r'))
goto RESTART;
// else
// break;
}
else if(a==2)
{
double x[27] = {10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200,220,240,260,280,300,320,340};
double y[27] = {10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200,210,220,230,240,250,260,270};
int i,n;
// double x2[27];
// double y2[27];
// x[]
// y[]
n=27;
for(i=0;i<n;i++)
{
if(x[i]<0 || x[i]>660 || y[i]<0 || y[i]>410)
{
cout<<"The position is illegal."<<endl;
break;
}
else
if(i==0)
{
lPulseX2 = x[i]*500;
lPulseX=lPulseX2+10000;
lPulseY2 = y[i]*500;
lPulseY=lPulseY2+10000;
}
else
{
lPulseX2 = (x[i]-x[i-1])*500;
lPulseX=lPulseX2+10000;
lPulseY2 = (y[i]-y[i-1])*500;
lPulseY=lPulseY2+10000;
}
dwDV=20000;
dwReturnCode = P1240MotAxisParaSet(
byBoard_ID, // Board ID number
Y_Axis, // Assign the operation axis
byTS, // Assign the acceleration type T or S
dwSV, // Assign the initial speed
dwDV, // Assign the drive speed
dwMDV, // Assign the Maximum drive speed
dwAC, // Assign the acceleration speed
dwAK); // Assign the acceleration rate
if ( dwReturnCode != ERROR_SUCCESS )
printf("\n\n Program Fail--MotAxisParaSet1 0x%04x", dwReturnCode);
if (i==0)
{
if(y[i]!=0)
dwDV *= (x[i]/y[i]);
else
dwDV = 50000;
}
else
{
double m,k;
if(y[i]!=y[i-1])
m = (x[i]-x[i-1])/(y[i]-y[i-1]);
else
m = 2;
// cout<<m<<endl;
k = (m>0?m:-m)*dwDV;
dwDV = (long)k;
if(dwDV>dwMDV)
{
cout<<"error!"<<endl;
break;
}
}
dwReturnCode = P1240MotAxisParaSet(
byBoard_ID, // Board ID number
X_Axis, // Assign the operation axis
byTS, // Assign the acceleration type T or S
dwSV, // Assign the initial speed
dwDV, // Assign the drive speed
dwMDV, // Assign the Maximum drive speed
dwAC, // Assign the acceleration speed
dwAK); // Assign the acceleration rate
if ( dwReturnCode != ERROR_SUCCESS )
printf("\n\n Program Fail--MotAxisParaSet2 0x%04x", dwReturnCode);
//讀邏輯位置計(jì)數(shù)器
ULONG Xposi,Yposi,Xposi2,Yposi2;
dwReturnCode = P1240MotRdReg(
byBoard_ID, // Board ID number
X_Axis,
Lcnt,
&Xposi);
cout<<"Xposi"<<Xposi<<endl;
if ( dwReturnCode != ERROR_SUCCESS )
printf("\n\n P1240MotRdReg Fail 0x%04x", dwReturnCode);
dwReturnCode = P1240MotPtp(
byBoard_ID, // Board ID number
XY_Axis, // Assign the operation axis
byRA, // Assign movement operation is relative
// or absolute coordinate
lPulseX, // The movement pulses number for X axis
lPulseY, // The movement pulses number for Y axis
lPulseZ, // The movement pulses number for Z axis
lPulseU); // The movement pulses number for U axis
if ( dwReturnCode != ERROR_SUCCESS )
printf("\n\n Program Fail--P1240MotPtp 0x%04x", dwReturnCode);
else
printf("\n Moving......\n");
// Program wait when axis busy
while ( P1240MotAxisBusy(byBoard_ID, XY_Axis) != ERROR_SUCCESS )
{
dwReturnCode = P1240MotRdReg(
byBoard_ID, // Board ID number
X_Axis,
Lcnt,
&Xposi2);
if ( dwReturnCode != ERROR_SUCCESS )
printf("\n\n P1240MotRdReg Fail 0x%04x", dwReturnCode);
if((Xposi-Xposi2)==lPulseX2||(Xposi-Xposi2)==-lPulseX2)
{
cout<<"Xposi2"<<Xposi2<<endl;
break;
}
}
}
cout<<"If you want to restart,press r."<<endl;
cin>>back;
if((back == 'R') || (back == 'r'))
goto RESTART;
// else
// break;
}
// default:
// cout<<"error!"<<endl;
// break;
//Give user the chance to run program again
printf("\nPress 'R' or 'r' to Run again, press other keys to continue!\n");
int iChar = getch();
if ( ((iChar == 'R') || (iChar == 'r')) )
{
goto RESTART;
}
else
{
// Device close
dwReturnCode = P1240MotDevClose(byBoard_ID);
if ( dwReturnCode != ERROR_SUCCESS )
printf("\n\n Program Fail 0x%04x", dwReturnCode);
else
printf("\nDevice closed!\n");
//printf("\n\n Press any key to quit\n");
getch();
exit(1);
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -