CNC Programming with G-Code

The days of manual milling, grinding, and forming workpieces are almost over. Today, most manufacturers use some form of Computer Numerical Control (CNC). CNC allows complex and precise work to be done on as many as five axes at a time and is more productive, efficient, and accurate compared to manual milling.

CNC programming is required to develop the instructions for the internal CPU on the CNC machine that allows it to control specific tools. These instructions guide the tool path not only to perform precision cuts on the workpieces. They also tell the machine the most efficient order to perform the work to complete it with the least amount of time and waste.

To find out more about CNC software, you can check out our article “The Ultimate Guide to CNC Software” here.

What is CNC Programming Software?

The controllers within a CNC machine are connected to toolsets. But CNC programming isn’t about entering instructions on the machine interface to activate the toolset needed. Instead, the complexity of the required instructions requires CNC programming software.

CNC programming software is used to create a detailed set of instructions that tell each linked tool what to do, how fast to do it, and where the action needs to occur on the workpiece. The codes required for these instructions are then sent to the computer onboard the CNC to run the appropriate tool. CNC programming software allows a machine to understand the functions and tasks required for the design being produced.

How to Write G-Code

G-Codes for CNC machines are considered preparatory codes and begin with the letter G. These codes direct the machines to perform movements. Typical G-Code actions include:

  • Changing a Pallet – Pallets are used to remove and add material for new workpieces to reduce or eliminate manual loading and unloading time.
  • Controlled Feed – This includes the various straight lines and arcs required by the design.
  • Set Tool Information – Tool start information such as offset and other parameters set before work begins.
  • Switch Coordinate Systems – CNC programming works off a Cartesian coordinate system using an X, Y, and Z coordinate structure.
  • Rapid Movement – This allows the CNC machine to move the tool quickly between two points for the next cut.
  • Feed Moves – Controlled feed moves may require a cut, bore, grind, or decorative profile shape.

How to Read G-Code Commands

G-Code–or Geometric Code–is a programming language that tells the CNC machine how to move and what to do. Tools are driven by these commands in a defined toolpath. Each line within a set of G-Code instructions has five components. 

The first is the G command telling the machine to move in a certain way.  This is followed by X, Y, and Z coordinates with the grid position number for each axis.  And the final is the F value which determines the feed rate to move during the cut.  These instructions are included in a list, like a roadmap, that the machine reads left to right starting at the top line and moving to the bottom.

The Most Common G-Codes

To control the movement with G-Code there is a long list of common G-Codes that correspond to specific functions and movements. When combined in a G-Code program, these codes guide a machine’s movement to complete each task in order.

Common G-Codes Include:

G00: Rapid Positioning 

One benefit of CNC machines is that they offer efficient production.  The G00 code is used for rapid movement from point to point.  The machine will know to move all axes at the same time, so the position quickly moves in a straight line to bring it to the next point.

G01: Linear Interpolation 

This is the most common code used for feeding during cuts. The CNC computer will determine the start point as well as the endpoint and calculate the material depths and parameters to reach the destination in a straight line. This is not simply moving from one point to another.  This code determines the linear movement through the material and sends instructions to the machine’s motors and servos to keep the path in a straight line during the cut when resistance is encountered.

G02: Circular Interpolation Clockwise 

Circles and arcs are pretty standard in workpieces. The same computer control that works to keep the machine moving using linear movements in G01 performs complex and fast calculations in G02 to produce circle or arc cuts in a clockwise motion.

G03: Circular Interpolation Counterclockwise 

G03 is the same as the motions and is calculated by the CNC machine’s computer, except that the rotation used for the arcs and circles is counterclockwise. Intricate cuts such as G01, G02, and G03 show why CNC programming software is critical. The number of calculations, the precision, and the orchestration of the motors and servos to act and compensate for the force required for material removal while remaining linear or circular can only be accomplished with software.

G17: XY Plane Selection  

This code determines the position of the tool in the XY plane. In most CNC equipment, the G17 code will be the default power-on code unless changed by G-Code instructions by the CNC programming software for a specific workpiece requirement.

G18: XZ Plane Selection 

G18 is used to determine the XZ circular plane motion. On multi-axis machines, circular motion can be accomplished using a fourth or fifth axis. G18 accomplishes this by defining the position of the tool around the XZ plane.

G19: YZ Plane Selection  

Like the G18, the G19 code also determines the circular motion by defining coordinates within the YZ plane. When combined, these coordinates in the master G-Code instructions can move the tool to perform tasks in any direction.

G20: Programming in Inches  

While most of the world uses the metric system of coordinates, the US, Canada, and the UK often use Standard measurements. The G20 code sets the measurements of the design in inches for those situations.

G21: Programming in Millimeters  

Likes G20, G21 defines measurements for the workpiece and all cuts and tool actions. However, this code sets the measurements in millimeters.

G28 Return Home  

Every CNC job starts at home position. This is the default reference point where all programs begin.  However, G28 moves the tool to the home position by X, Y, and Z coordinates plotted against the Part Zero position and not the Machine Zero position. This keeps the tool from colliding with the part. This means that the Return Home G28 code may make more than one move to return the original home reference point.

G90 Absolute Positioning  

Different workpiece designs require different toolpaths to achieve the most accurate and efficient path to perform the task. Because of this, some CNC jobs require absolute positioning. In absolute positioning, the movement of the tool is always from point zero. G code coordinate commands will take the tool to the defined point regardless of where it was in the previous position.

G91 Relative Positioning  

G91 is the other side of the coin from G90. Here, tool movement and positioning are relative to the previous point. This is also called incremental mode and this may be a more efficient progression for the workpiece compared to absolute or based on the design parameters of the workpiece.

These are the most common G codes used in CNC machines. But there are dozens more that include things such as cutting, grinding, boring, tapping, threading, drilling, and other subtractive commands. 

There are also numerous G codes for offsetting and for more complex functions such as rotating the coordinate system and complex feed rate adjustments depending on the design.  All these G-Codes work in concert with CNC computers and are part of the magic of CNC programming software.

Conclusion

CNC machines have revolutionized manufacturing production. They offer more precise and more accurate pieces at faster throughput rates than manual production. They are also more efficient, produce less waste, and leave significantly less room for human error.

But CNC programming software that produces G-Codes is what makes this possible. This software not only controls the motion and path of the tools. It tells the machine how fast to move, what speed to perform each task, and instructs the CNC computer on adjusting motor and servo speed to keep linear motions straight and circular motions arced with precision and to a tight tolerance.

Now you know a little bit more about G-Codes and their importance in CNC programming software. And with just a quick effort, you know now how to read and demystify G-Codes to make sense. And finally, you understand how it works and how it makes the speed and precision of CNC machined parts much more desirable than manual inputs.

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

More To Explore

Uncategorized

Level Up With a Tiny Compression CNC Bit

This tiny little 1/8″ compression bit is pretty incredible. We’ve been experimenting around with it here at Fabber HQ. Check it out:

Uncategorized

VanBuilders uses Fabber!

The folks at VanBuilders.com have been long time users of Fabber. Check out some of their fantastic projects below. They design each van custom and