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

📄 p1240arctheta.cpp

📁 基于PCI-1240运动控制卡的示例2-ArcTheta
💻 CPP
字号:
//*****************************************************************************
// Program        : P1240ArcTheta.CPP                                                  
// Description    : PCI-1240 demo program for X & Y-Axis arc interpolation 
//                  function with center/angle parameter.                                   
// APIs used      : P1240MotDevOpen, P1240MotAxisParaSet, P1240MotArcTheta,              
//                  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 "..\..\..\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 = 8000;   //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 lCenter1, lCenter2 is pulse
   LONG lCenter1 = -5000;
   LONG lCenter2 = 0;
   DOUBLE dMoveAngle = -120; //angle is 120 degree, counter-clockwise

   printf(" PCI-1240 demo program for X & Y-Axis \n");
   printf(" arc interpolation function with center/angle parameter.\n\n");
   printf(" T curve acceleration \n");
   printf(" Absolute coordinate \n");
   printf(" Movement Direction CCW(counter-clockwise) \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 axis center : %6d\n", lCenter1);
   printf(" Y axis center : %6d\n", lCenter2);
   printf(" Move angle    : %7.3f\n", dMoveAngle);

   //If PCM-3240 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;
   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("\nDevice open success!\n");
   }

   // Set arc interpolation parameter
   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("\nSetting parameter.......\n");

RESTART:
   // Start arc function
   dwReturnCode = P1240MotArcTheta(
      byBoard_ID, // Board ID number
      XY_Axis,    // Set 0 for Arc Interpolation
      byRA,       // Assign movement operation is relative 
                  // or absolute coordinate
      lCenter1,   // The center position for first axis
      lCenter2,   // The center position for second axis
      dMoveAngle);// Degree for moving

   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 )
   {
      ;
   }
   
   //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;
   }
   
   // 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 Press any key to quit.\n");
   getch();
}

⌨️ 快捷键说明

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