Combining G-Code and ST
A GST-Program
<g-code>
<g-code>
! <st-code>
<g-code>
<g-code>
{
<st-code>
<st-code>
! <g-code>
<st-code>
<st-code>
}
<g-code>
<g-code>
A GST-file consists of sequences of G-code and sequences of ST-code that can be interleaved as shown above. Each program starts in G-code mode. The mode can be switched to ST for one line using an exclamation mark (‘!’). The ST-mode ends at the end of line automatically.
As an alternative a block of ST-code can be defined using curly braces (‘{‘…’}’). This notation is more practical to define a long sequence of ST-code in a GST-program. Within the ST-block the G-code mode can be entered for one line using the exclamation mark. Thereby, the G-code mode ends at the end of line automatically.
G-Code Block
<address><value> <address>=<G-Expression> <address>{<ST-Expression>}
A line of G-code is called a block. It consists of a sequence of words. A word is a combination of an address (e.g. G or X) and a value. A value can be defined by a literal (e.g. 2.54), by a G-expression (e.g. 2*foo+1) or by an ST-expression (e.g. sin(foo**2)-1).
G-Code Expression
<address>=a+b-c*d/e
The result of the expression is used as the value of the word. The four basic arithmetic operations (‘+’, ‘-’, ‘*’, ‘/’) can be used in a G-expression. They are evaluated as expected, i.e. all operations are left-associative and ‘*’, ‘/’ have a higher precedence than ‘+’, ‘-’. Variables that have been declared in ST can also be used in a G-expression (with respect to their scope).
All computations are performed using type LReal (64-bit floating point according to IEEE 754). The value of an ST-variable is implicitly converted to type LReal according to the conversion rules of ST. If a type (e.g. STRING) cannot be converted, an error is reported.
![]() | RESTRICTION:
|
![]() | RESTRICTION: Array variables, struct variables and objects cannot be used in a |
![]() | RESTRICTION: Parentheses are not allowed in a |
Embedded ST-Expression
<address>{<ST-Expression>}
The result of the ST-expression is used as the value of the word. It must be convertible to LReal. Basically, an ST-expression is ST-Code that could be placed on the right hand side of an assignment. Other ST-Code (e.g. an ST-statement) is not allowed. However, extensive computations can be encapsulated in an ST-function that is then called in the ST-expression.
![]() | An |
Example:
- The following GST-program starts with a line of
G-code that moves the tool rapidly to the origin. - The line is followed by a line of
ST-code that declares variable ‘i’. TheST-mode is entered by the prefixed exclamation mark (‘!’). After this lineG-code mode resumes. - The
G-code in line 3 moves the tool down. - Lines 4 to 8 define a block of
ST-code that contains aFOR-loop. The code in this block is interpreted asST-code, except for theG-code line in line 6. This line ofG-code uses aG-expression to set theX-axis to10*i. The value of theY-axis is defined using anST-expression that is enclosed in curly braces. This expression evaluates to0if ‘i’ is even and to10otherwise. - The programmed path of the program is shown in Figure “ExampleExpressions”.
G00 X0 Y0 Z0
! VAR i : INT; END_VAR
G01 Z-1 F6000
{
FOR i := 1 TO 5 DO
!G01 X=i*10 Y{ (i MOD 2) *10 }
END_FOR;
}
Figure “ExampleExpressions”.
Suppression of G-Code Blocks
/<n> <G-Code block>
The execution of a G-Code block can be suppressed conditionally. If ‘/<n>’ is prefixed and the n-th bit in an internal disable mask is set, the block is suppressed (not executed). The disable mask can be set by the PLC and by the ST-function disableMaskSet. If n is omitted, it has 0 value by default. [See section Suppression of G-Code Blocks.]
