G-code stands for “Geometric Code”. We use this language to tell a machine what to do or how to do something. The G-code commands instruct the machine where to move, how fast to move and what path to follow.
Code initialization. This character (%) is always present at the beginning and at the end of the program.
In some G-code files you can also see “N##” in front of the commands. The N is simply there to number the line or block of code. That can be helpful for identifying a specific line in case of an error. This code is not essential but is good practice.
The G00 command moves the machine at maximum travel speed from a current position to a specified point or the coordinates specified by the command.
The G02 command tells the machine to move clockwise in a circular pattern (G03 is counterclockwise).
With these G-code commands we select the working plane of the machine (G17 – XY plane, G18 – XZ plane, G19 – YZ plane).
We will be using G17 for the XY plane.
The G21 command defines the G-code units, in this instance millimeters (G20 is inches).
The G28 command tells the machine to move the tool to its reference point or home position.
With the G90 and G91 commands we tell the machine how to interpret the coordinates. G90 is for absolute mode and G91 is for relative mode.
In absolute mode the positioning of the tool is always from the absolute point or zero. So the command G01 X10 Y5 will take the tool to that exact point (10,5), no matter the previous position.
On the other hand, in relative mode, the positioning of the tool is relative to the last point. So if the machine is currently at point (10,10), the command G01 X10 Y5 will take the tool to point (20,15). This mode is also called “incremental mode”.
In this tutorial we will be using G90 for absolute mode.
We will now begin writing the G-code for a Checkers game piece; G-code can be written on Google Docs, on the NotePad app, in Visual Code Studio or directly into NC Viewer.
Example Code:
%
N01 G00 G02 G17 G21 G90
Code initialization: This character (%) is always present at the beginning and at the end of the program.
Safety line: N01 is line number 1, G00 tells the machine to move at full speed, G02 tells the machine to move in clockwise direction, G17 indicates we are working on the XY plane, G21 sets programming in metric system (all dimensions in mm) and G90 sets absolute positioning.
Use the 'Useful Website' resources below to investigate how to create a circle and complete the task.
N45 G0
N46 G21
N47 X0Y0
N48 G1 Z-1
N49 G2 J-3
N50 Z1
N51 G0
N52 G21
N53 X-0Y-1
N54 G1 Z-1
N49 G2 J-2