TG Motion  version 421 - 4033/904 cnc 121
Real-time system for controlling servo drives and I/O modules
G-code extensions

TG Motion uses several G-code extensions to simplify G-code programming.

Parametric programming

There are 100 parameters (P00 - P99) which can be used instead of fixed numerical values in any G-code address. All the values are expressed as floating point values with precision of 15-17 digits (double precision).
During G-code execution system uses the value stored in the parameter. Before use, the value should be defined in an assignment.

P37 = 10 + 25 * SIN(45)
G0 X 10 Z P37
Note
Because the parameters are marked as Pxx, the address P is reserved and can be used ONLY for parameters.

Mathematic expressions

Mathematic expression can contain:

Expressions can be entered directly after the address letter:

G0 X P21+P22 Z P23

Or as an assignment to a parameter:

P1 = ReadPLCDouble(1024) + SIN(ABS(ReadPLCLong(2048)))
G1 X P1

Priority of operations

  1. brackets
  2. mathematic functions
  3. power of ^
  4. multiplication and division * /
  5. addition and subtraction + -

Subroutines and labels

Any block of G-code text can act as a subroutine. Subroutine starts with a label or line number and ends with M17 or RETURN. The label is text in the begin of G29 comment function or can be declared independently on a separate line, then it must end with colon \:.
Functions G25, G26 or keyword CALL can be used to call the subroutine. Subroutines must be in the same G-code file as their call(s).

G1 X... Y...
CALL Subroutine1
...
M2
G29 Subroutine1
G2 X... Y... I... J...
...
RETURN

The same meaning with independent label:

G1 X... Y...
CALL Subroutine1
...
M2
Subroutine1:
G2 X... Y... I... J...
...
RETURN

Using line number N:

G1 X... Y...
G25 L 1000
...
M2
N 1000 G2 X... Y... I... J...
...
RETURN

Loops

There are two loop program constructs available: FOR loop and WHILE loop.
FOR loop syntax is:
FOR initial_value TO end_value [STEP step_value]
  ... loop body
END

Example:

P2 = -10 // end Z coord
P3 = 2 // safe Z coord
FOR P1 = 0 TO P2 STEP -1
G1 Z P1
G0 Z P3
END

Every FOR loop must end with keyword END.

WHILE loop syntax is:
WHILE condition
  .. loop body
END

Example:

P1 = 0 // actual Z coord
P2 = -10 // end Z coord
P3 = 2 // safe Z coord
WHILE P1 > P2
G1 Z P1
G0 Z P3
P1 = P1-1
END
G1 Z P2
G0 Z P3
END

The condition could be:

Symbol Description
> Greater than
< Less than
== Equal to
!= Not equal to
<> Not equal to
<= Less or equal to
>= Greater or equal to

Conditional jumps

Sometimes it is useful to skip some block of G-code parts depending on some condition. Conditional jumps are used for this situation.
Syntax is:
IF condition THEN
  ...
ELSE
  ...
END

If the condition after the IF keyword is met, the code till ELSE is executed, otherwise the code between ELSE and END is executed.
Example:

FOR P21 = 60 TO 45-P22 STEP P22
IF P24 == 0 THEN
CALL Cone
ELSE
CALL Remove
P23 = P23 + P24
END
P25 = P25 + P26
END

Conditional jumps can be used to exit from loop, exit from subroutine or continue loop on a next iteration: