Next: Example 3 - An Up: 13.5 Sample Variable Programs Previous: Example 1 - Drilling Contents Index

## Example 2 - Incremented drilling

The lines of code below illustrate the technique of incrementing variables along with using those variables during the running of a program. Again lines N10 and N12 assign initial values to the variables that will be used. Line N14 moves the machine to the location of the hole to be drilled while N16 and N18 perform the operation. Line N20 increments both variables. In the illustrated code #1000 is increased by 2 and #1001 is increased by 1. Taken together, lines N14 through 18 are a loop (although this version of RS274NGC does not implement looping) and the code is just copied and pasted into the program for the number of times the operation is to be repeated.

`N10 #1000 = 0 (x distance for first hole)`
`N12 #1001 = 0 (y distance for first holes)`
`N14 G55 g0 x#1000 y#1001 z1 (move to first hole)`
`N16 g1 f4 z2 (drill)`
`N18 g0 z0`
`N20 #1000 = [#1000 + 2] #1001 = [1001 + 1]`
`N14 G55 g0 x#1000 y#1001 z1 (move to second hole)`
`N16 g1 f4 z2 (drill)`
`N18 g0 z0`
`N20 #1000 = [#1000 + 2] #1001 = [1001 + 1]`
`N14 G55 g0 x#1000 y#1001 z1 (move to third hole)`
`N16 g1 f4 z2 (drill)`
`N18 g0 z0`
`N20 #1000 = [#1000 + 2] #1001 = [1001 + 1]`
`N14 G55 g0 x#1000 y#1001 z1 (move to fourth hole)`
`N16 g1 f4 z2 (drill)`
`N18 g0 z0`
`N52 g53 x0 y0 z0`
`N54 m2`

Since the EMC interpreter doesn't care what the lines are numbered, the above code will run as is. It would look somewhat better if it were renumbered. Again only the variable values need to be changed to move the location of the set of holes. In this case, the code will produce a diagonal set of four holes. Each hole is two inches in x and one inch in y away from the previous hole.

A cautionary note must be included here. Once the machine tool is into the program, there is no good way to know where it is except to observe the machine itself. Stopping and then restarting from anywhere but the top line is an invitation to disaster because the values of the variables have been changed by the program itself.

Next: Example 3 - An Up: 13.5 Sample Variable Programs Previous: Example 1 - Drilling Contents Index