A guide to everything your need to know about G-code

What is the G-code?

Originally, wood- and metal-working machines were operated manually and controlled by cranks. Man power was slowly replaced by steam engine than electricity, but still controlled manually until mid-20th century.

In the '40s, John T. Parsons mounted a servomotor on the cranks to automate them and acted as one of the pioneers of numerical control for machine tools.

Then, in the '50s, Engineers at MIT develop a language to communicate with the machine. This is how G-code was born. 

It is a language that simply allows you to send information to a machine to tell it where to go, how fast to go there, and what to do on the way.

How does G-Code work?

G-Code is made up of strings of letters and numbers like this one, comprising different classes of machine commands.

Odoo • A picture with a caption
An example of a G-code section

There are different types of codes: 

1/ Codes that start with G are preparation functions, which indicate a specific task to the machine as it is:

  • "Make a hole"

  • "Mill a line"

  • "Move there"

2/ The codes that start with M are various machine commands. They are usually used to turn something on or off, such as a spindle or a cooling system.

3/ Codes that start with D, H or T define the tools to be used and the offsets to be used with that tool.

4/ Finally, codes that start with F or S define the machine's travel and rotation speeds. Literally the "Feed" and "Speed". For more information, refer to our eponymous article.

The various codes in the G-code are divided into groups. A line of G-code is composed of several functions, but can only contain one action per group, in order to avoid errors. For example, the machine cannot be asked to drill and tap a hole at the same time.

To discover the different groups of G-code and the parameters of each function, there are reference tables, like the one of LinuxCNC.

Is it useful to learn the G-code?

Originally, the G-code was directly entered by hand into the machines. Today, we use CAM software that allows you to generate the commands using the post-processor adapted to your machine. They also make it possible to generate movements that are much more complicated than what could be done manually.

It is therefore not necessary to learn the G-code. However, knowing the basics allows you to quickly find your way around the code during a machining operation, to find errors or to make quick modifications from the control software.

To learn more about CNC control software, you can refer to our article here.

For example, the following commands can be very useful: 

  • G0: Moves at rapid speed (linear interpolation)

Example: G0 X30 Y45 moves the machine to the work coordinate (30.45) at high speed.

  • G01: Moves at working speed (linear interpolation).

  • G02: Clockwise movement (circular interpolation).

  • G0 : counterclockwise movement (circular interpolation).

  • F : allows you to change the speed of an operation

Are there G-code specifications depending on the machines or programs used?

Yes, and this is one of the disadvantages of G-code. Although most of the standard functions are identical, every major manufacturer such as Haas, Fanuc or Siemens has also added their own codes. Therefore, you have to use the post processor adapted to the machine you are using from the CAM software. The G-code, originally developed for milling machines, is now also used by 3D printers which added new functions.

To learn more about the installation of the Mekanika post-processor for Fusion360, please refer to our article here.

Share this post
Sign in to leave a comment
What is the best CNC control software?