⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p1240line.cpp

📁 基于PCI-1240运动控制卡的示例4-Linek
💻 CPP
字号:

// ****************************************************************************
// Program        : P1240LINE.CPP                                                       
// Description    : PCI-1240 demo program for X & Y-Axis 
//                  linear interpolation function. 
// APIs used      : P1240MotDevOpen,
//                  P1240MotAxisParaSet,P1240MotLine,P1240MotAxisBusy   
//                  P1240MotDevClose                                                    
// Author         : xianfeng.yan                                              
// Revision       : 1.10                                                      
// Created        : 01/19/2005           Advantech Co., Ltd.                     
//*****************************************************************************

#include <windows.h>
#include <windef.h>
#include <stdio.h>
#include <conio.h>
#include <winreg.h>
#include <iostream.h>

#include "..\..\..\include\ADS1240.h"


void main()
{
   DWORD dwReturnCode;

   BYTE byBoard_ID = 0;
   BYTE byTS = TCurveAcceleration;
   BYTE byRA = AbsoluteCoordinate;
   DWORD dwSV = 1000;   //Start Velocity, 1000 pulse per second
   DWORD dwDV = 50000;   //Drive Speed, 8000 pulse per second
   DWORD dwAC = 480000; //Acceleration Speed, 480000 pulse per second
   DWORD dwAK = 960000; //Acceleration Rate, 960000 pulse per second
   DWORD dwMDV = 800000;//Maximum Drive Speed, 800000 pulse per second
   //The Unit for lPulseX, lPulseY is pulse
    LONG lPulseX = 200000;
    LONG lPulseY = 0;
	LONG lPulseZ = 80000;

   printf(" PCI-1240 demo program for X & Y Axis"); 
   printf(" linear interpolation function.\n\n");
   printf(" T curve acceleration\n");
   printf(" Relative coordinate\n");
   printf(" MDV(Maximum Drive Speed) : %7d\n", dwMDV);
   printf(" SV(Start Velocity)       : %7d\n", dwSV);
   printf(" DV(Drive Speed)          : %7d\n", dwDV);
   printf(" AC(Acceleration Speed)   : %7d\n", dwAC);
   printf(" AK(Acceleration Rate)    : %7d\n", dwAK);
   printf(" X PULSE : %6d\n",lPulseX);
   printf(" Y PULSE : %6d\n",lPulseY);
   
   //If PCI-1240 drives a servo motor,
   //a "SERVO-ON" signal should be sent to the driver before moving.
   //If this signal is not auto set when power on, you can follow these steps:
   //1. Power Off.
   //2. Connect "nOut6" to the driver's "SERVO-ON" signal.(n stand for X,Y,Z,U)
   //3. Power On.
   //4. Call "P1240SetOutputType" to set general output type. 
   //5. Call "P1240MotDO" to enable "SERVO-ON".
   printf(" If you use servo motor, Please make sure that the Servo is on!\n");

   printf(" Please input BoardID (the range is from 0 to 15)\n");
   int tempID=0;
//   scanf("%d", &tempID);
   while ( (tempID < 0 ) || (tempID > 15) )
   {
      printf("BoardID out of range, please enter a correct one!\n");
      scanf("%d", &tempID);
   }
   byBoard_ID = tempID;      
   
   // Device open
   dwReturnCode = P1240MotDevOpen(byBoard_ID);
   if ( dwReturnCode != ERROR_SUCCESS )
   {
      printf("\n\n Program Fail 0x%04x", dwReturnCode);
      printf("\n Board %d doesn't exsit !", byBoard_ID);
      printf("\n Press any key to exit....");
      getch();
      exit(1);
   }
   else
   {
      printf("Device open success!\n");
   }

   // Set linear interpolation parameter
	dwReturnCode = P1240MotAxisParaSet(
		byBoard_ID, // Board ID number
	    0,          // Set 0 for Arc or Line 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);
RESTART:
   // Start line function

	for(int h=1;h<5;h++)
	{
		dwReturnCode = P1240MotLine(
	      byBoard_ID, //Board ID number
	      XZ_Axis,    //Assign operation axis
	      byRA,       //Assign movement operation is relative 
                  //or absolute coordinate
	      lPulseX,    //The new position for X axis
	      0,    //The new position for Y axis
	      lPulseZ,          //The new position for Z axis
	      0);         //The new position for U 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, XZ_Axis ) != ERROR_SUCCESS )
	   {
	      ;
	   }
	   lPulseX=-lPulseX;
	   lPulseZ=-lPulseZ;
	   cout<<lPulseX<<"    "<<lPulseZ<<endl;
	}

   //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;
   }

   dwReturnCode = P1240MotDevClose(byBoard_ID);
   if ( dwReturnCode != ERROR_SUCCESS )
      printf("\n\n Program Fail 0x%04x", dwReturnCode);
   else
      printf("\nDevice closed!\n");

   printf("\n Press any key to quit.\n");
   getch();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -