Next: 13.1 Types of Variables Up: III. Part 3 - Previous: Endnotes Contents Index

# 13. Programming With Variables

RS274NGC makes provision for the inclusion of variables in the numeric part of program words. Variables can be named with any number up to 5399. You can access the value of a variable in a gcode program by placing a hash (#) sign before the number/name of the variable that you want to reference. Often in the EMC literature the terms variables and parameters are used to refer to the same thing.

For those who learned part programming on older machine tool controls, the inclusion of variables makes for some strange looking program blocks. But variables can be very useful programming tools. This unit develops the concepts of variables as a gcode programming tool and applies them to five common milling tasks.

Before we begin, you need to understand that the NGC development defined a lot of variables and how they should be used in machine control. But the EMC and its interpreter only takes advantage of a few of these variables and those only for its built in coordinate system. You can see which ones, all in the 5000 + range if you view the emc.var or generic.var files shipped with EMC. A typical variable file is listed below. We will add and use several variables that do not have predefined functions in the EMC.

Format is:
<variable> <value>
<variable> runs from 1 to 5399 inclusive, <value> is a number.
Units for <value> are INCHES, the default units for RS-274-NGC.

Lines not of that form, or blank lines, are considered comments. Don't enter a line beginning with two numbers unless you mean it.
You can put whatever you want in here as user variables, but some are reserved. See the RS-274-NGC manual for the reserved variables.
This file is loaded into the interpreter at the beginning, and dumped from the controller at the end.
Only variables you put explicitly in here will be dumped out from the interpreter.

Axes offsets for G92 5211 0.000000 5212 0.000000 5213 0.000000 Coordinate system for G54 - the default used at start 5221 0.000000 5222 0.000000 5223 0.000000 Coordinate system for G55 5241 0.000000 5242 0.000000 5243 0.000000 Coordinate system for G56 5261 0.000000 5262 0.000000 5263 0.000000 Coordinate system for G57 5281 0.000000 5282 0.000000 5283 0.000000 Coordinate system for G58 5301 0.000000 5302 0.000000 5303 0.000000 Coordinate system for G59 5321 0.000000 5322 0.000000 5323 0.000000 Coordinate system for G59.1 5341 0.000000 5342 0.000000 5343 0.000000 Coordinate system for G59.2 5361 0.000000 5362 0.000000 5363 0.000000 Coordinate system for G59.3 5381 0.000000 5382 0.000000 5383 0.000000

Subsections

- 13.1 Types of Variables
- 13.2 Units of Variables
- 13.3 Changing Variable Values
- 13.4 Writing blocks using variables
- 13.5 Sample Variable Programs
  - Example 1 - Drilling a pattern from a variable location
  - Example 2 - Incremented drilling
  - Example 3 - An outside milled four cornered object
  - Example 4 - Milling an inside circle
  - Example 5 - Iterated Run

Next: 13.1 Types of Variables Up: III. Part 3 - Previous: Endnotes Contents Index