If you’re new to plasma CNC machining, you may not be fully aware of the G-code.
Essentially, G-code is a programming language comprising lines of code organized in blocks. Each block performs a specific operation, such as cutting with a particular tool. And each line has the letter “N” as the label and a number that is mostly even (like N2, N4, N6.).
G-code is generated using CAM (computer-aided manufacturing) software. In a CAM program, you can enter your 3D CAD (computer-aided design) model and tool selections along with other important information about the project. CAM optimizes the path and creates a G-code to instruct the plasma CNC machine what to do.
It is also possible to write G-code programs by hand, but with more complex machines involving thousands of lines of code, you need the help of a machine. Even when you are not manually entering the blocks of code, you can add comments to these lines, which can help you identify a particular operation.
What is the Importance of G-code?
G-code tells a CNC machine what to do, so it is essential to learn its importance. With essential knowledge of G-code’s core functions, you can easily discuss its operation with a programmer, machinist, or operator.
When you run into an issue while working with the CNC machine, it helps to be able to check the program for any potential errors. If anything runs haywire, G-code knowledge will help you to evaluate and address the problem. When you are well-versed in how your machine works, you can customize the designs of the machine parts more effectively. This way, you will be able to save both time and money.
How to Read G-code Commands?
When you first look at a line of G-code, it will probably look alien to you, but as you keep learning, the lines will start making sense.
If you look closely at the code, you will notice that all lines have the same structure. The ‘complicated’ part of the G-code is the numbers in Cartesian coordinates. If you look at the single line, it will help to know how it works:
This is the structure of the line:
[G## X## Y## Z## F##]
- First comes the G-code command, which instructs the machine to move to a specific position in a straight line.
- The position or coordinates are given with X, Y, and Z values.
- With the F value, we can set the speed or feed rate for program execution.
In a nutshell, the above commands tell the CNC machine to move to specific coordinates at a given speed and in a straight line.
Now that we have a fair idea of how to read G-code, we can move to the most important G-code commands. Every G-code command combines a letter and numbers, and five main letters are used in this language. As mentioned earlier, each letter is related to a different action.
Here are the letters you need to know:
- M: codes for machine action
- G: codes for motion
- F: feed control
- S: spindle speed
- T: operating the tools
Paired with a number, each of these letters creates a command. Let’s look at the most important ones:
All the M commands control the machine and start or stop the spindle or starting tool change.
M00: stop program
M02: end program
M03: clockwise rotation, spindle on
M04: counterclockwise rotation, spindle on
M05: stop spindle
M06: change tool
M08: flood coolant on
MO9: flood coolant off
M30: end program, rewind, and reset mode
G commands prepare the CNC machine to move in a particular way. Coordinates accompany these commands to instruct the machine to move in a direction. Some G commands are used at the beginning of the program as safety settings to ensure that the machine is in the right mode.
G0: rapid motion
This command moves the machine to new coordinates to begin cutting or move back to the tool carousel to change the tool. The commands are always used when the tool is not in contact with any part.
G01: controlled motion
The command is used for cutting operations where the feed rate is also mentioned.
G02: clockwise motion
The clockwise motion is used for curved paths. In this mode, you need to specify end coordinates and distance to the center of the arc in both X and Y directions. I command is the X distance to the center, and J is the Y distance to the center. The arc’s starting point is the machine’s positioning when G2 begins, so you must first move the machine to a correct starting point.
G03: counterclockwise movement
This command will create an arc between two points, just like G2, but in a counterclockwise direction.
G17/G18/G19: working plane
- G17 will set the X/Y plane scheduled for machining, whereas G18 will set the Z/X plane and G19 will set the Y/Z plane.
- G20 will set the units in inches, G21 will set the units to mm, and this unit has to match your CAD model.
G28: home position
- G28 will send the machine directly to the home position. The machine goes there straight. If you provide an intermediate point, make sure that the machine does not crash into anything on the way home.
These commands handle the mode in which the machine interprets your coordinates. G90 puts the machine in absolute mode, and G91 tells the machine to operate in relative mode.
What is the Difference between G-code and M-Code?
Commonly, the CNC machine writes and performs the G-codes and deals with the machine’s motion control part. The M-codes are machine codes that operate the most basic electrical controls like coolants, tool changers, and safety circuits.
We covered the basics of G-code in this post and explained the important commands. Understanding G-code is not hard, but it may take some time to become familiar with it.