Live Knowledgebase > SmartBench > Essential principles > CNC theory > What is G-code?

Please Wait a Moment
X

Knowledge Base

Our knowledgebase contains all the information you need to know about all things SmartBench

 

What is G-code?

This article will explain what G-codes are and how they are produced with an example.

| List | Next >

Understanding G-codes

G-code is what SmartBench reads in order to bring a CAD/CAM model to life. 

It is a set of instructions that tells CNC machines where to move, how fast to move and what path to follow. Each separate line or block contains a machining instruction.

G-code is shorthand for “geometric” code, and you might notice that many of the words or individual codes of this machine language also begin with the letter G.

Functions of G-codes

The table below shows some frequently used G-codes along with their functions:

G-code

Function

G00

Rapid move (typically x mm/min)

G01

Linear move at given feed rate

G20

Length unit in inches

G21

Length unit in millimeters

G90

Distance mode to absolute coordinate

G91

Distance mode incremental, relative to current position

Structure of G-code

G-code programming is structured in a systematic way for efficient manufacturing. A typical structure of a G-code program has the following:

A: Preparatory functions

This is where the machine sets up the starting tool, unit of measurement, plane, etc of a workpiece.

B: Dimension words

This is where the machine understands your stock dimension and a profile that needs to be cut, along with information such as spindle speed and feed rate.

C: Miscellaneous or machine function

This is where the machine functions are executed. For example: extraction on or off, spindle on or off.

 In a human language the above G-code would direct a CNC machine as follows:

  • Load the starting tool (T1).

  • Plane for machining is XY (G17).

  • Set program length unit in millimeters (G21).

  • Set distance mode to absolute coordinate (G90). 

  • Turn the spindle on (M3) at 1000 rpm (S1000.0).

  • Start the workflow at a given feed (G1) in the Z-axis (Z-0.300) at feed rate 100mm/min (F100.0).

  • Rapidly raise the spindle (G0) in the Z-axis (Z7.500) .

  • Stop the spindle (M5).

How is G-code produced?

The process for turning a design into G-code usually looks like this: 

  • First, the 3D model is generated in CAD software.

  • The 3D CAD model is then imported into the CAM software, and the machining operations (toolpaths) are defined, e.g, roughing, finishing, drilling etc. 

  • The post-processor (which will normally be part of your CAM software) converts the machine operations to G-code (click here to learn more about post-processing).

Sample G-code example

This section will show you how G-code is generated from a simple 3D model. 

CAD model generation

The model is a 100x100x50 mm wooden block, which was modelled on Solidworks (CAD software).

CAM generation

The model is imported into CAM software (Vectric in this example), and the toolpaths are generated. 

The colour coding is as follows:

  • The blue line shows the cut profile (100x100x50 mm), and is used to represent the coordinates in the X and Y axis.

  • The green line shows where the tool retracts and engages with the workpiece (Z-axis).

  • The red line indicates the safety height above the workpiece.

D: Stock

E: Profile to be cut

Click here to learn more about Vectric. 

G-code generation (post-processing)

The CAM toolpaths are converted into G-code, via a post-processor. 

Click here to learn more about post-processing.

G-code example

This is the G-code for this cut:

Preparatory functions

T1

G17

G21

G90

Setting the dimensions

G0Z18.500

G0X0.000Y0.000

S1000M3

G0X0.000Y-25.000Z7.500

Cutting the profile (square)

G1Z1.100F100.0

G1X28.800F800.0

G1Z2.450

G3X25.000Y-21.200I-3.800J0.000

G1Z1.100

G1Y28.800

G1Z2.450

G3X21.200Y25.000I0.000J-3.800

G1Z1.100

G1X-28.800

G1Z2.450

G3X-25.000Y21.200I3.800J0.000

G1Z1.100

G1Y-28.800

G1Z2.450

G3X-21.200Y-25.000I0.000J3.800

G1Z1.100

G1X0.000

G1Z-0.300

G1X28.800

G1Z2.450

G3X25.000Y-21.200I-3.800J0.000

G1Z-0.300

G1Y28.800

G1Z2.450

G3X21.200Y25.000I0.000J-3.800

G1Z-0.300

G1X-28.800

G1Z2.450

G3X-25.000Y21.200I3.800J0.000

G1Z-0.300

G1Y-28.800

G1Z2.450

G3X-21.200Y-25.000I0.000J3.800

G1Z-0.300

G1X0.000

G0Z7.500

End of the job

M5

G0Z18.500

G0X0.000Y0.000

M2

SmartBench

The G-code is then simply transferred to SmartBench, ready for manufacture.

Click here to learn more about how to transfer your G-code file to SmartBench.


| List | Next >

If this article didn't solve your problem, please submit a support ticket here

Elliot.

Elliot. is the author of this solution

Glad we could be helpful. Thanks for the feedback.

Sorry we couldn't be helpful. Your feedback will help us improve this article.

Did you find it helpful?

Yes   No
Updated on Fri, 12 May 2023