10. Custom Macro
Variables
Macro Variables
Variables are fundamental elements of parametric programming and allow storing and manipulating numerical values.
Variable Types
| Range | Type | Description |
|---|---|---|
| #1 - #33 | Local | Arguments passed to macro (A=#1, B=#2, C=#3...) |
| #100 - #199 | Common | Shared between programs, cleared on power off |
| #500 - #999 | Permanent | Retained even after power off |
| #1000+ | System | Axis positions, machine states, timers |
Common System Variables
| Variable | Description |
|---|---|
| #5001-#5006 | Block end position (X,Y,Z,A,B,C) |
| #5021-#5026 | Current machine position |
| #5041-#5046 | Current work position |
| #3001 | Millisecond timer |
| #3002 | Hour timer |
| #4001-#4021 | Active modal G codes |
Using Variables
; Assignment
#1 = 25.5 ; Direct value assignment
#2 = #1 * 2 ; Operation result assignment
#3 = [#1 + #2] / 2 ; Complex expression
; Use in movements
G1 X#1 Y#2 Z#3 F500
; Use in parameters
G81 X0 Y0 Z[-#4] R2 F#5
; Indirect variables
#[#10] = 100 ; #10 contains variable number
#11 = #[#10] ; Reads variable indicated by #10
Empty Variable (#0)
Variable #0 is always empty and can be used to:
- Check if an argument was passed
- Skip optional parameters
IF [#1 EQ #0] THEN #1 = 10 ; If #1 empty, use default 10
Note: Variable ranges may vary between controllers. Always check your specific controller manual.
