What is a 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 - a language that 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. It has now been accepted as the universal language for CNC machining.
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.
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"
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.
Mekanika is a Belgian startup based in Brussels whose ambition is to make local production more accessible. We produce desktop machines for screen printing and CNC milling, which have been recognized for their quality and ease of use, with open source plans allowing makers to adapt their tools to their specific needs.Visit our shop to find out more, or check out our tutorials to continue learning.