G-code  is the most widely used computer numerical control programming language. It is primarily used in computer-aided manufacturing to control automated machine tools and has many variants. G-code instructions are given to the machine controller (industrial computer), which tells the motor where to move, how fast to move, and what path to follow. The two most common cases are that in machine tools such as lathes or mills, the cutting tool is moved according to these instructions, cutting away material through the toolpath, leaving only the finished part and/or the unfinished part precisely positioned around three Any of up to nine axes in three dimensions, relative to the toolpath, and one or both of which can move relative to each other. The same concept extends to non-cutting tools such as forming or polishing tools, additive methods such as photo-drawing, 3D printing, and measuring instruments. All CNC machines rely on G-code to function.

G-code programming is used in conjunction with M-code. M code stands for machine code and controls various functions of CNC machine tools that are not directly related to motion. These functions include commands such as machine loading programs, program pauses and coolant flow.

The Application of G Code in NC Machining

G code is the most widely used CNC programming language, mainly used in computer-aided manufacturing to control automatic machine tools.

G-code plays a vital role in CNC programming. CNC machines cannot understand conversational language. They use a dedicated set of machine language commands. Programmers compile these commands into G-code files that instruct the CNC machine how to operate. G code is an instruction in the NC program, generally called G instruction, using G code can realize fast positioning, reverse circular interpolation, forward circular interpolation, intermediate point circular interpolation, radius programming, and jump processing.

Are all G-codes common in CNC machine tools?

There are more than one hundred G-code commands for CNC programming. Most G-codes are common to every CNC programming operation. However, certain G-codes are specific to types of operations such as milling, turning, drilling, etc. G-code listings may vary between different CNC manufacturers. Not every machine supports all G-codes. Additionally, machines with unique features or multi-axis machining capabilities may have additional G-codes. The manufacturer may provide instructions for G-code for CNC programming in the reference yearbook accompanying the machine tool. The G-code may vary slightly depending on the specific build model you are using, before referring to your machine’s owner’s manual, check your equipment’s CNC programming design for differences.

Knowing G-codes is essential for learning CNC programming and making any part by automating the machining process, there are many different G-codes for different instructions. You can refer to the table below for G-codes to use when working on a CNC programming project.

Commonly used G code types in CNC machine tools
G-code that controls motion and toolpaths in CNC programming
G00 Machine tool moves quickly
G01 Machine tool linear interpolation
G02 Clockwise circular arc interpolation
G03 Counterclockwise circular arc interpolation
G04 stay
G09 precise stop

 

Plane selection G-code program specifies a two-dimensional plane in the X, Y, Z axis Cartesian coordinate system
G17 XY plane selection
G18 XZ plane selection
G19 YZ plane selection
G-code programs for dimensions indicate which units of measure are selected
G20 Change unit measurement to inches
G21 Change unit measurement to mm
Tool compensation codes take into account parameters such as tool length and tool radius. Using these commands increases the precision of the entire CNC operation.
G40 Cancel tool length compensation
G41 Cutter Compensation Left
G42 Cutter Compensation Right
G43 Tool Length Compensation
Workpiece offset, zero offset ensures that the workpiece is in the true zero position
G54 Work Offset 1
G55 Work Offset 2
G56 Work Offset 3
G57 Work Offset 4
G58 Work Offset 5
G59 Work Offset 6
Canned cycle G-code program    
G73 High-speed deep hole drilling canned cycle. Chip breaking while drilling
G74  Peck drilling canned cycle, usually used for face grooving. For tapping only.
G75 Quick grooving cycle for CNC lathe
G76 Fine Boring Canned Cycle and Threading Cycle
G81 Standard Drilling Canned Cycle
G82 standard drill with dwell at the bottom of the hole
G83 Deep hole peck drilling cycle, retracts the entire hole
G84 Right-hand tapping cycle for threading into pre-drilled holes
G85 Reaming cycle or Boring cycle
G86  Bore and stop canned cycle; the spindle stops when the tool reaches the bottom of the hole
G87 Boring cycle for enlarging the hole diameter with special tools
G88 boring cycle with P command; P indicates the number of seconds to stay
G89 Back boring cycle with dwell
cancel code speed and feed
G50 zoom out G94 Feed per minute mode
G80 Cancels all active canned cycles G95 Feed mode per revolution
    G96 constant surface speed
G97 constant spindle speed
Targeting return command
G90 Use absolute mode for positioning G98 return to initial plane
G91 Use incremental positioning G99 return fast plane

 

uncommon G-code
G10 Program Offset Input G51 Zoom
G22 Store travel limit G52 Temporarily move the program to zero
G23  Store stroke limit cancel G53  Return to Machine Zero
G27 Zero Check G60 one-way movement
G28 Return to Zero G61 Exact stop check (modal)
G29  return from reference position G64 normal cutting mode
G30 Second position return to zero G65 Custom macro call
G31 Jump function G66 Custom macro modal call
G44 Negative Tool Length Compensation G67 Cancel custom macro modal call
G45 Single offset increase G68 coordinate rotation mode
G46 Single Offset Reduction G69 cancel coordinate rotation mode
G47  Double Offset Increase G92 Program Work Offset
G48 Double Offset Reduction

Precautions for writing G codes for CNC machine tools

CNC machine tools need to cut different materials, including many materials with high hardness. Therefore, writing errors in G-code may cause safety hazards to machines, operators and work areas. It is a relatively common accident that props are damaged due to collisions. Therefore, factors such as workpiece offset and tool length offset should be considered when writing G codes to ensure that tool damage does not occur.

When writing G code, you need to keep the following points in mind at all times:

  1. Be familiar with the functions of the CNC system (such as the g command of the fanuc system);
  2. Understand the structural characteristics and performance indicators of machine tools;
  3. Master the setting method of processing route and process parameters;
  4. Familiar with the types and specifications of the knives used, and choose the knives reasonably
  5. Familiar with the use of commonly used measuring tools.
  6. Use various measuring tools correctly.
  7. Correct use of fixtures.
  8. Pay attention to safe and civilized production, and always remember safety first.

Leave a Reply