Download as pdf or txt
Download as pdf or txt
You are on page 1of 38

Robots & Automation – MFET 445

Robots & CNC in Integrated


Manufacturing – MFET 685
Agenda
• G-code Parameters
• G-code Flow control

2
Numbered Parameters
Parameters are G-Code “variables”
Indicated with a # sign prefix

#1
#31
#5399

Parameters #1-30 or so are only used to pass arguments to subroutines


• Read-only
• Local to subroutine

All parameters are floating point numbers


Tormach
Fanuc
Named Parameters
• You can use an English variable name to help prevent confusion
• Use angle brackets to enclose name
• Default is local (within routine), use leading underscore for global

#<localvariable>

#<_globalvariable>

#<tool_diameter>
#<number_of_parts>
#<ZERO_OFFSET>
Setting Parameters
• Use equal sign to set a parameter value

#<variable_name> = 27

Sets the parameter <variable_name> to a value of 27

#<variable_name_1> = 55
#<variable_name_2> = #<variable_name_1>

Sets the parameter <variable_name_2> to the same as <variable_name_1>, equal to 55


Using Parameters
• Parameters can be used in regular g-code commands

#<X_value> = 30
#<Y_value> = 45

G00 X#<X_value> Y#<Y_value>

Does a rapid move to X=30, Y=45


Using Parameters
• Parameters are set only after all parameter values on the same line are found

#<X> = 15

#<X>=6 G01 X#<X>

Does a linear interpolation to X=15, then sets <X> to a value of 6


Using Parameters
• You can use parameters to point at parameters

#50 = 75

##50 = 10

Sets the value of parameter 75 to a value of 10


External Parameters
M64 – activate outputs https://www.tormach.com/blog/r
M65 – deactivate outputs obot-meet-tormach/

For example

M64 P0

Activates relay #1
On a tormach mill using Mach or Pathpilot
controls, these are used to control external devices
M65 P2
• Coolant systems
Deactivates relay #2 • Robot controls
• PLC interface
• Door control
• Pneumatic vise jaws

4 external relays available


External Parameters
M66 – wait on input https://www.tormach.com/blog/r
obot-meet-tormach/
For example

M66 P0 L0

M66 P1 L3 Q5000
Parameters Math
Parameters Expressions
• Since regular parentheses are used for comments, use square brackets for expressions

#<endmill_radius> = [#<endmill_diameter> / 2]

#55 = 2.0 / 3 * 1.5 – 5.5 / 11.0

Is equivalent to

#55 = [[[2.0 / 3] * 1.5] – [5.5 / 11.0]]


Parameters Expressions
Logical operations
operator Meaning
Number 0.0 is FALSE, any other nonzero number is EQ Equal
TRUE (default 1)
NE Not equal
#54 = 0 GT Greater than
#55 = 19
#56 = 27 LT Less than
#57 = [#55 LE #56] OR #54 GE Greater than/equal
#58 = [#55 LE #56] AND #54
LE Less than/equal
Sets #57 to a value of 1 AND Logical AND
Sets #58 to a value of 0
OR Logical OR
XOR Logical exclusive OR
Subroutines
Labeled with the letter O, uses M98 to call and M99 to end

O123

or

O<subroutine_name>
Subroutines
%
O1000
Fanuc controls
(main program code)

M98 P2000

M2

O2000

(subroutine code)

M99

M30
%
Macros– Passing parameters
%
O1000

G65 P2000 X10 Y12 Z55

M2

O2000

G00 X#24 Y#25


G00 Z#26

M99

M30
%
Macro call

G65 invokes a macro call. It is NOT modal (need to re-invoke G65 each time)
modal

Not
modal
G66 invokes a macro just like G56, but it is modal.
Modal macro call Each change in coordinates calls the macro again

Modal
calls
macro
P8004

G67 cancels modal macro call


G-Code Flow Control
GOTO

Unconditional branch
Jumps directly to a new line number

N100 G00 Z5
N110 GOTO 130
N120 G00 Z10
N130 M30
G-Code Flow Control
GOTO

Unconditional branch
Jumps directly to a new line number

N100 G00 Z5
N110 GOTO 100
N120 G00 Z10
N130 M30
G-Code Flow Control
GOTO

Unconditional branch
Jumps directly to a new line number

N100 G00 Z5
N110 GOTO 100
N120 G00 Z10
N130 M30
G-Code Flow Control
IF [condition] GOTO NNN

Conditional branch
Makes a decision – if [condition] evaluates to TRUE, then the program jumps to line NNN
Otherwise, the next line is executed

N100 G00 Z2
N110 #100 = 0
N120 IF [#100 EQ 5] GOTO 500
N130 G81 X#100 Y#100 Z-1 R2 F5
N140 #100=#100+1
N150 GOTO 120

500 M30
G-Code Flow Control
IF [condition] THEN [expression]

Conditional expression
Makes a decision – if [condition] evaluates to TRUE, then the [expression] is executed
If [condition] evaluates to FALSE, nothing happens and the next line is executed

N100 IF [#100 EQ 0] THEN #100 = 1


N110 #110 = #105/#100

No G or M codes are allowed after the THEN

N100 IF [#100 EQ 0] THEN G00 X5

Will throw an error.


G-Code Flow Control
IF [condition] THEN [expression]

Conditional expression can be complex


Makes a decision – if [condition] evaluates to TRUE, then the [expression] is executed
If [condition] evaluates to FALSE, nothing happens and the next line is executed

N100 IF [[#100 LT 0] AND [#101 GT 5]] GOTO 500


G-Code Flow Control
#100 = 0
G00 X0 Y0
WHILE [#100 LT 5] DO1
G1 X#100 Y0 F10
Y1
Y0
#100=#100+1
END1
G00 X0 Y0
G-Code Flow Control
#100 = 0
G00 X0 Y0
WHILE [#100 LT 5] DO1
G1 X#100 Y0 F10
Y1
Y0
#100=#100+1
END1
G00 X0 Y0

1st time: #100=0


X0 Y1

X0 Y0
G-Code Flow Control
#100 = 0
G00 X0 Y0
WHILE [#100 LT 5] DO1
G1 X#100 Y0 F10
Y1
Y0
#100=#100+1
END1
G00 X0 Y0

2nd time: #100=1


X1 Y1
X0 Y1

X0 Y0 X1 Y0
G-Code Flow Control
#100 = 0
G00 X0 Y0
WHILE [#100 LT 5] DO1
G1 X#100 Y0 F10
Y1
Y0
#100=#100+1
END1
G00 X0 Y0

5th time: #100=5


X0 Y1 X4 Y1

X4 Y0
X0 Y0 X1 Y0
G-Code Flow Control
#100 = 1
G00 X0 Y0
G00 Z=1
WHILE [#100 LT 5] DO1 Nested WHILE loops
#101=0
WHILE [#101 LT #100] DO2
G00 X#100 Y#101
G01 Z0 F5
#103=#100+0.1
G01 X#103 Y#101 F10
G0 Z1
#101=#101+1
END2
#100=#100+1
END1
G00 X0 Y0
G-Code Flow Control
#100 = 1
G00 X0 Y0
G00 Z=1
WHILE [#100 LT 5] DO1 Nested WHILE loops
#101=0
WHILE [#101 LT #100] DO2
G00 X#100 Y#101
G01 Z0 F5
#103=#100+0.1 X3 Y3
G01 X#103 Y#101 F10
G0 Z1
#101=#101+1
END2 X3 Y2
#100=#100+1
END1
G00 X0 Y0
X0.1 Y0 X3 Y1

X3 Y0
X0 Y0 X1 Y0 X2 Y0
X0 Y0
G-Code Flow Control
G90 Nested loops
#100 = 0
G00 X0 Y0
G00 Z=1
WHILE [#100 LE 5] DO1
G00 X0 Y#100
G91 G81 X1 Z-1 R1 F10 K5
G90
#100=#100+1
END1
G00 X0 Y0

X0 Y0
Coordinate Transformation

G68 X0 Y0 R120

Rotates the coordinate system by 120 degrees counterclockwise


Around the point X0 Y0
Coordinate Transformation

G69

Cancels a coordinate rotation


Coordinate Transformation

O2001
G00 Z1
G00 X1 Y0
G01 Z-0.5 F5
G01 X2 Y0 F10
G00 Z1
M99

X1 Y0 X2 Y0
Coordinate Transformation
G00 Z1
#100=0
WHILE [#100 LT 360] DO1
G68 X0 Y0 R#100
M98 P2001
#100 = #100 + 10
END1
G69
M30 etc

O2001
G00 Z1
G00 X1 Y0 X1 Y0 X2 Y0
G01 Z-0.5 F5
G01 X2 Y0 F10
G00 Z1
M99

You might also like