Numerical control technology is the core of numerical control machine. The control program contribute much for Numerical control technology. G code and M code are the main components of the control program. In this article, we will help you get a comprehensive understanding of G & M codes in the CNC machining process.
What is G-code?
G code is one of the most commonly used programming languages in CNC machine tools, which can control the movement of the tool and the machining path. G code is often used to control simple lines, arcs, etc.
What is M-code?
M code is a programming language used in CNC machine to control the auxiliary functions of the machine tool, such as tool change, lubricating oil pump switch, etc. M codes are often used to control actions such as stopping, starting, and repeating.
The combination of M code and G code can create complex parts by CNC machining. When writing M code, it is necessary to note that different brands and models of CNC machines may have different code specifications and compatibility issues.
Definition of the letters In CNC programming
- O: Program number
- N: program sequence number
- G: Preparatory function
- X/Y/Z: Dimension characters, axis movement command
- A/B/C/U/V/W: Additional axis movement command
- R: Radius of arc
- I/J/K: Center coordinates of arc (vector)
- F: Feed rate
- S: Spindle speed
- T: setting tool number
- M: control function on/off
- H/D: setting tool offset number
- P/X: setting dwell time
- P: setting subprogram number (e.g., subprogram call: M98 P1000)
- L: Loop, setting subprogram or fixed loop repetition count (e.g., M98 P1000 L2, omitting L represents L1)
- P/W/R/Q: parameters used for fixed cycles (e.g., threading G98/(G99) G84 X_ Y_ R_ Z_ P_ F_)”
How does G-codes work?
Format: G00 X(U)Z(W)
- The instruction makes the tool move quickly to the specified position, The workpiece shall not be processed during movement.
- when one axis completes the programming value, it stops, while the other axes continue to move.
- G00 can be written as G0.
Example: G00 X75 Z200 G01 U-25 W-100: First, along with X and Z axis move simultaneously at a rapid speed to point A by 25 units, then along Z continues to move rapidly to point B by 75 units.
Format: G01 X(U)_Z(W)F(mm/min)
- This command moves the tool to the specified position in a linear interpolation manner. The feed speed is controled with F command. All coordinates can be run in tandem.
- G01 can also be written as G1.
Example: G01 X40 Z20 F150: Two-axis simultaneous movement from point A to point B.
Arc Interpolation mia
Format: G02 X(u)_Z(w)I_K_F
- When X and Z are at G90, the end coordinate of the arc is the absolute coordinate value compare to the programming zero. At G91, the end of the arc is the increment relative to the beginning of the arc. I and K are the incremental coordinates of the center of the arc compare to the starting point.
- When the G02 instruction is programmed, it can be directly programmed through the quadrant circle, the whole circle, etc.
- G02 can also be written as G2.
Example: G02 X60 Z50 I40 K0 F120: Programming a quadrant arc with specified parameters.
Format: G04_F_ or G04_K_
During machining, motion is paused, and after the specified time, machining continues. The pause time is specified by the data following F. The unit is in seconds, ranging from 0.01 seconds to 300 seconds.
Intermediate Point Arc Interpolation
Format: G05 X(u) Z(w) IX IZ F
X and Z are the endpoint coordinates, while IX and IZ are the coordinates of the intermediate point. Similar to G02/G03 with additional parameters.
Example: G05 X60 Z50 IX50 IZ60 F120
These commands occupy a line by themselves in the program. When the program reaches this section, the feed rate will increase by 10%. To increase it by 20%, you would need to write two separate lines.
When placed on a line by itself in the program, the system will operate in radius mode, and the values following in the program will also be interpreted as radius values.
Diameter Dimension Programming
When placed on a line by itself in the program, the system will operate in diameter mode, and the values following in the program will also be interpreted as diameter values.
Format: G25 LXXX
When the program reaches this segment, it transfers to the specified program segment (XXX represents the program segment number).
Format: G26 LXXX QXX
When the program reaches this segment, it starts the program segment specified by LXXX as a loop, and the number of repetitions is determined by the value following QXX.
G Code Commands List
Defining Machining Planes
- G17 Spindle Z-plane XY
- G18 Spindle Y-plane ZX
- G19 Spindle X-plane YZ
- G24 Chamfer of length R, chamfer length R
- G25 Radius R rounding, radius R
- G26 Tangent approach to contour with radius R
- G27 Tangent exit contour, radius R
Defining Workpiece for Graphic Display
- G30 Workpiece definition: minimum point
- G31 Workpiece definition: maximum point
Tool Radius Compensation
- G40 Tool center path, no tool radius compensation
- G41 Left radius compensation path
- G42 Right radius compensation path
- G43 Radius compensation: expanding path
- G44 Radius compensation: retracting path
- G28 Mirroring
- G53 Origin shift using the origin table
- G54 Origin shift
- G55 Origin plane
- G73 Rotation
- G72 Scaling factor
- G80 Machining plane
- G247 Origin setting
- G70 Dimension units in inches (program starting point)
- G71 Dimension units in millimeters (program starting point)
- G90 Absolute dimensions
- G91 Incremental dimensions
G99 Tool definition, tool number T, length L, and radius R
Other G Codes
M Code Commands List
G and M codes, as well as a transformation of traditional machining methods, require a strong ability to apply program instructions and rich practical skills. At KUSLA, we have the necessary equipments, materials, and know-how of G&M codes to help you get high-quality machined parts.