Gcode is a text based programming language that enables a CNC to operate. Most CNC hobbyists will probably never write a line of gcode since most CAD/CAM programs do that for you.
Gcode contain commands that begin with a letter followed by a number. The letter “G“ in the name “Gcode” stands for geometric, referring to the ability to plot and machine a point in 3-D space as defined by the 3 axes, X, Y, and Z.
Most gcodes in Gcode begin with the letter “g” however there are some that begin with the letter “m” and a few that begin with other letters of the alphabet. But the vast majority will begin with either the letter “g” or “m” followed by a number.
Some gcodes are preparatory, meaning they are used to prepare the machine to do its work and mcodes are modal which means they are used to control the machine’s movement.
Mcodes are used to control various machine functions like turning coolant on or off, turning the spindle on or off, etc. The best thing about M codes is that you don’t have to worry about them because they aren’t needed to run a BobsCNC Quantum Series or Revolution 4th Axis Routers (with the exception of M2 and M30).
Many CAD/CAM programs not only come with the drawing tools needed to design 2D or 3D projects they also contain a CAM program to convert the designs into toolpaths, which are gcode files. The CAM program contains a post processor. The post processor edits the tool path ensuring the step and direction commands in the gcode will work with the type of CNC you own.
When the gcode file is opened by a Gcode Sender, like BobsCNC BASIC SENDER, the file is sent line by line, to the CNC controller which tells the CNC spindle where to move and what to do. Both BobsCNC basic Sender, and UGS will allow you to preview the gcode file as it runs using a simulator included with the software.
13 Common G-Code Commands Plus M2 & M30
[G0] Rapid Positioning: This command moves the Spindle as quickly as machine parameters allow from the last position the Router (Spindle) was located to the next position needed to begin cutting. The G0 command must only be used when the cutting bit is out of the work piece and above the tops of any hold downs or clamps. No feed rate command required.
[G1] Straight Line Interpolation: This command moves the Router to and from the beginning of a cut to the end of a cut in straight line. A feed rate command is required.
[G2] Circular Interpolation (Clockwise): This command is used to move the Router from its last position in a clockwise motion to a specified location. This is used to create arcs any sized all the way to a full circle. A feed rate command is required.
[G3] Circular Interpolation (Counter-Clockwise): This command is used to move the Router from its last position in a counter-clockwise motion to a specified location in a circular arc to create any sized arc to a full circle. A feed rate command is required.
[G4] Dwell: This command is used when drilling holes in a work piece. It directs the CNC to wait or dwell at a given depth when drilling. This enables the bit to clear any material in the hole before drilling any deeper.
[G10] Coordinate System Origin Setting: This command tells the CNC the distance from the home position (Home: X0, Y0, Z0) to the workpiece zero position (i.e., where the work piece is mounted on the spoilboard).
[G17] The XY Plane Selection: This command tells the CNC that the XY is active and will interpret all subsequent X and Y coordinates as movements in the XY plane.
[G18] The XZ Plane Selection: This command tells the CNC that the XZ plane is active and will interpret all subsequent X and Z coordinates as movements in the XZ plane.
[G19] The YZ Plane Selection: This command tells the CNC that the YZ plane is active and will interpret all subsequent Y and Z coordinates as movements in the YZ Plane work.
G20] Set Imperial Units: This command tells the CNC that all measurements (units) when designing the gcode file were in inches.
[G21] Set Metric Units: This command tells the CNC that all measurements (units) when designing the gcode file were in millimeters.
[G90] Absolute Positioning Mode: This command instructs the CNC to interpret all location coordinates relative to a “single zero location.” In most cases this refers to the zero position of the work piece.
[G91] Incremental Positioning Mode: This command tells the CNC that all location values are made relative to the machine’s current position. The zero position changes each time the machine moves. This may be used for drilling a series of holes.
[M2] Program End, No Rewind: This command indicates the gcode file is finished. The “No Rewind” is a phrase left over from the early days of CNC, more accurately NC (numeric control) when the gcode files were recorded on reels of punch-tape and the reels had to be re-round. This command stopped that from happening. On large industrial machines it also stopped the machines’ movement on all axes, the spindle from rotating, and the flow of coolant.
[M30] Program End, Rewind: This command indicates the gcode file is finished. “Rewind” as above is a phrase left over from the early days of NC (numeric control). However, now it is used to reset industrial machines to their default mode. This command is unnecessary for a BobsCNC Router because the “header” at the beginning of gcode files contains all the preparatory gcode commands to set up the CNC for proper operation.
What a G-Code File Looks Like
In the illustration below the first seven lines highlighted by the red brace in the example below is called a “Header.” It contains preparatory commands needed to set up the CNC for correct operation. The header should be included in every gcode file. The line numbers in this example 1-26 are not necessary but are recommended for easy reference. Each individual lines is called a “block.” Blocks tell the CNC where to go, how fast to go, and what to do.