Updated on: 18.05.2022
Subject area
CNC programming
G-Code
In the world of CNC machine tool programming, G-code or G-functions are of particular importance. In this article you will learn everything you need to know about G-code.
Manual CNC programming
In modern CNC programming, machining programmes are often created with the help of CAM software (Computer Aided Manufacturing). Starting from the 3D model of the workpiece, a machining sequence is created using predefined procedures and translated into a machine-specific NC programme. Even though the software takes over many programming tasks, a basic understanding of manual CNC programming facilitates the optimal design of the machining process. In manual programming, all motion sequences and machining parameters are described line by line in the form of individual command blocks.
What is the G-code or a G-function?
Within a CNC programme, the G functions determine which calculation logic is to be used for determining the tool path. The G-code thus determines how the machine axes are to be moved. For complex component geometries, several G codes often have to be combined in order to realise the desired movement sequence. As with other NC commands, the G code is a standardised function block that is called with the address letter "G". In this case, the G stands for Go and precedes all preparatory path conditions. Preparatory because the G commands precede the coordinate commands in a programming line. The term G code is also used synonymously in many cases for a manually created CNC programme.
Functions of the G-code
Even though different manufacturers provide additional or modified control commands, the basic structure is identical. The address letter G is followed by a two-digit number. This is used, among other things, to determine the type of interpolation, the direction of the tool radius compensation, the path dimension input or defines the cycle. A typical NC program is structured in blocks and is executed block by block from left to right or from top to bottom.
Structure of the G-code
Like every command set, G functions also begin with a set number with the address designation N. This is then followed by the actual G command for defining the path movement with which the coordinates named afterwards are approached.
...
N30 G03 G17 X165 Y70 R100 F150 $
...
Set no. 30 - Movement on circular path (radius: 100 mm) counterclockwise with a feed rate of 150 mm/min.
G-code commands and instructions
The following table provides an overview of all G commands according to DIN 66025.
G-Code | Function |
---|---|
G00 | Positioning in rapid traverse (point control) |
G01 | Linear interpolation |
G02 | Circular interpolation (clockwise) |
G03 | Circular interpolation (counterclockwise) |
G04 | Dwell time |
G06 | Interpolation on a parabolic path |
G09 | Exacthalt |
G17 | Selection of the machining plane X - Y |
G18 | Selection of the machining plane X - Z |
G19 | Selection of the working plane Y - Z |
G33 | Thread cutting with constant pitch |
G34 | Thread cutting with increasing pitch |
G35 | Thread cutting with decreasing pitch |
G40 | Reset all recalled tool offsets |
G41 | Tool radius compensation (in feed direction left) |
G42 | Tool radius compensation (in feed direction right) |
G43 | Tool correction (positive) |
G44 | Tool correction (negative) |
G53 | Resetting the zero offset |
G54 - G59 | Zero offset 1 - 6 |
G60 | Entry tolerance 1 |
G61 | Entry tolerance 2 |
G63 | Maximum feed |
G70 | Dimension input [inch] |
G71 | Dimension input [mm] |
G80 | Resetting the recalled cycles |
G81 - G89 | Drilling cycles |
G90 | Absolute dimension input in relation to the current coordinate system (reference dimension) |
G91 | Relative dimension input in relation to the current coordinate system (incremental dimension) |
G92 | Shifting the reference point - Set memory |
G94 | Feed rate [mm/min] |
G95 | Feed [mm/rev] |
G96 | Constant cutting speed |
G97 | Spindle speed [1/min] |
G-code types
Basically, 3 types of G-commands can be distinguished, which in turn are divided into different function groups. It is important to remember that G-codes from one function group overwrite each other.
Zero offset with G-code
The zero point is the essential reference value in an NC program. Depending on the workpiece and machining task, it may make sense to define a new reference point for the following machining steps. Especially if programme components (e.g. drilling patterns) are to be reused at another point, a zero point shift is essential. The G commands G54 - G59 can therefore be preset with different values in the control and called up in the programme.