G-codes for CNC machines: table with examples and training


18.03.2020
  1. What is CNC programming with G codes
  2. What is CNC G Code
  3. Methods for programming parts processing using GID codes for CNC
  4. Why you should learn CNC programming
  5. Standards and dialects of G-code for a CNC machine: examples
  6. What are the G and M CNC codes: description
  7. CNC preparatory G functions
  8. Decoding G-codes for CNC
  9. Additional functions and symbols for programming
  10. G-codes for CNC: table of preparation commands
  11. Table of basic G commands for CNC machines
  12. Table of auxiliary (technological) commands G and M code for CNC machines
  13. Command parameters specified in Latin letters
  14. Requirements for writing algorithms
  15. What G-codes look like for CNC: example of a control program for milling

We propose to find out how the trajectory of movement (and in general the sequence of actions) of high-performance metalworking equipment is set. Let's take a closer look at ready-made G-codes for CNC: with examples, operator training and other nuances that play a fairly important role. Maximum useful information - from possible methods and current standards to basic and preparatory functions, from definitions and terms, to the reasons why service personnel need to understand the issue.

Let's start with the fact that today they are used for all types of numerically controlled equipment, both professional and installed at the most critical facilities, and for amateurs. Taken together, they form a basic subset of the ISO 7 bit language, which allows you to set and control the processing modes of parts.

What is CNC programming with G codes

In fact, this is the task of specifying a certain sequence of commands that determine the nature of the movement of the cutting tool and gripping elements, the degree of fixation of the workpiece and other parameters. In terms of its role, this is a key part of the technological support for metalworking equipment installed in modern production facilities.

The written algorithm has a rigid structure and is a sequence of frames - groups of several commands. Each such block, united by a common function, has a serial number and is separated from subsequent and previous ones by a line feed (PS/LF symbol). This is done for clarity of the listing.

Development process

The development of control commands for CNC requires special skills and is carried out in several stages:

  • Obtaining information about the details and the production process;
  • Based on the drawings, creating a 3D model;
  • Creation of a set of commands;
  • Emulation and code correction;
  • Testing the finished product, manufacturing a prototype part.

Collecting information is the very first stage of creating a management program. It is necessary not only for writing control commands, but also for selecting a tool and taking into account the characteristics of the material when creating. First of all, it becomes clear:

  • The nature of the required surface of the part;
  • Material characteristics: density, melting point;
  • Allowance amount;
  • The need for grinding, cutting and other operations.

This will allow you to calculate the operations required for processing, as well as the working tools.

The next step is modeling the part. It is impossible to develop a program for creating parts of medium or more complexity without modeling. When creating standard products, you can search for ready-made models on the Internet, but you should carefully check them for compliance.

What is CNC G Code

This is a system of commands perceived by computer-controlled machines. It was created at the dawn of the 60s by the EIA (Electronic Industries Alliance) association, but it was finalized to a ready-to-use format (RS274D) only in 1980. Later, at the next meeting of the relevant committee, it was approved as the ISO 6983-1:1982 standard. In the Soviet Union, GOST 20999-83 was introduced to regulate its provisions, and ISO-7 bit began to denote it in the technical literature.

From that time to this day it has been widely used, both independently and as a basic subset for creating similar languages, and is constantly being improved and expanded.

Methods for programming parts processing using GID codes for CNC

There are 3 fundamentally different options - each with its own characteristics, pros, cons and specific application. Let's briefly look at each method from this trio, highlighting the main points.

Manual

The functioning algorithm is compiled in text format in an editor on a remote computer. After which it is transferred by the technologist to the equipment memory - recorded from an optical disk, a USB device (previously floppy disks were also used for this), and when directly connected to a PC - through the interface ports.

On the CNC console

In this case, commands are entered from a keyboard located on the rack. Each frame (block) is displayed on the display, and constant cycles can be presented in the form of icons (at the operator’s choice) - for convenience, to shorten the listing. The nuances depend on the features of the system, for example, the HEIDENHAIN or Fanuc interface is interactive, so the sequence of actions can be set intuitively.

Using CAD/CAM

CAD systems are rightly considered the most progressive method, as they help reduce time costs and protect against errors, which are especially common with complex algorithms. But to use them effectively, it is necessary to implement uniform electronic solutions for the entire production cycle, which is not always possible.

Today, G-codes are entered manually for a CNC lathe, and only when it is necessary to perform simple tasks, for example, to bore a hole or remove metal in two directions, that is, in situations where errors can be identified immediately. From the remote control you can set all the same and more complex transitions, with processing in 2.5 and 3 coordinates. It is a very suitable choice for mass production of template parts.

After creating a sketch in ADEM, MasterCAM or other popular CAD software, it is convenient to select equipment, tools and accessories, movement limits and the degree of correction in dialog mode. The possibilities for specifying a trajectory are as wide as possible, and with the current level of development of CAD/CAM, it will not be difficult to perform a virtual simulation of the technical process, immediately detect noticeable errors such as collisions, missed allowances, gouges, and eliminate them.

ArtCAM software

This set of products for modeling and designing products to be produced on CNC machines is used to enable automatic processing. The ArtCAM package includes tools for modeling products that make it possible to create complex spatial reliefs.

Let us note the following features of the ArtCAM package:

  • The ability to use 3D templates to create product designs from simple elements.
  • Function for automatically generating 3D models from 2D drawings.
  • A wide range of tools for creating and editing raster images and vectors, importing models and creating assemblies.
  • A wide database contains many processing strategies, allowing you to choose the optimal way to perform work of varying complexity.
  • Ability to program axial machining and create extrusion elements.
  • Using functions for editing ready-made volumetric models, you can create textures for grinding machines.

Among the areas of application of the ArtCAM package:

  • furniture manufacture,
  • shoe industry,
  • production of molds,
  • creation of plastic products.

PC requirements

Minimum requirements for ArtCam to work:

  • operating system: Windows 64-bit;
  • processor: no lower than Intel Core i5;
  • RAM: from 4 GB;
  • video card: RAM at least 1 GB, must support OpenGL 2.0;
  • graphic display: 1920×1200.

ArtCAM is a simple and accessible software even for users with basic skills.

Why you should learn CNC programming

The answer is obvious - to be able to write optimal algorithms for performing a specific technological operation. Simply understanding commands and using ready-made solutions is not always convenient - for the following reasons:

  • Standard options almost certainly do not take into account the specifics of production - in order to optimize they need to be adapted, and this is extremely difficult to do without knowledge of the ISO 7 bit language.
  • Methods are constantly being improved, so it is necessary to keep up with them, because the sequence of actions that was relevant a year ago may already be morally outdated today.
  • The process of managing the production of parts needs to be streamlined - by reducing the number of personnel, combining repetitive cycles and other ways to simplify listing, which can only be implemented by a well-versed operator.

Standards and dialects of G-code for a CNC machine: examples

The first steps to regulate the set of commands were taken by the already mentioned Electronics Industry Association (EIA) when it introduced RS-274. Over time, the set of rules was supplemented and expanded, becoming NIST RS-274NGC. Most of its provisions have been adopted into the current ISO 7 bit standard.

Dialects are branches of a language within which engineers have added their functions, focused on certain specific technical processes or helping to stand out positively among a number of competitors.

  • Fanuc, with its unification and ubiquity, is popular among professionals.
  • Mach3, due to its comparative simplicity and clarity of listing, is liked by amateurs and beginners.
  • Haas offers additional options when tasking the pocket milling algorithm.

And so on - there are many dialects, they differ in the levels of support and display, the nature of macro- and micro-operations, offset and formatting parameters, incremental and absolute coordinates.

What are the G and M CNC codes: description

First, let's determine what the difference is between them. The GI teams are the main and preparatory teams, the EM teams are auxiliary (technological). They are written down together, in a line (the first ones at the beginning, the second ones at the end) or, in other words, frame by frame - for clarity of listing. As a result, the algorithm is a collection of character blocks - with addresses and numeric values.

The tasks of the G-group include determining the linear or circular speed, as well as the direction of movement of the working tools of the equipment. In addition, they are required to regulate boring and threading, manage coordination and other features of additional equipment.

CNC programming M-codes are designed to complement the basic ones, simplifying the execution of the algorithm. In practice, their role is reduced to changing blades, drills (or other organs), calling and terminating subroutines.

Besides these two common families, there are also:

  • S-commands that determine the specifics of the main movement.
  • F, responsible for the nature of the feed.
  • D, H, T, expressing the key parameters of the hanging elements.

Therefore, it is extremely important for the operator to understand the variety of symbols presented, and the ability to read them line by line is generally implied - this is a necessary condition for monitoring the execution of technological operations.

Types of programs

When creating a program for machine tools, it is necessary to take into account a whole range of issues:

  • at what speed the spindle can operate;
  • at what speeds it can operate;
  • what productivity is the machine capable of working with;
  • how much the working tool can move;
  • how many tools the machine can use.

Most questions are related to the characteristics of the machine. To determine the necessary data, it is enough to use the instructions that come with the equipment when purchasing it. Some controlled machines may have additional functions. They also need to be taken into account when programming, otherwise processing may not be carried out accurately. A list of additional functions is also included in the instructions.

CNC preparatory G functions

They can set the speed of movement of the knife (guillotine) or the choice of cutting plane, but they are always written first in the block. After the obligatory letter - GI with symbols - there are coordinates presented as numerical values.

Depending on their purpose, they determine the position of the working body, perform switching, compensate for diameter and length, and determine the features of drilling, boring, threading (we will provide a complete list of compliance below). It is important that when compiling an algorithm in text format, they remain clear: with proper experience in reading the listing, it is not difficult for the operator to understand what each of them contains.

Decoding G-codes for CNC

There are quite a lot of basic functions, so let’s take a closer look at those that are most often used in practice, and these are:

  • G00 – for high-speed positioning and quickly bringing the tool to the ready/safe position;
  • G01-03 – for movement of the working body either in a straight line or in an arc, clockwise and counterclockwise, respectively; additional symbols – I, J and K – in this case set the coordinates;
  • G04 – to provide a break in the operation of the blade (drill, etc.), lasting 1 second (standard option) or longer, depending on the values ​​of the X or P field;
  • G17 CNC code is needed to determine the main plane - it is used to select XY coordinates when performing rotational actions when making technological holes;
  • G18-19 – do the same thing, only in XZ and YZ plans, respectively, relevant for circular interpolation;
  • G20 - for taking measurements in inches, needed when determining indicators not presented in the SI system; G21, on the other hand, is required for metric calculations;
  • G40 – to change auto-correction to the radius set by G41 (to the left of the workpiece, with an additional D-command) or G42 (similarly, but to the right);
  • G43 CNC code adjusts the position of the cutter (or other organ), compensating for its length, supplemented by the H parameter;
  • G52 enters local coordinates, G53 provides switching - to them and back;
  • G54-59 are responsible for the tool displacement relative to the fixed workpieces; depending on which one is in the listing, you can understand which part is being affected;
  • G64 activates the cutting mode and cancels any others;
  • G71 - turns on the hole drilling option, G73 does the same, but with a high speed condition, G74 starts the left-hand thread cutting process, G81-83 - drilling operation, G85-87 - boring cycles;
  • G97 CNC code determines the number of revolutions made per unit of time (usually per minute).

Of course, there are others, less applicable, but still necessary and used. In the process of writing an algorithm, the engineer groups them into groups, forcing them to interact with each other and/or change each other. The overall rationality of the listing, and therefore the performance of technical operations, depends on the effectiveness of the combinations.

How to write CNC programs

There are two options: automatically create a program from a part layout or write it from scratch.

Most often they use the first option - first they draw on the part in 3D (there is special software for this), and then the program itself generates the necessary code for the machine to produce the drawn part. The disadvantage of this approach is that the code may turn out to be suboptimal: it will take too long to execute or a lot of waste will be generated in the process.

How does a 3D printer work?


A three-dimensional model of the part, on the basis of which the code for the machine will be generated.

The second approach is to write the program manually from scratch. To do this, you need to know perfectly all the parameters of the machine and the possible states of each sensor. It's more complicated, but it gives you more control over how the part is made.

In practice, they usually do this: they draw a three-dimensional model, upload the CNC code based on it, and then modify it, if required.


The program generated a code for the machine, which can be immediately corrected if necessary.

G-codes for CNC: table of preparation commands

Symbol Description
G00-04 setting the tool in position
G17-19 switching between planes – XY, XZ and YZ, respectively
G20-21 calculations in English (inch) or metric measurement systems
G40-44 compensation of length, diameter, dimensions of the working body
G53-59 transition from one coordinates to others
G80-84 activation of drilling or threading cycles
G90-92 switching from absolute to relative coordinates and vice versa

Now let's move on to those functions that are used most often, we have already examined them in detail, now, for clarity and better memorization, briefly.

SprutCAM program

SprutCAM is software from a Russian manufacturer. It is used to create control software that is used in the process of processing parts on CNC machines and machining centers. The system has wide customization capabilities for any type of controlled devices; it is compatible with machines that have different kinematic schemes.

SprutCAM includes the most complete set of tools for effective work in various areas of production. The software has a wide range of processing strategies, a basic set of post-processes, a built-in processing simulation module and a rich library that stores kinematic diagrams of machine tools. The Add-on Wizard allows integration with CAD systems for direct data exchange.

Table of basic G commands for CNC machines

Symbol Description
G00 moving the tool at idle speed with acceleration
Specifying interpolation
G01 linear
G02 circular clockwise
G03 in the opposite direction to the previous one (against)
G04 enable delay (in milliseconds)
G10 setting new starting points
G11 cancellation
G15
G16 working in a polar coordinate system
Measurement mode
G20 in inches
G21 in meters
G22 activation of machine stop frames – movement limits
G23 cancellation
G28 return to reference point
G30 Z-axis movement up
Compensation for the dimensions of the working body
G40 cancel (for sizes)
G41 radius left
G42 radius to the right
G43 heights are positive
G44 heights negative
G53 transition to equipment coordinates
G54-59 switching to operator-specified values
G68 turn at the desired angle
G69 cancellation
Drilling cycle
G80 refusal
G81 inclusion
G82 delayed
G83 with departure
G84 threading
Activating the coordinate system
G90 absolute
G91 relative
Feed Format F
G94 mm/min
G95 mm/rev
G98 cancellation
G99 refusal to return to the “approach” point after completing the cycle

Table of auxiliary (technological) commands G and M code for CNC machines

Symbol Description
M00 stop before pressing "start"
M01 similar to the previous one, but subject to confirmation mode
M02 completion of the algorithm
Start of spindle rotation
M03 clockwise
M04 against
M05 stop
M06 change of working body
M07 activation of additional cooling
Main cooling
M08 inclusion
M09 shutdown
M30 end of data output
M98 start of subroutine
M99 its completion, return to the main algorithm

Now you see how, for example, G49, G94 and G99 CNC codes differ from each other, but there are also functions with other letters. What are they doing? We suggest you look into this issue.

Example No. 2 of programming G02 G03 on a lathe


Example No. 2 of programming G02 G03 on a lathe

N20 G50 S2000 T0300 G96 S200 M03 G42 G00 X35.0 Z5.0 T0303 M08 G01 Z-20.0 F0.2 G02 X67.0 Z-36.0 R16.0 G01 X68.0 : G03 X100.0 Z-52.0 R16.0 G01 Z-82.0 G40 G00 X200.0 Z200.0 M09 T0300 M30

G code G02 G03 Example I&K program

G02 G03 G-code cyclic interpolation can be programmed in two ways:

G02 X … Z … R … G02 X … Z … I … K …

Below is the same CNC program but this version uses I&K with code G02 G03

N20 G50 S2000 T0300 G96 S200 M03 G42 G00 X35.0 Z5.0 T0303 M08 G01 Z-20.0 F0.2 G02 X67.0 Z-36.0 I16.0 K0 G01 X68.0 : G03 X100.0 Z-52.0 I0 K- 16.0 G01 Z-82.0 G40 G00 X200.0 Z200.0 M09 T0300 M30

Command parameters specified in Latin letters

Symbol Description
Coordinates of points along the corresponding axes
X
Y
Z
Speed
F working feed
S spindle rotation
R radius (or, less commonly, standard cycle indicator)
I, J, K dimensions of the arc observed in the case of circular interpolation
D correction of the current tool
P delay (or number of subloop calls)
L subroutine by label

Requirements for writing algorithms

They must be clearly structured and divided into frames, each of which must end with a CR/LF separator. At the end you need to put M02 or M30. Associated comments are left in parentheses, either immediately after the characters or on a separate line. The same functions can be repeated in any chosen sequence and any number of times, if this is a rational decision.

If the algorithm generates CAD, the operator needs to control the result. To do this, he needs to know the dimensions of the part, the thickness of the removal layer, the parameters of the cutter, and the depth of insertion of the blade.

What G-codes look like for CNC: example of a control program for milling

We invite you to see what listing is like when processing workpieces of the simplest forms. Let's say we have a circle and a triangle.

Then in the first case, our set of functions will look like this (we present it line by line, with explanations):

  • O001 (Circle) serial number and name (can also be written in transliteration).
  • G00 Z0.5 Sets the safe height of the tool.
  • G00 X-80 Y0 the organ moves to the processing starting point.
  • G01 Z-2 F60 the blade cuts to the proper depth (2 mm).
  • G02 I10 F80 Circular metal removal occurs.
  • G00 Z0.5 The tool is raised again.
  • G00 X0 Y0 return to the starting position.
  • M30 end of the program.

In the second case, with a triangle, the listing will look like this:

  • O002 (Triangle) number and name - everything is as simple as possible here.
  • G00 Z0.5 F70 installation of the working element at a safe height.
  • G00 X20 Y30 moves to the starting point of the operation.
  • G01 Z-3 F60 cutting the blade to the required depth (3 mm).
  • G01 X20 Y150 F60 – passage along the first leg.
  • G01 X110 Y30 – processing of the hypotenuse.
  • G01 X20 Y30 – passage along the second leg.
  • G00 Z0.5 – the cutter returns to a safe height.
  • G00 X0 Y0 – return to the initial position.
  • M30 – completion of the algorithm.

We looked in detail at G-codes for CNC milling machines, and for the machines themselves, start mastering programming. Well, the equipment, modern and reliable, into the memory of which you can enter any written program, is already ready to be sold by its direct manufacturer - Izhevsk.

Features of machine programming

Unlike a computer, where a new and empty area of ​​memory is allocated for each program and variable, everything is different in machine tools. The fact is that the program at the time of launch does not know what position the cutters are in, whether the guides are secured, and so on. If you simply run the program without preparation, the CNC, for example, can move the cutter even further to the left, which is already in the very left position, and then the drive or the cutter mount may break.

To prevent this from happening, before each launch, zeroing and initialization commands are built into the program so that each element is returned to its original position. This is better than just checking what is where - after zeroing, we will know for sure that all elements of the machine are in a position known to us and the program will be able to work with them correctly.

It is also important to understand that machines work with living material: metal, wood, acrylic, stone, etc. The material is imperfect, may have internal defects, and may melt and crack. Cutters and spindles are also made of some materials that have thresholds for heating, strength and speed. If you make a mistake in the computer code and cause a memory overflow, the computer will simply freeze. You reboot it, and that's it. And the machine can break the cutter or damage the spindle. And this farm is worth it, be healthy.

Rating
( 1 rating, average 5 out of 5 )
Did you like the article? Share with friends:
For any suggestions regarding the site: [email protected]
For any suggestions regarding the site: [email protected]
Для любых предложений по сайту: [email protected]