G codes for CNC. Description of G and M codes for programming CNC machines CNC codes used in the program

Processing programming on modern CNC machines is carried out in a language usually called ISO 7-bit language, or G- and M-code language. Codes with address G, called preparatory codes, determine how the control system is configured for a specific type of work. Codes with address M are called auxiliary and are intended to control the operating modes of the machine.

For example, if the programmer wants the tool to move in a straight line, he uses G01. And if it is necessary to change the tool, then in the processing program he indicates M06.

A fairly large number of different codes are used to control the numerous functions of a CNC machine. However, by learning a set of basic G- and M-codes, you can easily create a control program.

In table Table 5.1 provides a list of the basic codes that we will look at in detail in this and subsequent chapters. And in the chapter “Directory of G- and M-codes” you will find a detailed description of all standard codes and examples of their use.

Table 5.1. Basic Processing Programming Codes

Code (function) Purpose and example of a frame with code
Axial movement
G00 Rapid traverse - moving at very high speed to a specified point
G00 X10. Y20. Z25.
G01 Linear interpolation – moving in a straight line at a specified feedrate
G01 X10. Y20. F100
G02 Circular interpolation - moving in a clockwise arc at a specified feed rate
G02 X10. Y20. R10. F100
G03 Circular interpolation - moving in a counterclockwise arc at a specified feed rate
G03 X10. Y20. R10. F100
Settings
G20 Entering inch data
G20 G00 X10. Y20
G21 Entering Metric Data
G21 G00 X10. Y20
G90 Absolute positioning - all coordinates are measured from a constant zero point
G90 G00 X10. Y20
G91 Relative positioning - all coordinates are measured from the previous position
G91 G00 X10. Y20
Hole machining
G81 Drilling cycle
G81 X10. Y20. Z-5. F30
G82 Drilling cycle with delay at the bottom of the hole
G82 X10. Y20. Z-5. R1. P2. F30
G83 Intermittent drilling cycle
G83 X10. Y20. Z-5. Q0.25 R1. F30
G85 Bore cycle
G85 X10. Y20. Z-5. F30
Auxiliary codes (functions)
M00 Programmed stop – program execution is temporarily stopped
M01 Programmed Selective Stop – Program execution is temporarily stopped when Selective Stop mode is activated
M03 Direct spindle rotation - the spindle rotates clockwise
M04 Reverse spindle rotation - the spindle rotates counterclockwise
M05 Spindle stop
M06 Automatic tool change
M06 T02
M08 Turning on the coolant supply
M09 Turning off the coolant supply
M30 End of program, move the cursor to the beginning of the program

Good afternoon, dear readers!

A program written using G-code has a rigid structure.

All control commands are combined into personnel- consisting of one or more commands.

The frame ends with a line feed character (CR/LF).

The order of commands in the frame is not strictly specified, but it is traditionally assumed that the preparatory commands are indicated first, then the movement commands, then the selection of processing modes and process commands.

In short, our PC via USB simply sends commands to the printer (microcontroller) port, and the printer executes them without hesitation.

Looking ahead a little, I will say that the G-code for a printer differs in some places from the usual G-code. Some commands were modified to suit the needs of the printer, some were removed, some are not used at all, but overall everything is very similar.

The description of the commands will be made for the MARLIN firmware, and it may work on other firmwares.

The most only the most basic commands (working minimum), in search of exotic ones, you can follow the link.

The teams themselves are divided into groups:

G- Preparatory (main) teams;

M- Auxiliary (technological) teams.

These commands have parameters.

X- Coordinate of the trajectory point along the X axis [ G0 X100 Y0 Z0]

Y- Coordinate of the trajectory point along the Y axis [ G0 X0 Y100 Z0]

Z- Coordinate of the trajectory point along the Z axis [ G0 X0 Y0 Z100]

E- Coordinate of the plastic extrusion point [ G1 E100 F100]

P- Command parameter [ M300 S5000 P280]

S- Command parameter [ G04 S15]

F- Command parameter, feed (speed) [ G1 Y10 X10 F1000]

G - commands

G0- Idling, no tool operation [ G 0 X 10]

G1- Coordinated movement along the X Y Z E axes [ G 1 X 10]

G4- Pause in seconds [ G4 S15]

G28- Home command - park the head [ G28 Y0 X0 Z0]

G90- Use absolute coordinates [ G90]

G91- Use relative coordinates [ G91]

G92- Set current set position [ G92]

Explanation:

Relative coordinates- these are coordinates relative to the current position of the head.

For example, if the head is in position X10 Y10, then when the command is given G91

G1 X10 F1000, the head will move 10 mm along the X axis at a speed of 1000.

This command can be done a lot of times, until the “software” limitation in the firmware is reached.

Absolute coordinates- these are coordinates strictly tied to the work area.

When executing the command G90 G1 X10 F1000- the head will move to coordinate X10 at a speed of 1000.

The command will only be executed one once.

Regular commands

M0- Pause and wait for a button to be pressed on LCD displays (works if the ULTRA_LCD parameter is set in the firmware) [ G0 X10 Y10 Z10 M0]

M17- Apply current to the motors (the motors do not rotate by hand)

M18- Remove current from the motors (motors can be rotated by hand, similar to M84)

M42- ARDUINO MEGA 2560 contact management [ M42 P4 S255]

M80- Turn on power, ATX only - power supply

M81- Turn off the power, only for ATX - power supply

M84- Turn off all axes (motors after inactivity) [ M84 S10]

M112- Emergency stop

M114- Get current coordinates

M115- Get the firmware version

M117- Write a message on the screen [ M117 Hello World]

M119- Get the status of limit switches

M300- Play sound [ M300 S5000 P280]

SD card commands

M21- Initialize SD card

M22- Use SD card

M23- Select a file from the SD card [ M23 filename.gcode]

M24- Start/resume printing from SD card

M25- Pause printing from SD card

M26- Set the position of the SD card in bytes [ M 26 S 12345]

M27- Find out the print status from the SD card

M28- Write file to SD card [ M 28 filename. gcode]

M29- Finish recording the file on the SD card

M30- Delete file from SD card [ M 30 filename. gcode]

M31- Get the value of how much time has passed since the last M109

M32- Select a file from the SD card and start printing [ M32/path/filename#]

M928- Logging to SD card [ M 928 filename. gcode]

Extruder

M82- Set the extruder to an absolute coordinate system

M83- Set the extruder to a relative coordinate system

M104- Waiting for the extruder to heat up to a certain temperature [ M104 S190]

M105- Get current extruder temperature [ M105 S2]

M106- Turn on the part blowing fan [ M106 S127] - power 50%

M107- Turning off the fan blowing the part [ M 107]

M109- Heat the extruder and hold the temperature [ M109 S215]

Table

M140- Set table temperature [ M140 S65]

M190- Heat the table and maintain the temperature [ M190 S60]

In Pronterface you can enable answer mode in the menu Settings / Debug communications, the program will write all responses from the printer.

You can add G-code to the file in slicers (Slic3r and Cura) at the beginning and end.

Or open the G-code file in Notepad and write everything by hand. =)

M190 S60- turn on the heating of the table and wait until it warms up to a temperature of 60 degrees

M109 S210- turn on the heating of the nozzle and wait until it heats up to a temperature of 210 degrees

G21- sets the metric coordinate system

G90- sets the absolute coordinate system

M82- sets the absolute coordinate system for the extruder

M107- turn off the blowing of the part

M300 S5000 P280- sound signal

G28 X0 Y0- Home X Y command

G28 Z0- Home Z team

G1 X100 Y100 Z5 F1000- center the nozzle relative to the table

G92 E0- resets the amount of extruded plastic

G1 F300 E4- extrude 4 mm of plastic at a speed of 300 mm

M117 Printing- displays a message on the screen

M106 S125- turn on the blowing of the part at a speed of 50%

G1 Z0- lower the nozzle to 0 mm

G1 X96.11 Y110.92 E87.55

G1 Z0.2- raise the nozzle by 0.2 mm

G1 X96.11 Y111.00 E89.60- go to the coordinates and squeeze out the plastic

M140 S50- change the table temperature

G1 Z4.8- raise the nozzle by 4.8 mm

G1 X96.11 Y110.92 E87.55- go to the coordinates and squeeze out the plastic

G1 Z5- raise the nozzle by 5 mm

G1 X96.11 Y111.00 E89.60- go to the coordinates and squeeze out the plastic

G91- sets the relative coordinate system

G1 E-5 F200- suction by extruder of 5 mm rod

M104 S0- turning off the extruder heating

M140 S0- turning off table heating

M107- turn off the blowing of the part

M84- turn off the stepper motors

M300 S5000 P280- sound signal

Thank you for your attention!

Programming of numerical control (CNC) systems is carried out using G-code.

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

Despite the general regulation, G-code has many implementations and additions, introduced mainly by developers of hardware devices of 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 frames, each frame containing a set of control commands.

Control commands can follow in a frame in any order, but usually, for the sake of ease of reading the control program of a numerical control system, the preparatory commands come first, then the commands to control the movement of the cutting tool, followed by the commands for selecting material processing modes, and the frame ends with technological commands.

The text of the control program begins and ends with the symbol “%”.
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 preceded by the symbol “;”.

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

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

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

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

Z - coordinate of the trajectory 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 speed (for example, S1500 M3),

R - standard cycle parameter or arc radius,

H - correction parameter of the selected tool,

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

Basic commands

G15 command - cancels the polar coordinate system.

Command G16 - assigning a polar coordinate system (X radius, Y angle).

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

G80 command - cancels cycles for drilling, boring, tapping, etc.

Command G81 - drilling cycle.

Command G82 - delayed drilling cycle.

Command G83 - intermittent drilling cycle (with the drill fully retracted).

Command G84 - thread cutting cycle.

G97 S (Speed) command - sets the spindle speed using an S word.

Main auxiliary (technological) teams

Command M03 - starts spindle rotation clockwise.

Command M04 - starts spindle rotation counterclockwise.

Command M05 - stops spindle rotation.

Command M06 - tool change.

Command M07 - enable additional cooling.

Command M08 - enable main cooling.

Command M09 - switch off cooling.

Command M13 - turns off cooling and spindle rotation clockwise.

Command M14 - turns off cooling and spindle rotation counterclockwise.

Command M17 - end of subroutine.

Command M25 - manual tool change.

Examples of various control programs for numerically controlled machines are presented

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

In pursuit of powerful post processors - CAM applications, machine operators do not notice an inexpensive, accessible and easy-to-use and learn software product. On all forums, there are a lot of questions for smart gurus - how to understand the settings of universal programs, scouring the Internet in search of hacked copies of expensive programs, for some reason we don’t think that it is easier to purchase an inexpensive software product honestly and legally, and what is important - and very effectively, apply it on your equipment.

Home hobby and homemade or retrofit CNC machines or construction machines are now becoming increasingly widespread. Everything is usually clear with the control program - it’s MACH, there are practically no alternatives. And with the choice of a post-processor, the home master usually has problems.

Consider using a CNC machine to create a simple bas-relief.

An inexpensive solution to the G-code issue for this purpose is the simple and convenient Bmp2Cnc program.

Bmp2Cnc creates a G-code control program (G-code programmer) from a halftone image. You can also upload a color photograph into the program: it is possible to convert a color image into a halftone one, but here we will use a ready-made black and white drawing as an example:

Let's look at working with the program step by step.

So, upload the image to the program. Change the size of the image to one that corresponds to the size of the future bas-relief. Enter the value 100 mm in the “Width” box and, if there is a bird in the checkbox below, the height of the picture changes with the same scale:

Next, choose zero. The easiest way is to take the lower left corner of the picture as the origin of the UE coordinates. Why? The convenience lies in the fact that the dimensions of the bas-relief will be displayed more clearly in the future in the Mach3 control program, and it will be easier to further manipulate the control program - scale the part, loop it, i.e. perform several identical treatments using one control program on one workpiece, and so on:

The most interesting moment comes. Now we will see the detail in volume. In the "Depth" section we set the depths for the white and black colors of the image. For our bas-relief measuring 100 by 100, set the depth for the darkest shade of black to first 10 mm, click the “Apply” button. A second later we see the resulting relief in the graphical visualization window:

Need more volume? Set the depth 15 mm. Now the part looks quite voluminous:

In the next bmp2cnc dialog, select the postprocessor suitable for our system - Mach2-3 in millimeters and p Let's move on to choosing a tool:

Selecting a suitable cutter with a sharp nose, which will process our part quite cleanly:

Choosing tool diameter- cutters and parallel passes, do not get carried away and set too high parameters - otherwise the processing will last for hours or even days! Here it is better to compromise, let the part turn out to be slightly rough; in the end, you will have to sand it in any case (since the original picture was of low quality), but the machine will perform the processing much faster:

The number of depth passes can be set to any number depending on the hardness of the material, the quality of the tool, etc.

Here in the sixth dialog of the program there is a very useful function, which, by the way, is implemented “with difficulty” in other venerable programs. By pressing one button, you can cut off the planes that are unnecessary for processing, thereby significantly shortening the processing time. We cut off the lower plane - and ours the model takes its final form:

Clicking the "Calculate" button- and we see the resulting processing trajectories. In a separate window there is a ready-made control program:

Next you can run simulation of processing. An animated cutter tool on the program screen will move along the trajectories created in Bmp2Cnc, providing us with an excellent visualization of the operation of the machine:

That's all. The G-code NC file can be sent to the machine, and the results of the work can be saved as a Bmp2Cnc project for subsequent access and changes, or as a Stl or Dxf model.

The finished G-code program is loaded into Mach3:

G code- name of the programming language for computer numerical control (CNC) systems.

The control program is a regular text file and consists of a sequence of frames and usually begins with the program start symbol (%) and ends with M02 or M30.

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

A control program block consists of statements in word form (G91, M30, X10., etc.). A word consists of a symbol (address) and a number representing an arithmetic value.

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

Words describing movement may have a (+) or (-) sign. If there is no sign, the displacement is considered positive.

Addresses I, J, K mean interpolation parameters.

G - preparatory function.

M - auxiliary function.

S - main movement function.

F - feed function.

T, D, H - tool functions.

Symbols may take on different meanings depending on the specific CNC.

Preparatory functions (G codes)

G00- fast positioning.

The G00 function is used to perform rapid movement of the cutting tool to a machining position or to a safe position. Rapid traverse is never used to perform machining, since the speed of movement of the machine's actuator is very high. Code G00 is canceled by codes: G01, G02, G03.

G01- linear interpolation.

Function G01 is used to perform linear movements at a given speed (F). During programming, the coordinates of the end point are specified in absolute values ​​(G90) or incremental values ​​(G91) with the corresponding movement addresses (for example, X, Y, Z). Code G01 is canceled by codes: G00, G02, G03.

G02- circular interpolation clockwise.

The GO2 function is designed to move the tool along an arc (circle) in a clockwise direction at a given speed (F). During programming, the coordinates of the end point are specified in absolute values ​​(G90) or incremental values ​​(G91) with the corresponding movement addresses (for example, X, Y, Z).

Code G02 is canceled by codes: G00, G01, G03.

G03- circular interpolation counterclockwise.

The GO3 function is designed to move the tool along an arc (circle) in a counterclockwise direction at a specified speed (F). During programming, the coordinates of the end point are specified in absolute values ​​(G90) or incremental values ​​(G91) with the corresponding movement addresses (for example, X, Y, Z).

The interpolation parameters I, J, K, which determine the coordinates of the center of the circular arc in the selected plane, are programmed in increments from the starting point to the center of the circle, in directions parallel to the X, Y, Z axes, respectively.

Code G03 is canceled by codes: G00, G01, G02.

G04- pause.

Function G04 is a command to perform a dwell with a specified time. This code is programmed along with an X or P address, which specifies the length of the dwell time. Typically, this time is from 0.001 to 99999.999 seconds. For example, G04 X2.5 - pause 2.5 seconds, G04 P1000 - pause 1 second.

G17- selection of the XY plane.

The G17 code is for selecting the XY plane as the working plane. The XY plane becomes dominant when using circular interpolation, coordinate system rotation, and canned drilling cycles.

G18- selection of the XZ plane.

The G18 code is for selecting the XZ plane as the working plane. The XZ plane becomes dominant when using circular interpolation, coordinate system rotation and canned drilling cycles.

G19- selection of the YZ plane.

The G19 code is for selecting the YZ plane as the working plane. The YZ plane becomes dominant when using circular interpolation, coordinate system rotation, and canned drilling cycles.

G20- input of inch data.

Function G20 activates the inch data mode.

G21- input of metric data.

Function G21 activates the metric data mode.

G40- Cancel tool radius compensation.

The G40 function overrides the automatic tool radius compensation G41 and G42.

G41- left tool radius compensation.

The G41 function is used to enable automatic compensation for the radius of the tool located to the left of the machined surface (when viewed from the tool in the direction of its movement relative to the workpiece). Programmable together with the tool function (D).

G42- right tool radius compensation.

The G42 function is used to enable automatic compensation for the radius of a tool located to the right of the surface being machined (when viewed from the tool in the direction of its movement relative to the workpiece). Programmable together with the tool function (D).

G43- correction for tool position.

Function G43 is used for tool length compensation. Programmable together with the tool function (H).

G52- local coordinate system.

The control system allows you to set, in addition to standard working coordinate systems (G54-G59), also local ones. When the machine's control system executes a G52 command, the origin of the current work coordinate system is shifted to the value specified by the data words X, Y and Z. The G52 code is automatically canceled by the G52 XO YO Z0 command.

G54 - G59- specified offset.

Offset of the working coordinate system of the part relative to the machine coordinate system.

G68- rotation of coordinates.

The G68 code allows you to rotate the coordinate system by a certain angle. To perform a rotation, you need to specify the plane of rotation, the center of rotation, and the angle of rotation. The plane of rotation is set using codes G17, G18 and G19. The center of rotation is set relative to the zero point of the active work coordinate system (G54 - G59). The rotation angle is specified using R. For example: G17 G68 X0. Y0. R120.

G69- cancel coordinate rotation.

The G69 code overrides the G68 coordinate rotation mode.

G73- high-speed intermittent drilling cycle.

The G73 cycle is designed for drilling holes. The movement during the machining process occurs at the working feed with periodic withdrawal of the tool. The movement to the starting position after processing occurs at an accelerated feed.

G74- left-hand thread cutting cycle.

The G74 cycle is designed for cutting left-handed threads with a tap. The movement during machining occurs at the working feed, the spindle rotates in a given direction. The movement to the starting position after processing occurs at the working feed with reverse rotation of the spindle.

G80- canceling the constant cycle.

A function that cancels any canned loop.

G81- standard drilling cycle.

The G81 cycle is designed for centering and drilling holes. Movement during processing occurs at the working feed. The movement to the starting position after processing occurs at an accelerated feed.

G82- holding drilling.

The G82 cycle is designed for drilling and countersinking holes. The movement during processing occurs at the working feed with a pause at the end. The movement to the starting position after processing occurs at an accelerated feed.

G83- intermittent drilling cycle.

The G83 cycle is designed for deep hole drilling. The movement during the machining process occurs at the working feed with periodic withdrawal of the tool into the retraction plane. The movement to the starting position after processing occurs at an accelerated feed.

G84- thread cutting cycle.

The G84 cycle is designed for tapping threads. The movement during machining occurs at the working feed, the spindle rotates in a given direction. The movement to the starting position after processing occurs at the working feed with reverse rotation of the spindle.

G85- standard boring cycle.

The G85 cycle is designed for reaming and boring holes. Movement during processing occurs at the working feed. The movement to the starting position after processing occurs at the working feed.

G86- boring cycle with spindle rotation stop.

The G86 cycle is designed for boring holes. Movement during processing occurs at the working feed. At the end of processing, the spindle stops. The movement to the starting position after processing occurs at an accelerated feed.

G87- boring cycle with manual retraction.

The G87 cycle is designed for boring holes. Movement during processing occurs at the working feed. At the end of processing, the spindle stops. The movement to the starting position after processing is done manually.

G90- absolute positioning mode.

In the absolute positioning mode G90, the movements of the actuators are made relative to the zero point of the working coordinate system G54-G59 (it is programmed where the tool should move). The G90 code is canceled by the G91 relative positioning code.

G91- relative positioning mode.

In the relative (incremental) positioning mode G91, the zero position is each time taken to be the position of the actuator, which it occupied before moving to the next reference point (it is programmed how much the tool should move). The G91 code is canceled by the G90 absolute positioning code.

G94- feed rate in inches/millimeters per minute.

Using the G94 function, the specified feedrate is set in inches per 1 minute (if the G20 function is in effect) or in millimeters per 1 minute (if the G21 function is in effect). Programmable together with the feed function (F). Code G94 is canceled by code G95.

G95- feed rate in inches/millimeters per revolution.

Using the G95 function, the specified feedrate is set in inches per 1 spindle revolution (if the G20 function is in effect) or in millimeters per 1 spindle revolution (if the G21 function is in effect). Those. Feedrate F is synchronized with spindle speed S. Code G95 is canceled by code G94.

G98- return to the original plane in a cycle.

When a machine canned cycle is run in conjunction with the G98 function, the tool returns to the home plane at the end of each cycle and between all holes being machined. The G98 function is canceled with G99.

G99- return to the retraction plane in a cycle.

If the machine's canned cycle is operated in conjunction with the G99 function, the tool returns to the retraction plane between all holes being machined. Function G99 is canceled with G98