'***************************************************************************
'Description:
'This example code is an introduction to Galil programming
'***************************************************************************
'Anything that is preceded with an apostrophe is a comment
'A label is preceded by a # sign and can followed by up to 7 characters
'The max line length for current generation controllers is 80 characters.

'Commands can be entered from a command line or in a program
'To execute programs, download the code into the controller and
'then issue XQ to start executing from the top. Issue XQ#LABEL
'to start executing at a specific label or line number.
'The code will execute until an EN ends the program or subroutine

#AUTO
'The #AUTO label is a special label that tells the controller to
'automatically start running as soon as power is applied.
'To perform a basic move, issue a PR command as shown here:
ACA= 1000000;  'acceleration
DCA= 1000000;  'deceleration
SPA= 20000;    'speed
PRA= 40000;    'distance
'This will move the X axis motor 40000cts.
BG A;           'start the motion
AM A;  'waits for motion to complete before continuing code execution
WT 2000; 'causes the controller to wait 2 seconds
EN


'To change parameters on multiple axes at once, use commas for each axis
#chg_spd
SP 20000,,40000; 'this specifies the speed for the X and Z axes
SP*= 20000;       'this sets the speed for ALL axes to 20000
'Axis designators can be ABCDEFGH or XYZWEFGH
'The following two commands do exactly the same thing (set speed for axis 1). Galil recommends using A,B,C,D instead of X,Y,Z,W
SPA= 20000
SPX= 20000
EN

#operand
'Operands - the value of almost all commands can be interrogated by using
'the underscore and then the command like this:
speedx= _SPA;    'creates a variable (SpeedX) and sets it to the value of SPX
EN

#message
'Messages - to output something to the screen from a program, use the MG cmd
speedx= _SPA
MG speedx;  'outputs variable SpeedX
MG "The Speed of the X axis is ",_SPA
'or alternatively
MG "The Speed of the X axis is ",speedx," cts/sec"
EN

#var1
i= 1;     'defines the variable i to 1
'Variables can be up to 8 characters long (upper or lower case or mixed)
'They are case sensitive and should not be the same as commands.
'For example, PR is not a good choice for a variable name.
'To list all current variables use the LV command
'
EN

#init
i= 0
#loop;    'This is a label that defines the start of a subroutine
 DPA= 0;    'Defines position of the X axis to zero
 PRA= 100;  'Position relative move of 100cts
 BG A;      'Begin motion
 AM A;      'Wait for motion to complete
 WT 1000;  'Wait 1 second
 PRA= -100; 'Move -100 counts (opposite direction)
 BG A;AM A;WT 1000;  'to condense code, put multiple cmds on one line
 i= i+1;    'Increment the variable i
JP #loop,i<5;   'Jump to the #LOOP label while i is less than 5
MG "DONE";    'Output a message when you are finished
EN;           'Ends the program