0% found this document useful (0 votes)
31 views

G Codes

Uploaded by

Syprose Adhiambo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

G Codes

Uploaded by

Syprose Adhiambo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

G CODES

To control CNC machines, we use commands called CNC G Codes. Although Different
manufactures of the machine tool may adopt their own use for certain G Codes there is
a core group that is common on every machine tool. These standards are used on CNC
Lathes, Milling machines, routers and more recently by 3D printers (in a very basic
form). We are going to examine this group and how they are used to control the
machines.

G00 - Rapid travel

It can be shortened to G0 as the older machines didn’t have much RAM and every bit
counts.

This command is used when the tool is not touching the part to rapid move, normally
used when going home for a tool change and returning with a new tool. Some
machinists like to rapid as close to the part as possible but it is advised to give oneself at
least 1mm clearance. Keep your hand on the feed knob and come in slow for the first
time run. It is in this mode you will do the most damage if you didn’t get your tool set
up right.
G00 X-100;
In the example above, the cutter is moving 100mm to the left.

G00 is the rapid travel command in G Code. It is used when the cutter or tool is not
removing material so that the time it takes to machine the part is as quick as can be. The
top speed is set by the machine parameters and therefore is only controllable by the
operator using a rapid override control.
When using a rapid move, be aware of any clamps, vices, and parts that may be in your
path. If you are unsure it may be wise to move the X and Y axis first, then on a separate
line, move down in Z. It will increase your machining time by a second or two but it
will help avoid a 3 Axis crash.

G01 - Linear Interpolation

A G01 command is used when you are cutting in a straight line. This command has to
have a feed rate (F) active before it will run. A typical block would look like G01 X-100
F50.0; You don’t need to add this command on every line, as long as there is no other
movement G-Code active, for example, you only need to add it after a G02, G03 or a
G00 command. In much the same way, a feed rate (F50) is only needed once until you
want to change the speed in which you are cutting.
G00 X101 Z1.0;
G01 X100 Z-20 F100;
X110 Y-40;
G00 Z300;
This command can be used with all axis cutting at the same time, or just one. It is not
common to cut with the Z axis as well as X and Y but it is possible if needed.

When programming a profile, it is easier to use cutter compensation G41 and G42 then
you do not need to allow for the radius of the cutter when plotting your tool paths, you
can simply use the dimensions on the drawing and the machine will offset the cutter to
achieve the correct dimensions.
G02 and G03 - Circular Interpolation

G02 is used to machine an arc or radius in a clockwise direction and G03 is for anti-
clockwise.

Using an ‘R’ value to define the radius, the G02/G03 command moves the cutter in a
straight line with the defined radius at the end of this move.

If a feed rate is already active there is no need to add it to this line unless you wish to
change the feed rate for the machining of the arc.
G03 Y50.0 R10.0 F100.0;
G01 X50.0;
The centre point of the arc can also be defined using I, J, and K values. I (X) J(Y) and
K(Z) defines the auxiliary axis.

Using the drawing above, programming an arc using I and J values would look like
this:
G03 Y50.0 I10.0 J40.0 F100.0;
G01 X50.0;
The K is seldom used but is available if an arc using the Z axis is needed.

When using G02 with G01 and G03 (Counter clockwise arc) any shape can be machined.
These three G Codes are the foundation of G Code programming and are the three you
will use when cutting material.
G04 – Dwell
Sometimes we need to pause the cutter for a brief moment, for that we add a dwell to
the code to stop the machine from continuing reading the program for a specified
amount of time.

Uses:

While drilling with a flat bottom drill and the surface of the bore has a chattered finish,
we can stop moving the drill in Z-Axis with it still rotating for half a second to clean up
the surface.
G01 Z-20.0 F50; G04 X500; G01 Z5.0;
The few blocks listed above looks like the tool will move 500mm while deep in the part.
It won’t. The X value in ‘G04 X500’ forces the tool to dwell for 500 milliseconds before
moving onto the next block. The feed rate does not need to be specified again after a
dwell command as the machine still knows that one was defined before the dwell on
the G01 block.

G20 and G21 - Measurement Systems

G20 and G21 are Imperial and Metric systems. G20 Define Inch units; G21 Define Metric
units; CNC Machines can read measurements in both Imperial and Metric systems
(inches and mm) this is defined by G20 and G21.

Although it is only needed once in the program it is good practice to add this
information after every tool change. This makes it safer to run from any position in the
program.

For example, you might want to repeat the finishing cutter pass to remove more
material after measurement. To define the unit of measurement again will stop the
machine from accidentally being in the wrong system and moving unexpectedly.
G90 and G91 - Absolute or Incremental
G90 = Absolute positioning
G91 = Incremental positioning
A positioning system must be defined before any movements are made, below is an
explanation of both positioning systems

G90 selects the absolute positioning system. In this mode, all movements of the spindle
are taken from the datum position. For example, if X100.0 is read by the control then the
tool will move to 100mm in the plus direction from the datum. If X150.0 was the next
positional movement it would move the tool another 50mm in that direction.

G91 selects the incremental positioning system. When G91 is active all movements of
the spindle are taken from its last known position. For example, If X100.0 is read then
the tool will move 100mm in the plus direction of the position that the tool is already in.
If X150.0 was read after this move, The tool will move another 150mm in the plus
direction.

When programming CNC machines, we have to be aware of the difference between


G90 and G91 G-Codes. Also known as absolute (G90) or incremental (G91)
programming.
These G-Codes tell the machine controls how to read the measurements. Below we take
a look at how each one works

The G Code G90 is used to define the absolute positioning system. When G90 is active
the machine will read all dimensions and movements from the working datum position.

If we were to issue a movement command such as G00 X100.0 Y100.0; then the machine
would move 100mm in the plus direction from the datum in both the X and Y axis.

If we were to enter G00 X0.0 Y0.0; we would move the spindle/tool to the datum
position.

Each and every movement command we make will move the tool in relation to the
datum position that we have set previously.

Regarding the above drawing. To move the cutter to position A from the datum in the
lower left-hand corner of the part, we would give an X dimension of +80. To continue to
move to position B we would give an X dimension of +100.

So in absolute mode, each dimension is taken from the datum.


G91 incremental positioning

When working with G91 incremental positioning, We command the tool to move from
its current position and not the datum position.

The above drawing shows that to move to position A from the origin we would give a
distance of 80mm, the same as absolute. To move from position A to position B we
would need to command the X-axis to move 20mm in the plus direction.

This is because we are giving the distance from the tool position and not the datum
position.

We can think of it as the origin or datum is shifting to the centre of the tool after each
movement.
Programming with G90 absolute

Let's have a look at how we would program the hole positions on this drawing.

The way the dimensions are laid out gives us everything we need to know to be able to
program this using the absolute system. Everything comes from the datum, just like the
way we would program using G90.

Note: This program simply moves to each position marked on the drawing using the
absolute G90 system. This program does not drill the holes

:0002 (G90 EXAMPLE);

N2 T0202 (15MM DRILL);

G90 G21;

S600 M03;

G00 X15.0 Y15.0 (POSITION 1);

X35.0 (POSITION 2);

X55.0 (POSITION 3);

X75.0 (POSITION 4);

Y35.0 (POSITION 5);


X55.0 (POSITION 6);

X35.0 (POSITION 7);

X15.0 (POSITION 8);

Y55.0 (POSITION 9);

X35.0 (POSITION 10);

X55.0 (POSITION 11);

X75.0 (POSITION 12);

G00 Z50.0;

G28 X0.0 Y0.0 M05;

M00;

Every X and Y movement command takes the dimensions from the datum position on
the bottom left of the part.
Programming with G91 incremental

Now for the same program written using the G91 Incremental system.
The drawing here shows the dimensions using incremental. All dimensions are taken
from the tool position and not the datum.

:0003 (G91 EXAMPLE);

N2 T0202 (15MM DRILL);

G90 G21 (MOVING TO POSITION 1 IN ABSOLUTE);

S600 M03;

G00 X15.0 Y15.0 (POSITION 1);

G91 (INCREMENTAL MODE); X20.0 (POSITION 2);

X20.0 (POSITION 3);

X20.0 (POSITION 4);

Y20.0 (POSITION 5);

X-20.0 (POSITION 6);

X-20.0 (POSITION 7);

X-20.0 (POSITION 8);

Y20.0 (POSITION 9);

X20.0 (POSITION 10);

X20.0 (POSITION 11);

X20.0 (POSITION 12);

G90 (ABSOLUTE MODE);

G00 Z50.0;

G28 X0.0 Y0.0 M05;

M00;

Use of the G90 absolute to move the cutter to the first position is done, since the spindle
position is unknown at this time. Once the tool is at the first hole, G91 is activated for
the duration of the movements.

Drilling Cycles
We can't talk about incremental without mentioning canned cycles.

A lot of canned cycles such as the G81 drilling cycle automatically use incremental
when activated on most machines (but not all, check your users manual). We do not
have to state this by entering the G91 command. Below is an example of the same
program but this time using a G81 drilling cycle.

:0004 (G91 EXAMPLE);

N2 T0202 (15MM DRILL);

G90 G21;

S600 M03;

G00 G81 X15.0 Y15.0 Z-10.0 (POSITION 1, DRILLING CYCLE ACTIVE);

X20.0 (POSITION 2);

X20.0 (POSITION 3);

X20.0 (POSITION 4);

Y20.0 (POSITION 5);

X-20.0 (POSITION 6);

X-20.0 (POSITION 7);

X-20.0 (POSITION 8);

Y20.0 (POSITION 9);

X20.0 (POSITION 10);

X20.0 (POSITION 11);

X20.0 (POSITION 12);

G00 Z50.0;

G28 X0.0 Y0.0 M05;

M00;
On the third line, we select the absolute system with G90 and move to the position of
the first hole. We continue to drill all holes using incremental but we don't need to
select G91 as it is part of the G81 drilling cycle.
Safety
When switching between G90 and G91 within your programs care must be taken when
not running the program from the start. A good habit to minimise mistakes is to state
G90 or G91 before any movement commands are made on each section of G-Code after
the tool change

You might also like