PVT Example: Quad Circle

In this example we will use PVT algorithm to draw a Quad Circle. The concept involved to derive the equations is as follows:


If we know how many points we have then the angle between each point should be equal as shown below:

pvtquad1.jpg


Now we use the algorithm to find each point coordinate. Below is the equation to find x & y coordinate of point A:

pvtquad2.jpg


Formula used for Velocity is simple:
Velocity = (A - B) / time velocity is computed separately for x & y coordinates


The FOR loop used in the code and lines of code below help fill the position array better explained by image below:


position[x] = (radius*cos((i+1)*degrees*PI/180.0)); position[y] = (radius*sin((i+1)*degrees*PI/180.0));


As you can see from the image below, position[x] populates the values in the red rectangle position[y] populates values in the blue rectangle.

pvtquad3.jpg


The FOR loop used in the code and the lines of code below help fill the velocity array better explained by image below:


vel[x] = (position[x+2] - position[x])/TIME_SLICE; vel[y] = (position[y+2] - position[y])/TIME_SLICE;


As you can see from the image below, vel[x] populates the values in the red rectangle vel[y] populates values in the blue rectangle.

pvtquad4.jpg


The FOR loop and the lines of code below help fill the time array better explained by image below:

time[i] = TIME_SLICE;

pvtquad5.jpg


We also manually set the Velocity of X Axis and Y Axis as 0 for the last point since we want the system to come to rest which is set by the following lines in code:


Final two points (X Axis Final Vel, Y Axis Final Vel) need to be set to 0. vel[(POINTS*2)-2] = 0; //X Axis vel[(POINTS*2)-1] = 0; //Y Axis


Below is the code to draw a Quad Circle. User can enter sensible value of POINTS and TIME_SLICE and RADIUS for testing purposes.

	  #define POINTS		3000    //total points used
      #define AXIS_COUNT	2       //two axis computation (X & Y)
      #define TIME_SLICE	0.005   //each point processed within 10ms
      
      long radius = 1000.00;                     //radius of circle
 
      double PI = 3.14159265358979323;    //variable used in equation to convert degrees to 
      radians
 
      double degrees = 90.00/(POINTS);    //angle between each point. Used in the equation 
      below.
 
      double position[POINTS * AXIS_COUNT];       //defining size of position array
      double vel[POINTS * AXIS_COUNT];            //defining size of velocity array
      double time[POINTS];                        //defining size of time array
 
/////////////////Calculations to Auto Generate Position & Time Array////////////////////////
      for (int i=0, x = 0, y = 1; i < POINTS; i++)
      {
            position[x] = (radius*cos((i+1)*degrees*PI/180.0));
            position[y] = (radius*sin((i+1)*degrees*PI/180.0));
 
            x = x + 2;
            y = y + 2;
 
            time[i] = TIME_SLICE;
      }
 
/////////////////Calculations to Auto Generate Velocity Array////////////////////////////
      for (int i=0, x = 0, y = 1; i < (POINTS-1); i++)
      {
            vel[x] = (position[x+2] - position[x])/TIME_SLICE;
            vel[y] = (position[y+2] - position[y])/TIME_SLICE;
 
            x = x + 2;
            y = y + 2;
      }
 
      //Final two points (X Axis Final Vel, Y Axis Final Vel) need to be set to 0.
      vel[(POINTS*2)-2] = 0;  //X Axis
      vel[(POINTS*2)-1] = 0;  //Y Axis
 
      multiAxis->Abort();
      multiAxis->ClearFaults();
      multiAxis->AmpEnableSet(true);
 
      axis->PositionSet(radius); 
      axis1->PositionSet(0);     
 
      multiAxis->MovePVT(position, vel,  time, POINTS, -1, false, true);
      multiAxis->MotionDoneWait(); 


The result would appear as follows if the X Axis commanded position and Y Axis commanded position are graphed together:

pvtquad6.jpg