What are G-Codes and how 3D printers use it
3D printers fall under the category of computerized numerical control (CNC) machine. These are the computer aided manufacturing machines in which different tools are used to perform different operations and are controlled by a specific numerical controlled programming language called G-codes. As 3D printing is an additive manufacturing process in which machine has to add the material layers according to the shape of the 3D object. These G-codes gives directions to the CNC machine about the movement of different tools used for different application and in case of 3D printer these G-codes gives the direction for the formation of a proper 3D object. There are different softwares that are used for the generation of the G-codes as in the case of 3D printer first cad model of an object is designed. These specific programs like Cura, skienforge, slic3r takes the specific 3D CAD model and generate G-codes by slicing it in to the layers. It provides the specific G-code for each layer and then the object is printed material wise. There are other libraries like Mecode which are also used to generate the G-codes which gives more accuracy in the 3d printing.
How to write G codes
G-codes syntax is very simple it uses the Alphabets of English. Each alphabet which is used in the G-codes has a special purpose. The main alphabets which are used by the G-codes are G, E, F, X, Y, Z etc. The commands are given through these variables and in each line there are many variables depending upon the function that has to be executed during the line.
Let’s write a simple line of G-code.
G1 X-4.5 Y-6.5 Z0.5 F2000.0 E0.0377
This command is for the motion of the tool and it controls the movement of tool in the specific directions.
This command in line is for the movement in the X coordinate and the displacement it will covers is 4.5 millimeter and the negative sign shows the direction where the x-axis is negative.
This command in the line is for the movement in Y coordinate and the displacement it will cover is 6.5 millimeter. As it is positive 6.5 so the movement will be in direction of positive Y-axis
This command in the line is for the movement in Z coordinate and the displacement it will cover is 0.3 millimeter in the direction of positive z-axis (upward).
This F command is for the controlling the speed of the motor. In this case it is 2000mm/min
This command is for the total amount of extrusion and in this case speed rate is taken.
As the G-codes for an object is made into the sliced files and through these fragment of G-codes whole 3D object is created. Let’s take a fragment of G-Code which is the start of developing a 3d object. In this code the machine starts to print a square.
Starting Fragment of G-code will print this square
By combining fragments of G-codes the final 3d object.
The starting fragment of G code
G 21 This command sets the unit in millimeters.
G90 It set the printer to absolute positioning system.
G1 X400 F2000 Moves printer in X axis 400mm with 2000mm/min
G1 Y400 F2000 Moves printer in Y axis 400mm with 2000mm/min.
G1 X-400 F2000 Moves printer in negative x axis 400mm with 2000mm/min.
G1 Y-400 F2000 Moves printer in negative Y axis 400mm with 2000mm/min.
G92 X0 Y0 Z0 moves the printer to the origin where vale of x y and z is zero.
This above code has given direction to printer to print an outer line of 400mm*400mm square. To fabricate a whole 3D object the different G-codes fragment are combined, the code becomes complex and results in a finished 3D object which is shown above.