CNC PROGRAMMING G-Code basics

image_print

G-Code from the Machine’s Perspective

There are a handful of basic concepts you should know before we dive into what individual g-codes do and how to use them. Most importantly, you must understand what a computer language is and how to think about it.G-Code is a computer language aimed at telling your machine what to do. The trouble with computer languages like g-code is that unlike people, machines are very literal. They assume you know exactly what you want, they don’t question you about it, and they immediately try to comply, even if that means hurting themselves!

G-Code Skill Level

For that reason, you need to adopt an approach of being protective of your machine, perhaps even over protective bordering on paranoid. It will do exactly what you tell it to even if that means rapiding a spinning cutter with 20HP behind it directly into your expensive fourth axis and destroying it. There’s no need to be afraid of g-code, but it is important to understand it and to respect it in order to be successful. Getting to that stage is another excellent reason to spend time learning the g-code. It will give you insights into your machine that enable you to extract more performance and to protect it better from accidents.                                                       (http://www.cnccookbook.com/CCCNCGCodeBasics.htm)

 
Code
Category
Function

Notes

Tutorials
 
  G00
Motion
Move in a straight line at rapids speed. XYZ of endpoint G00 and MDI.

 

Linear Motion: G00 and G01

 
  G01
Motion
Move in a straight line at last speed commanded by a (F)eedrate XYZ of endpoint G01 and MDI.

 

Linear Motion: G00 and G01

 
  G02
Motion
Clockwise circular arc at (F)eedrate XYZ of endpoint

 

IJK relative to center

R for radius

G02 / G03 Tutorial and Examples  
  G03
Motion
Counter-clockwise circular arc at (F)eedrate XYZ of endpoint

 

IJK relative to center

R for radius

G02 / G03 Tutorial and Examples  
  G04
Motion
Dwell: Stop for a specified time. P for milliseconds

 

X for seconds

Precise Timing and Speed: Dwell, Exact Stop, Backlash Compensation  
  G05
Motion
FADAL Non-Modal Rapids      
  G09
Motion
Exact stop check   Precise Timing and Speed: Dwell, Exact Stop, Backlash Compensation  
             
  G10
Compensation
Programmable parameter input      
  G15
Coordinate
Turn Polar Coordinates OFF, return to Cartesian Coordinates   G15/G16 Polar Coordinates  
  G16
Coordinate
Turn Polar Coordinates ON   G15/G16 Polar Coordinates  
  G17
Coordinate
Select X-Y plane   CNC G-Code Coordinates  
  G18
Coordinate
Select X-Z plane   CNC G-Code Coordinates  
  G19
Coordinate
Select Y-Z plane   CNC G-Code Coordinates  
  G20
Coordinate
Program coordinates are inches   G20 and G21: Unit Conversion  
  G21
Coordinate
Program coordinates are mm   G20 and G21: Unit Conversion  
  G27
Motion
Reference point return check   G28: Return to Reference Point  
  G28
Motion
Return to home position   G28: Return to Reference Point  
  G29
Motion
Return from the reference position   G28: Return to Reference Point  
  G30
Motion
Return to the 2nd, 3rd, and 4th reference point   G28: Return to Reference Point  
  G32
Canned
Constant lead threading (like G01 synchronized with spindle)      
  G40
Compensation
Tool cutter compensation off (radius comp.)      
  G41
Compensation
Tool cutter compensation left (radius comp.)      
  G42
Compensation
Tool cutter compensation right (radius comp.)      
  G43
Compensation
Apply tool length compensation (plus)      
  G44
Compensation
Apply tool length compensation (minus)      
  G49
Compensation
Tool length compensation cancel      
  G50
Compensation
Reset all scale factors to 1.0      
  G51
Compensation
Turn on scale factors      
  G52
Coordinate
Local workshift for all coordinate systems: add XYZ offsets      
  G53
Coordinate
Machine coordinate system (cancel work offsets)      
  G54
Coordinate
Work coordinate system (1st Workpiece)      
  G55
Coordinate
Work coordinate system (2nd Workpiece)      
  G56
Coordinate
Work coordinate system (3rd Workpiece)      
  G57
Coordinate
Work coordinate system (4th Workpiece)      
  G58
Coordinate
Work coordinate system (5th Workpiece)      
  G59
Coordinate
Work coordinate system (6th Workpiece)      
  G61
Other
Exact stop check mode   Precise Timing and Speed: Dwell, Exact Stop, Backlash Compensation  
  G62
Other
Automatic corner override      
  G63
Other
Tapping mode      
  G64
Other
Best speed path      
  G65
Other
Custom macro simple call   Subprograms and Macros  
  G68
Coordinate
Coordinate System Rotation   G68 and G69 Tutorial and Examples  
  G69
Coordinate
Cancel Coordinate System Rotation   G68 and G69 Tutorial and Examples  
  G73
Canned
High speed drilling cycle (small retract)      
  G74
Canned
Left hand tapping cycle      
  G76
Canned
Fine boring cyle      
  G80
Canned
Cancel canned cycle      
  G81
Canned
Simple drilling cycle      
  G82
Canned
Drilling cycle with dwell (counterboring)      
  G83
Canned
Peck drilling cycle (full retract)      
  G84
Canned
Tapping cycle      
  G85
Canned
Boring canned cycle, no dwell, feed out      
  G86
Canned
Boring canned cycle, spindle stop, rapid out      
  G87
Canned
Back boring canned cycle      
  G88
Canned
Boring canned cycle, spindle stop, manual out      
  G89
Canned
Boring canned cycle, dwell, feed out      
  G90
Coordinate
Absolute programming of XYZ (type B and C systems)      
  G90.1
Coordinate
Absolute programming IJK (type B and C systems)      
  G91
Coordinate
Incremental programming of XYZ (type B and C systems)      
  G91.1
Coordinate
Incremental programming IJK (type B and C systems)      
  G92
Coordinate
Offset coordinate system and save parameters      
             
M-Codes
 
 
Code
Category
Function

Notes

Tutorials
 
             
             
             
  M03
M-Code
Spindle ON (CW Rotation)   M03 and MDI.  
  M04
M-Code
Spindle ON (CCW Rotation)      
  M05
M-Code
Spindle Stop   M05 and MDI.  
  M06
M-Code
Tool Change      
             
             
  M30
M-Code
End of Program, Rewind and Reset Modes