Difference between G code and M code in CNC programming?
G code and M code are types of machine control codes used in CNC (computer numerical control) manufacturing. G codes are used for controlling the movement of the machine and its axes, such as rapid movement (G00), linear movement (G01), and circular movement (G02/G03). M codes are used for miscellaneous machine functions, such as turning on/off coolant (M08/M09), opening/closing machine doors (M30/M31), and initiating tool changes (M06). In general, G codes are used to control the movement of the machine and its tool, while M codes are used to control other machine functions.
G-codes are also known as preparatory codes, and are used to control the movement of the machine’s tool in a specific coordinate system. G-codes are used to command the machine to move in a certain direction, at a certain speed, or to perform a specific action. Some common G-codes include G00 (rapid positioning), G01 (linear interpolation), G02 (circular interpolation clockwise) and G03 (circular interpolation counter-clockwise).
On the other hand, M-codes, also known as miscellaneous functions, are used to control non-movement related functions of the machine. These can include turning on/off coolant, opening/closing machine doors, initiating tool changes, and more. Some common M-codes include M00 (program stop), M01 (optional program stop), M02 (program end) and M03 (spindle on – clockwise).
In CNC programming, both G-codes and M-codes are used together to control the machine in a specific sequence. G-codes are generally used to control the movement of the machine while M-codes are used to control other machine functions such as coolant, spindle speed, tool changes, and more.
Additionally, G-codes can also be used to control the machine’s cutting speed, feed rate, and tool selection. The cutting speed is the speed at which the cutting tool moves through the material, and is typically measured in units of surface feet per minute (SFM) or meters per minute (MPM). Feed rate is the speed at which the cutting tool is moved along the workpiece, and is typically measured in inches per minute (IPM) or millimeters per minute (MMPM).
In addition to these, G-codes can also be used to control the machine’s coordinate system, which is the system of coordinates used to define the position of the machine’s tool in relation to the workpiece. G-codes can be used to switch between different coordinate systems, or to move the machine’s tool to a specific point in a specific coordinate system.
M-codes, on the other hand, can be used to control various machine functions such as starting and stopping the spindle, turning coolant on and off, and initiating tool changes. They can also be used to control the machine’s program flow, such as stopping the program execution or jumping to a specific point in the program.
In summary, G codes and M codes are used in conjunction to control the movement of the machine and its tool, as well as other machine functions. G-codes are used for moving the machine and its tool, controlling the cutting speed, feed rate, and tool selection, while M-codes are used for miscellaneous machine functions like coolant, spindle control, tool changes, and program flow control.