Programming a CNC machine for milling or lathe operations requires an understanding of how to create G-code and M-code.
G-code represents the operational language of the CNC process. The commands used line-by-line provide instruction on how the tooling in the machine should move in order to be in the correct position to perform a cutting operation. For the programming to function correctly, it is necessary to establish a fixed reference frame of three axes so that a command that specifies tool movement to a specific location will do so against this reference frame or coordinate system.
M-code is the machine control language for CNC. It is used to switch on or off certain machine functions. For example, there are commands to start or stop programs, start spindle rotation in counterclockwise or clockwise directions, or turn on or off coolant. When used in conjunction with G-code, the CNC programming generated an automated sequence of steps that can produce a finished part matching the original CAD model in dimensions and desired tolerance.