Approximate a spiral with constant radius arc segments.  This implementation uses the G2/G3 starting angle-ending angle-radius arc method.  To approximate the spiral the radius is changed every 180 degrees.  By changing the radius at the 0/180 or 90/270 angles the location of center of the arc remains fixed along the X or Y axis of the spiral. For the 0/180 angles the center is always on the X axis of the spiral.  For 90/270 the center is always on the Y axis of the spiral.

This example implements the spiral as a macro.  Operations implemented as macro's do result in a larger programs than the same operation implemented as a subroutine.  The macro can be changed to a subroutine to reduce the program size.  Program automation is used to access the macro or subroutine from user programs. 

Step-by-step guide

Setup the Macro for Auto-include:

  1. Copy the Macro Source code into a new file in Motion Composer
  2. Modify the X and Y axes names in the macro to reflect the axes used to create the spiral
  3. Verify the use of $task0 variable does not conflict with programs that will call the macro.  Change to an unused task variable index if required.
  4. Save the file.
  5. Open configuration manager.
  6. Click on the controller menu item and select "Program Automation->Add" 
  7. Browse for the file saved in step 4
  8. Set the mode to "Include"
  9. Click ok and reset the controller. 

Use the macro in a program

  1. Copy the "Calling Program" code into a new file in Motion Composer
  2. Modify the axis names to reflect the axes used to create the spiral
  3. Save as a PGM file.
  4. Open scope and configure to collect the position command of the X/Y axes. 
  5. Compile and run the file 
  6. Change scope display mode to 2D to view the path of the X/Y axes commanded position.


Macro

// Macro Implementation
// Spiral($x,$y,$rad,$count,$speed) 
//$x and $y are the location of the center of the spiral. This implementation changes the radius at the 0 and 180 degree points.
//the starting angle is 0 so the starting location of the X axis is offset from the circle center by the radius
//$rad is the maximum radius of the spiral
//$count is the number of iterations of the spiral
//$speed is the velocity used along the spiral path

//Comments:
//A critical section is used to ensure continuous motion through the "For-Next" loop. Otherwise the motion could stop during the 
//variable increment and test
//Macro's cannot declare variables so a task variable ($task0) is used as the index variable for the loop
//Change to a different task or global variable if the $task0 is used in the calling program for other purposes
#MACRO Spiral($x,$y,$rad,$count,$speed) G0 X $x+$rad Y $y \ 
 CRITICAL START 600 \ 
 for $task0=$count To 1 STEP -1 \ 
 G2 P0 Q180 R $task0*$rad/$count \ 
 G2 P180 Q0 R ($task0-0.5)*$rad/$count \ 
 next $task0 \ 
 CRITICAL END \
//END


Calling Program

//Calling the Macro
//Enable and home the axes. 
//The G16 command defines the coordinate system for G2/G3 motion and the direction of motion in each of the planes (X/Y, Y/Z, Z/X)
//This example programs motion on the X/Y axes. G17 selects the X/Y plane
//VELOCITY ON enables contouring (constant velocity) between G1/G2/G3 moves
 
ENABLE X Y 
HOME X Y 
G16 X Y Z 
G17
VELOCITY ON 

SCOPETRIG
//Place spiral with center at X=0, Y=0, radius=10, number of turns=5 and speed=10
Spiral(0,0,10,5,10)

2D Plot of Motion

Screen capture of output from example program. Motion starts at angle=0 on the X axis and moves in the clockwise direction (G2) for 5 iterations.