Next: 14. Remote GUIs Up: 13.5 Sample Variable Programs Previous: Example 4 - Milling Contents Index

## Example 5 - Iterated Run

As we have already seen in example 2, the EMC's interpreter allows for the setting of variables during program code execution. That example reset the loop variable at the start of each program run. But the value of a variable persists throughout the life of an EMC run so that it's incremented value can be accessed by pressing the <run> button to start the next loop.

Variable #1000 is a explicit variable. It is also the loop variable. By making #1000 explicit the machine operator can reset the loop to zero by reloading the parameter file from the TclTk parameter edit window when all of the loops through the program have been completed. This code shows a simple drilling operation that uses successive coordinate systems for each run.

This line is placed in the variable file. 1000 1001 The code below shows a simple drilling operation that uses successive coordinate systems each time the run button is pressed. It is line number n150 that does the work of incrementing explicit loop variable #1000. The work done by the machine could be expanded with the addition of lines of code before line 150 to as large a program as needed at each coordinate position.

`Incremented program that uses the <run> button for loop and <load variable file> to reset the loop`
`N10 (sample loop program with <run> press for each interation)`
`N20 #1001 = 54 (variables to reference coordinate systems)`
`N30 #1002 = 55`
`N40 #1003 = 56`
`N50 #1004 = 57`
`N60 #1005 = 58`
`N70 #1006 = 59`
`N80 #1007 = 59.1`
`N90 #1008 = 59.2`
`N100 #1009 = 59.3`
`N110 G0 X0 Y0 Z0 (move to known location)`
`N120 G#[#1000 + 1001] X0 Y0 (pick up new coordinates)`
`N130 G1 F5 Z1 (drill)`
`N140 G0 Z0`
`N150 #1000 = [#1000 + 1] Increment the loop variable)`
`N160 M2`

This kind of program might be used with a setup that had a number of vices on the milling table with the same part in each. The same thing could be achieved using a single program with incrementing between each and an option stop (m0). Such a program would be much longer and would require <restart> rather than <run>.

As the EMC interpreter exists now, there is no good way to know which coordinate system will be used next without looking at the machine or remembering the offsets as loaded into each coordinate system. This code will also cause an error message if you attempt to run it after the nineth time. Since the loop variable is explicit, it can be reset at any time before the EMC is shut down by reloading the variable file.

Next: 14. Remote GUIs Up: 13.5 Sample Variable Programs Previous: Example 4 - Milling Contents Index