For simplification we will be working in word address format.
LESSON 2
Conditional statements
Like most programming languages G-code allows for conditional statements albeit in a rudimentary and limited form.
comparison operators
CNC G-Code used few comparison operators which vary by control. The most common comparison operators for fanuc style controls are;
'NE: NOT EQUAL
EQ: EQUAL
LE: LESS THAN OR EQUAL
LT: LESS THAN
GT: GREATER THAN
GE: GREATER THAN OR EQUAL'
IF[] THEN
The If Then Conditional statement can be used to instruct your code to jump to a specific sequence or to set a macro variable value.
'IF[(X) NE (Y)] THEN #3000=1.0(X NOT EQUAL TO Y);'
this example would display an error message of 'X NOT EQUAL TO Y'.
Another example is
'IF[#100 GE 5] THEN GOTO 1'
This example would skip the program to sequence N1 if macro 100 is greater than or equal to 5.
The While Loop
The while loop is useful for when you want a sequence of code to repeat until a condition is met. For example let's say you wanted to run a machine wash cycle after running five loads of parts. You could write a while loop to accomplish this.
(MAIN PROGRAM RUNS UP HERE);'
'#101=#101+1;'
'WHILE[#101 GE 5] DO1'
'M98P(WASH CYCLE PROGRAM NUMBER);'
'#101=0;
END1;
For simplification we will be working in word address format.
#LESSON 2
## Conditional statements
Like most programming languages G-code allows for conditional statements albeit in a rudimentary and limited form.
##comparison operators
CNC G-Code used few comparison operators which vary by control. The most common comparison operators for fanuc style controls are;
'NE: NOT EQUAL
EQ: EQUAL
LE: LESS THAN OR EQUAL
LT: LESS THAN
GT: GREATER THAN
GE: GREATER THAN OR EQUAL'
##IF[] THEN
The If Then Conditional statement can be used to instruct your code to jump to a specific sequence or to set a macro variable value.
'IF[(X) NE (Y)] THEN #3000=1.0(X NOT EQUAL TO Y);'
this example would display an error message of 'X NOT EQUAL TO Y'.
Another example is
'IF[#100 GE 5] THEN GOTO 1'
This example would skip the program to sequence N1 if macro 100 is greater than or equal to 5.
##The While Loop
The while loop is useful for when you want a sequence of code to repeat until a condition is met. For example let's say you wanted to run a machine wash cycle after running five loads of parts. You could write a while loop to accomplish this.
`(MAIN PROGRAM RUNS UP HERE);'
'#101=#101+1;'
'WHILE[#101 GE 5] DO1'
'M98P(WASH CYCLE PROGRAM NUMBER);'
'#101=0;
END1;`
(post is archived)