Decoding of the cnc program. Description of G-codes. What is G-code

Codes denoted by the letter M are called auxiliary and are designed to control the operating modes of the machine. The M code can be either separately or in a block with G codes. Some M codes work in conjunction with other addresses. For example, the M code, which is responsible for the direction of rotation of the spindle, is usually indicated with the address S, which is required to set the number of its revolutions during rotation. The order of execution of commands and actions when M and G codes are in the block depends on the CNC model. Some CNC systems allow only one M code to be specified per block.

Table 1 - Basic M codes

Stop the execution of the control program - M00 and M01.Very often there are situations when it is necessary to temporarily interrupt the execution of the program. For example, to remove chips, check the dimensions of the work piece, or move fasteners to a different position.

Codes M00 and M01 temporarily suspend the execution of the part program or, in other words, pause in the production cycle of the machine. When the TNC reads the M00 code, a so-called programmed stop occurs. All axial movements stop and resume only after the machine operator presses the "Cycle start" key on the CNC control panel. In this case, the spindle continues to rotate and other functions remain active. If the machine operator presses the "Cycle start" key, the program execution will continue from the block following M00.

N40 M05 / Spindle stop

N50 M00 / Stop the execution of the control program

N60 M03 S1000 / Switch on spindle 1000 rpm

Code M01 is for optional stop. It acts similarly to the M00 code, however, it gives the operator a choice whether or not the execution of the control program should be interrupted. On the CNC panel of almost any machine there is a key (or switch) "M01". If this key is pressed, then when reading a block with M01, a stop occurs. If the key is not pressed, then the M01 command is skipped and the NC execution is not interrupted.



Spindle rotation control - М0З, М04, М05. Auxiliary codes M03 and M04 are designed to control the rotation of the spindle. The M03 code is responsible for the forward (clockwise), and M04 - for the reverse rotation of the spindle (counterclockwise). The direction of rotation is determined by looking in the negative direction of the Z axis (from the spindle towards the workpiece). When milling, the cutting tools must have a forward rotation (M03). When removing the tap from the hole, when cutting left-hand threads, in the cycles of automatic measurement of the tool diameter, reverse rotation of the spindle (M04) may be required. At the end of the machining program and before changing the tool, the spindle rotation must be stopped with the M05 command.

Figure 1 - Forward and reverse rotation of the spindle

The S address is used to set the spindle speed. S is followed by a numerical value that expresses the spindle speed in revolutions per minute. Most control systems only accept the S integer value. Usually the M03 and S codes are in the same block.

Controlling the supply of lubricating and cooling liquid - M07, M08, M09. During the milling process, coolant is supplied to the machining zone to increase tool life, improve the quality of the machined surface and remove (wash out) chips. CNC machines are equipped with an automatic coolant supply system. This system is controlled by several M codes. Typically, M08 is used to turn on the coolant supply and M09 to turn off. Some machines allow different types of coolant to be supplied to the processing area. For example, code M08 can cause coolant to be sprayed, while code M07 can be sprayed.

It is customary to turn off the coolant supply before changing the tool and at the end of the machining program. Many modern machines do this automatically when reading the M06 code (tool change), M30 and M02 codes (end of program). In addition to the programmed control of the automatic coolant supply system, there is also a manual control, which allows the machine operator, using certain keys on the CNC panel, to turn on or off the coolant supply if necessary.

Typically, the following command is specified in the program to perform an automatic tool change:

Address T indicates the number of the called tool (in this case tool # 1), and M06 provides the change. Most control systems allow any order of the data words in the tool change block.

Completion of the program - M30 and M02. At the end of any control program, there must be a code for its completion - M30 or M02. When any of these codes are executed, the machine will stop regardless of what function it was performing. The only difference between M30 and M02 is that at the end of the machining program with M30, the cursor of the current position is moved to the very beginning of the program, and with M02 it remains at the end.

Typically, at the end of a machining program, the work table or tool is moved to a position that makes it easier for the operator to remove the finished part from the machine. This movement is accomplished using the home return code G74.

There is a special language for CNC machine tools. This language is called ISO 7 bit. The system of G codes for CNC is a special command for the operation of milling and lathes with a control panel, special parameters are set in the commands. CNC programming is taught in technical colleges or in additional education courses.

What is G-code

The code system for turning is a special group of commands that are recognized by machines with programmed control functions. The code system was developed by Electronic Industries Allience in 1960 and refined in 1980. Since 1982, it has been operating in Russia. The code language is part of the structure of the foundations of programming, it is constantly being improved and changed.

What are G-codes

G-code programs are written in text format, each line is called a block. A frame consists of an alphabetic character - this is an address and a digit in which a numerical value is expressed. Codes are main and auxiliary. On the basis of such a program, a CNC lathe and milling machine works.

Group G teams are called preparatory. They set the movement of working elements on the machine at a certain speed. The speed can be circular or linear. Also G-code is used for hole and thread machining. Another function is to control the parameters and coordinate systems of the equipment.

The main commands of the program are aimed at performing the following functions:

  • G00 - G04 positioning function;
  • G17 - G19 switch operating parameters;
  • G40 - G44 compensation of length and diameter of various elements of the device;
  • G54 - G59 coordinate systems switching;
  • G71 - hole machining function;
  • G80 - G84 tapping and drilling function;
  • G90 - G92 toggle between absolute and relative coordinate systems.

Symbols are different: M performs auxiliary functions, such a command is necessary for changing the tool, calling a subroutine and its completion, S is the function of the main movement, F is the feed, T, D, H are the expression of tool functions.

The meaning of the symbol depends on the type of CNC machine. Programming is carried out based on these codes.

Preparatory functions

The preparatory functions in the code system are expressed by the symbol G. Each code has a specific meaning. All preparatory commands, such as the selection of the work plane or the selection of the traversing speed, are specified first in the program. A specific function is encrypted in the code. Parameters are set by numeric values.

Deciphering the main G codes for CNC

Let's move on to considering how the basic G codes for machines with PU are decoded.

G00

Specifies speed positioning. It is used when you need to quickly move the cutting tool to a ready state to start work or place it in a safe position. The accelerated version is not used in the processing of parts, since the speed that develops in this case is very high. This command can be canceled with the command G01, G02, G03.

G01

Represents linear interpolation. Such a command is necessary to move the tool in a straight line, the speed is specified by the F symbol. The function can be canceled by codes G00, G02, G03. Example of command recording: G01 X20 Y150 F60.

G02

Sets the clockwise movement, the cutting tool starts to move along an arcuate path, the speed is set by the F symbol. Parameters in the coordinate plane are also set. Symbols I, J, K - defining the coordinates of the arc in the plane. Cancellation is carried out by codes G00, G01, G03.

G03

This movement is counterclockwise in an arc at a given speed.

G04

Ask a break from work. the duration of the pause is set by the X or P symbol. The pause usually lasts about one second.

G17

Specifies the plane. XY coordinates are selected with the G17 code. This function is essential for rotating movements and the drilling process.

G18

Specifies a plane in XZ coordinates, this plane becomes the work plane during circular interpolation, rotary movements, and drilling.

G19

Allows you to select the working area in YZ coordinates. This function is required for tool movement in circular interpolation and canned cycle for drilling.

G20

Allows you to enter data in inch measurements. The function is designed to work with inch values.

G21

Allows you to work with metric indicators. It is required when working with data expressed in meters.

G40

Cancels the automatic tool radius compensation function specified by G41 and G42.

G41

Turns on automatic correction for the radius of the tool, which is located to the left of the workpiece relative to its movement. The program also includes function D.

G42

Similar to the G41 code, it is intended for automatic correction to the radius located to the right of the workpiece. The program is also set with function D.

G43

Needed to compensate for the length of the tool, corrects its position and is set together with the tool function H.

G52

Specifies local coordinate parameters in addition to standard parameters.

G53

Allows you to switch to the work machine coordinate system.

G54 - G59

A given displacement of the working element is carried out relative to the coordinate parameters of the machine. Using codes G54, G55, G56, G57, G58, G59, it is possible to determine in which coordinate system the work will be performed. By changing the codes, the programmer is able to process various details.

If any coordinate system was specified by codes G54 - G59, then it will remain in effect until it is canceled and other parameters are entered.

G64

This is the cutting mode, and other functions are automatically canceled.

G68

The rotation of coordinates is set, the command allows you to shift the coordinate system at a certain angle. The plane of rotation, center and angle of rotation are set by commands G17, G18, G19, R. Command G69 cancels this function.

G71

Allows you to make holes in products.

G73

This is the function of high speed hole drilling.

G74

Used for left-hand threading.

G81, G82, G83

Used for drilling cycle: standard, dwell and intermittent.

G85 - G87

Allows for different boring cycles.

G92

Allows to set absolute position accumulators.

G97

Sets the parameters of revolutions produced in one minute.

All codes interact with each other and form a separate group. In the program system, one function is replaced by another. An example of a code program can be found on the Internet. The code table must be visible during programming.

Requirements for writing a program

Programs that are written for a CNC machine based on the use of G-codes have a certain, completely clear structure, which consists of several commands. All commands for working with the machine are combined into groups - blocks. The end of one block is marked with CR / LF, the program ends with the auxiliary code M02 or M30.

If it is necessary to make a comment to the program, then it is placed in parentheses. For example, (move to the milling start point). The comment can appear immediately after the code, but you can also put it on a separate line.

One and the same command can be repeated several times, a specified number of times in a specific sequence. The program is written using main and auxiliary functions. It is read by turning and milling machines.

Special programs are involved in generating codes for working at the machine in production. At every enterprise, such a system operates smoothly and is controlled by the operator. If necessary, any program can be generated independently using special software that can be downloaded on the Internet.

No special knowledge is required for this, it is enough to have an idea of \u200b\u200bthe Cartesian coordinate system, to know the physical quantities and definitions from the geometry course. As an example, you can use a ready-made program. For work, you will need tables with decoding codes.

To create the code, you must have the following knowledge:

  • introduction of geometric parameters and dimensions of the workpiece;
  • know the parameters of tools and devices with which the work is carried out;
  • the thickness of the layer to be removed;
  • the depth of insertion of the slotting tool.

In practice, such actions are easy to perform. In order to understand how the system works, you can see an example of command recording, you will also need an auxiliary table with codes.

There are special services that allow you to create programs for machine tools online, they can be generated using a ready-made example. You don't need to install any additional software on your computer. All you need is Internet access. When programming, special care is required, if you make a mistake in maintaining a numerical reading, you can damage the part or break the machines. Programs created in this way can be used on turning, milling, plasma machines and processing a wide variety of materials.

M00 - programmed stop. When the control system executes the M00 command, a so-called programmed stop occurs. All axial movements stop and resume only after the machine operator presses the Cycle start button on the CNC panel. In this case, the spindle continues to rotate (on most machines) and other functions remain active. If the machine operator presses the Cycle start key, the program execution will continue from the block following M00.

M01 - optional stop. Code M01 is for optional stop. It acts similarly to the M00 code, however, it provides the operator with a choice - whether or not it is necessary to interrupt the execution of the control program. On the CNC panel of almost any machine there is a key (or switch) M01. If this key is pressed, then when reading a block with M01, a stop occurs. If the key is not pressed, then the M01 block is skipped and the NC execution is not interrupted.

M02 - end of the program. The M02 code informs the control about the end of the program.

M03 - direct spindle rotation. The M03 code enables direct (clockwise) rotation of the spindle at the programmed speed (S-word). The M03 command remains valid until it is canceled with M04 or M05.

M04 - reverse spindle rotation. With the M04 code, reverse (counterclockwise) rotation of the spindle with the programmed speed (S word) is enabled. The M04 command remains valid until it is canceled with M03 or M05.

M05 - spindle stop. The M05 command stops the spindle rotation, but does not stop the axial movements (except for the G95 mode).

M06 - automatic tool change. With the M06 command, the tool fixed in the spindle is changed to a tool in the standby position in the tool magazine.

M07 - switching on the sprayed coolant supply. The M07 command turns on the sprayed coolant supply to the machining zone, if the machine has this capability.

M08 - enable coolant supply. Command M08 turns on the supply of coolant to the treatment area in the form of a jet.

M09 - shutdown of coolant supply. The M09 command turns off the coolant supply and cancels the M07 and M08 commands.

M19 - spindle alignment. The M19 command is used to radially align the spindle (turn to a specific position) to bring the driven spindle nose to the tool change position. In this position, the spindle is usually clamped and cannot be turned by hand.

M20 - cancel spindle alignment. The M20 command cancels the M19 spindle alignment command.

M30 - end of the program. The M30 code informs the control about the end of the program.

M98 - subroutine call. The M98 command is designed to call a subroutine. Together with this command, a P-data word is programmed, which designates the number of the called subroutine.

Example:
М98 P1001 - call subroutine O1001.

M99 is the end of the subroutine. At the end of the subroutine, the M99 command returns to the main program from which the subroutine was called.

A NC program for a machine tool consists of a sequence of blocks and usually begins with the start of program (%) character and ends with M02 or M30.

Each block of the program represents one machining step and (depending on the CNC) can start with a block number (N1 ... N10, etc.) and end with the end of block (;) character.

The NC block is made up of statements in the form of words (G91, M30, X10. Etc.). A word consists of a character (address) and a digit representing the arithmetic value.

The addresses X, Y, Z, U, V, W, P, Q, R, A, B, C, D, E are dimensional movements, used to indicate the coordinate axes along which movements are carried out.

Movement words can have a (+) or (-) sign. In the absence of a sign, the movement is considered positive.

Addresses I, J, K stand for interpolation parameters.

G is a preparatory function.

M is an auxiliary function.

S is the main movement function.

F - feed function.

T, D, H - tool functions.

The symbols can take on different meanings depending on the specific CNC unit.

Preparatory functions (G codes)

The G-code is executed for execution in the machine control programs

Numerical control (CNC) systems are programmed using the G-code.

G-code is the general name of the programming language regulated by the ISO 6983-1: 1982 standard, the GOST 20999-83 standard.
In the technical literature of the Soviet Union, the G-code is referred to as the ISO 7-bit code (ISO 7-bit).

Despite the general regulation, G-code has many implementations and additions, introduced mainly by the developers of hardware devices for numerical control systems, which nevertheless does not prevent it from remaining the main standard in the industry.

In general, a program written using G-code consists of blocks, each block contains a set of control commands.

Control commands can follow in the block in any order, but usually, for the sake of ease of reading the control program of the numerical control system, first there are preparatory commands, then commands for controlling the movement of the cutting tool, followed by commands for selecting material processing modes, and ending the block - technological commands.

The text of the control program begins and ends with a "%" character.
This may be followed by the name of the program after the "O" symbol.
Comments in the text of the control program are placed either in parentheses or are preceded by the ";" symbol.

Each control command can have one or several parameters, which are designated by letters of the Latin alphabet.

The G-code allows you to use the following basic parameters for control commands:

X - the coordinate of the trajectory point along the X axis (for example,),

Y - the coordinate of the trajectory point along the Y axis (for example,),

Z - the coordinate of the path point along the Z axis (for example, G01 X25.4 Y2.3 Z0.2),

P - parameter (for example, P120),

(for example, G01 X10.5 F75),

S - spindle rotation speed (for example, S1500 M3),

R - canned cycle parameter or arc radius,

H - offset parameter of the selected tool,

I, J, K - arc parameters for circular interpolation (for example,).

Basic commands

G15 command cancels polar coordinate system.

G16 command - assignment of a polar coordinate system (X radius, Y angle).

G54-G59 commands - switching to the coordinate system specified by the operator.

The G80 command cancels the drilling, boring, tapping, etc. cycles.

The G81 command is a drilling cycle.

Command G82 - dwell drilling cycle.

The G83 command is an intermittent drilling cycle (full retraction).

The G84 command is a threading cycle.

G97 S (speed) command - Specifies the spindle speed using the S word.

Main auxiliary (technological) commands

Command M03 - start spindle clockwise rotation.

Command M04 - start counterclockwise spindle rotation.

Command M05 - stop the spindle rotation.

Command M06 - Tool Change.

Command M07 - enable additional cooling.

Command M08 - turn on the main cooling.

Command M09 - turn off cooling.

Command M13 - turn off cooling and clockwise spindle rotation.

Command M14 - turn off cooling and counterclockwise rotation of the spindle.

Command M17 - end of subroutine.

Command M25 - Manual Tool Change.

Examples of various NC programs for machine tools with numerical control are presented

When writing and debugging control programs for machine tools with numerical control, you can use an application that automatically creates control programs for machines with CNC systems after entering all the necessary parameters and geometric dimensions.