G-CODE & M-CODE
Definition: The full name of G-code is "Geometric Code."
It was developed in 1958 by the Massachusetts Institute
of Technology (MIT) Servomechanics Laboratory.
Purpose: It instructs machines on where and how to
move, enabling precise cutting and manufacturing.
Structure: G-code consists of the following types of
commands:
G: General machine movements (like G00, G01)
F: Feed rate (speed)
T: Tool change
S: Spindle speed
X, Y, Z: Three linear axes in the Cartesian coordinate
system
A, B, C: Angular rotation axes around X, Y, Z
How It Works:
G-code is generated from a CAD (Computer Aided
Design) file
The machine's microcontroller reads and interprets the
G-code
Various parts of the machine move according to the
instructions.
1.G00-RAPID POSITION
2.G01-LINEAR INTERPOLATION
3.G02-CIRCULAR ARC FEED MOVE IN
CLOCKWISE DIRECTION
4.G03-CIRCULAR ARC FEED MOVE IN
COUNTER CLOCKWISE DIRECTION
5.G15-POLAR-CORDINATE OFF
6.G16-POLAR-CORDINATE ON
G16 Works:
Coordinates Format: After G16, coordinates are
interpreted as distance (radius) and angle
Reference Point: The current position becomes the polar
coordinate origin (temporary center)
Direction: Angles are typically measured
counterclockwise from the 3 o'clock position (0°)
Input Format: After G16, X becomes the radius and Y
becomes the angle
When to Use G16:
Creating circular patterns (like bolt circles)
Machining features arranged in a circular pattern
When locations are easier to define by angle and distance
Simplifying complex circular machining operations
G15: Cartesian Coordinate System (Cancel Polar
Coordinates)
G15 cancels the polar coordinate mode and returns the
machine to the standard Cartesian coordinate system.
G15 Works:
Return to Default: Switches back from polar to the
standard X, Y, Z coordinate system
Coordinates Format: After G15, X, Y, Z represent standard
linear distances
Usage: Always used after completing operations that
required polar coordinates
7.G17-XY PLAIN SELECTION
8.G18-XZ PLAIN SELECTION
9.G19-YZ PLAIN SELECTION
G17: XY Plane Selection
Definition: Selects the horizontal XY plane as the active
working plane
Usage: Most common in milling operations, where the
tool moves across the table (XY plane)
Visual representation: Like drawing on a piece of paper
on a table
Applications: Face milling, pocket milling, profile milling,
drilling
G18: XZ Plane Selection
Definition: Selects the vertical XZ plane as the active
working plane
Usage: Standard for lathe/turning operations, where the
tool cuts along the length of rotating material
Visual representation: Like drawing on a vertical wall
aligned with the X-axis
Applications: Turning, facing, grooving, threading
operations on a lathe
G19: YZ Plane Selection
Definition: Selects the vertical YZ plane as the active
working plane
Usage: Less common, used for specialized operations
Visual representation: Like drawing on a vertical wall
aligned with the Y-axis
Applications: Side milling, special machining operations
Why Plane Selection Matters:
Circular Motion Definition: G02/G03 circular movements
need to know which plane to operate in
Tool Compensation: Cutter compensation (G41/G42)
depends on the active plane
Fixed Cycles: Many canned cycles operate based on the
selected plane
Default Setting: Most machines default to G17 (XY plane)
for mills and G18 (XZ plane) for lathes
10.G20-INCH MODE
11.G21-METRIC MODE
G20: Inch System
Definition: Sets all dimensions in the program to be
interpreted as inches
Usage: Common in US manufacturing and when working
with imperial measurements
Impact: All coordinate values, feed rates, and tool offsets
are read as inches
G21: Millimeter System
Definition: Sets all dimensions in the program to be
interpreted as millimeters
Usage: Standard in most of the world and in metric-based
manufacturing
Impact: All coordinate values, feed rates, and tool offsets
are read as millimeters
12.G28-RETURN TO HOME POSITIONS
Common Applications of G28
Program End:
Used at the end of programs to return the machine to a
safe position
Example: G28 G91 Z0 followed by G28 G91 X0 Y0
Tool Changes:
Often used before tool changes to position the machine
safely
Example: G28 G91 Z0 (raise Z) before T02 M06 (change to
tool #2)
Program Start:
Sometimes used at the beginning of programs to ensure
a known starting position
Example: G28 G91 X0 Y0 Z0 at program start
Safety Operations:
Used whenever the machine needs to be moved to a
known safe position
Example: Between different machining operations that
require repositioning
13.G40-TOOL COMPANSATION OFF
14.G41-TOOL COMPANSATION ON RIGHT
TO LEFT SIDE
15.G42-TOOL COMPANSATION ON LEFT
TO RIGHT SIDE
16.G43-TOOL HEIGHT COMPANSATION
G40: Cancel Tool Radius Compensation
Function: Cancels any active tool radius compensation
Usage: Used after completing a contour that required
compensation
Syntax: G40 (typically followed by a linear move away
from the part)
Effect: Returns the tool path to exactly match the
programmed coordinates
G41: Tool Radius Compensation Left
Function: Offsets the tool path to the left of the
programmed path
Usage: When cutting along the outside of a profile with
the tool on the left side
Syntax: G41 D# (where D# is the tool diameter offset
number)
Effect: Shifts the tool path left by the radius of the tool
G42: Tool Radius Compensation Right
Function: Offsets the tool path to the right of the
programmed path
Usage: When cutting along the outside of a profile with
the tool on the right side
Syntax: G42 D# (where D# is the tool diameter offset
number)
Effect: Shifts the tool path right by the radius of the tool
G43: Tool Length Compensation Positive
Function: Applies a positive tool length offset to the Z-
axis
Usage: Standard for most milling operations to
compensate for tools of different lengths
Syntax: G43 H# (where H# is the tool length offset
number)
Effect: Adjusts the Z-axis position by adding the tool
length offset value
17.G54 TO G59-WORK OFFSET SYSTEM
G54 to G59 are G-code commands in CNC machining that
define work coordinate system offsets, setting the origin
of a workpiece relative to the machine’s absolute zero
(home position).
Purpose:
Allow machining of multiple parts or setups on the same
table by switching between predefined offsets.Ensure
toolpaths reference the correct part origin, improving
precision and efficiency.
How They Work:
Setup: Offset values (X, Y, Z, and sometimes A, B, C axes)
for G54-G59 are stored in the CNC controller, set via
probing, edge finders, or manual measurement.
Execution:
Calling G54 (e.g., G54 X0 Y0 Z0) shifts the machine’s
coordinate system to the G54 offset.Switch between G54-
G59 for different parts/fixtures in a single program.
Differences:
G54: Default offset, often used for the first or primary
setup.G55 to G59: Additional offsets for secondary
setups, fixtures, or parts.Some machines support
extended offsets (e.g., G54.1 P1), but G54-G59 are
universal.
Applications:
Multi-Part Machining: Use G54 for part 1, G55 for part 2,
etc.Fixtures: Assign offsets to different vises or
pallets.Production: Streamline repetitive jobs with saved
offsets.Pallet Changers: Common in automated systems
for high-volume production.
18.G76-FINE BORING CYCLE
Key Uses of Boring Bars in VMCs:
Enlarging and Refining Holes:
Boring bars are designed to enlarge and refine pre-
existing holes, allowing for precise control over the hole
diameter and surface finish.
Achieving High Precision:
Boring bars are used to achieve close tolerances and high
accuracy in hole diameter and concentricity, crucial for
many applications.
Internal Contour Machining:
They can be used to create internal contours and profiles
within holes, offering versatility beyond simple hole
enlargement.
19.G80-CANAL CYCLE OFF
20.G81-SINGLE PACK DRILL
21.G83-PACK DRILL CYCLE
22.G84-TAPPING CYCLE
Center Drilling(G81):
Purpose: To create a small, precise, cone-shaped hole on
the surface of a workpiece. This is essential for:
Guiding the main drill bit during drilling, ensuring
accuracy.
Supporting the lathe centers when turning parts between
centers.
Creating a guide for the tap.
Drilling(G83):
Purpose: To create a hole through a material, typically
metal, for various purposes like creating a passage,
fastening with screws or bolts, or for further processing.
Process: A drill bit, attached to a rotating drill, penetrates
the material, removing material to form the hole.
Tools: Drill bits, drill presses, and other drilling machines.
Tapping(G84):
Purpose: To create internal threads in a drilled hole,
enabling screws or bolts to be screwed into it.
Process: A tap, a tool with external threads, is rotated
into the drilled hole, cutting internal threads.
Tools: Taps, tapping machines, and hand-tapping
wrenches.
23.G90-ABSOLUTE POSITION
24.G91-INCREMENTAL POSITION
G90 (Absolute Positioning):
Coordinates are always referenced to the machine's
origin or a defined work offset.
Each movement is calculated from the absolute
coordinates provided, regardless of the tool's current
position.
Suitable for precision work where exact location relative
to the origin is critical.
G91 (Incremental Positioning):
Coordinates are relative to the tool's previous position.
Each movement is a distance from the last point, making
it ideal for repetitive patterns or relative movements.
Can be more efficient for programming sequential
movements or patterns.
25.G98-RETURN TO INTIAL POINT
26.G99-RETURN TO RETRACTION POINT
G98 returns the tool to the initial Z-axis
position before the canned cycle began,
while G99 returns it to the R-point (a
position defined within the canned
cycle).
G98 (Initial Plane Return):
The tool returns to the Z-axis position it was at
immediately before the canned cycle was initiated.
G99 (R-Plane Return):
The tool returns to the Z-axis position specified by the "R-
point" parameter within the canned cycle command.
M-CODE
In CNC programming, M-code, or miscellaneous code,
controls non-geometric functions on the machine,
complementing G-code which manages movements. M-
code handles things like spindle control (on/off,
direction), coolant control (on/off), tool changes, and
program flow. It's essentially the backbone of the
manufacturing process, enabling precise actions beyond
basic movements.
Here's a more detailed explanation:
1. What M-code is:
M-code is a type of command used in CNC (Computer
Numerical Control) programming.
It's used to control auxiliary functions or non-geometric
functions on a CNC machine, alongside G-code.
G-code primarily controls the movement of the cutting
tool, while M-code manages other operations like spindle
control, coolant, and tool changes.
2. Key Functions Controlled by M-code:
Spindle Control: Turning the spindle (the main rotating
part of the machine) on or off, and specifying its direction
of rotation (clockwise or counterclockwise).
Coolant Control: Turning coolant on or off (mist coolant,
flood coolant, etc.).
Tool Changes: Instructing the machine to change the
cutting tool during a program.
Program Flow: Controlling program execution, including
starting, stopping, and ending a program.
1.M00-PROGRAM STOP
2.M01-OPTIONAL STOP
3.M02-PROGRAMME END
1.M00-PROGRAM STOP
The M00 code in VMC (Vertical Machining Center)
programming is used to stop the program's execution and
the machine's operation. It's a mandatory stop command
that causes the CNC machine to halt all movement and
spindle activity, requiring manual intervention to restart.
This is different from the optional stop (M01), which only
stops if the optional stop switch is activated.
Purpose:
M00 serves as a "program stop" command, pausing the
CNC machine's operation and the current program
execution.
Effect:
When M00 is encountered in the program, the machine
will immediately stop its current operation (e.g., cutting,
drilling), halt the spindle, and wait for operator
intervention before resuming.
Application:
M00 is often used for tasks like manual tool changes,
adding tapping oil, or making manual adjustments to the
workpiece or machine setup.
M01-OPTIONAL STOP
In CNC programming, especially for Vertical Machining
Centers (VMCs), M01 is an optional program stop
command. It allows the machine operator to pause the
program execution at a specific point if the optional stop
button on the control panel is activated. This is useful for
pausing the program, making adjustments, or checking
the workpiece without stopping the entire process.
Here's a more detailed explanation:
Optional Stop:
The M01 command only stops the machine if the
optional stop button on the CNC control panel is
engaged.
Program Execution:
If the optional stop button is not active, the program will
continue running to the next M01 command or the end
of the program.
Operator Control:
The M01 command provides the operator with a way to
pause the machine at specific points in the program,
allowing for adjustments or inspections during the
machining process.
Purpose:
M01 is used when the operator needs to temporarily halt
the machine for a specific purpose, like checking the
workpiece, changing tools, or making adjustments to the
machining parameters.
M02-PROGRAMME END
In CNC programming, specifically for Vertical Machining
Centers (VMCS), M02 is an M-code that signifies the "End
of Program" command. When encountered in a program,
the CNC machine will halt execution and transition to the
MDI (Manual Data Input) mode, preparing for the next
program or manual operations.
Here's a more detailed explanation:
M02: End of Program:
This code indicates that the current program has reached
its conclusion.
No Rewinding:
Unlike the M30 code, M02 does not automatically rewind
the program to the beginning.
Transition to MDI:
After executing M02, the machine will switch from its
automatic program mode to the MDI mode, allowing for
manual input or the loading of a new program.
Program Restart:
When the machine is in MDI mode, the user can restart
the program from the beginning using Cycle Start or
press the "R" button in the Axis GUI if using Axis CNC
software.
Lines after M02:
Any lines of code that appear after M02 in the program
file will not be executed.
4.M03-SPINDLE ON CLOCKWISE
DIRECTION(CW)
5.M04-SPINDLE ON COUNTER
CLOCKWISE DIRECTION(CW)
6.M05-SPINDLE STOP
M03-SPINDLE ON CLOCKWISE
DIRECTION(CW)
In the context of VMCs (Vertical Machining Centers), M03
is the code that activates the spindle to rotate in a
clockwise direction (CW). It's a crucial command for
initiating the cutting process.
Here's a more detailed explanation:
Purpose:
M03 is used to start the spindle motor and cause it to
turn clockwise at the speed specified by the S command
(e.g., S1000 for 1000 RPM).
Usage:
It's typically used in a G-code program block along with
the S command to set the desired spindle speed. For
example: G01 X100 Y50 S2000 M03.
M04-SPINDLE ON COUNTER CLOCKWISE
DIRECTION(CW)
In the context of Vertical Machining Centers (VMCs), the
M04 code signifies spindle rotation in the counter-
clockwise direction. It's used to initiate the spindle at the
last programmed RPM, but in the reverse (counter-
clockwise) direction.
Here's a more detailed explanation:
M03 vs. M04:
M03 initiates spindle rotation in the clockwise direction
(forward), while M04 initiates it in the counter-clockwise
direction (reverse).
Spindle Speed:
The specific RPM for the spindle is set using the "S"
parameter before the M04 code. For example, M04
S2000 would set the spindle to rotate counter-clockwise
at 2000 RPM.
Purpose:
M04 is often used in specific machining operations like
tapping, where the reverse direction is needed for the
tapping process.
M05-SPINDLE STOP
In the context of a CNC Vertical Machining Center (VMC),
the M05 code is a spindle stop command. It instructs the
machine to halt the rotation of the spindle, which is the
component that holds and spins the cutting tools. This
command is used to stop the spindle for tasks like tool
changes or when the cutting process is complete.
6.M06-TOOL CHANGE
7.M08-COOLANT ON
8.M09-COOLANT OFF
M06-TOOL CHANGE
In VMC (Vertical Machining Center) programming, M06 is
the code used to trigger a tool change. This command
instructs the machine to swap the cutting tool currently
in the spindle with a different tool, which is selected by
the program or the operator.
Explanation:
M06:
This is the standard M-code for tool change on most CNC
machines, including VMCS.
ATC (Automatic Tool Changer):
VMCS typically have an ATC, which is a system that
automatically changes tools based on the M06 command
and the selected tool number.
Tool Selection:
The tool to be changed is often specified with the "T"
word (e.g., T1, T5, etc.). The T word selects the tool to be
brought into position for the change, and the M06
command initiates the actual swap.
M08-COOLANT ON
In the context of CNC programming, M08 is the M-code
command used to turn on the flood coolant on a Vertical
Machining Center (VMC). It's a crucial command for
keeping the cutting tool cool and lubricating the part
during machining, as well as helping to evacuate chips
M09-COOLANT OFF
In the context of CNC programming, M09 is an M-code
command used to turn off coolant on a Vertical
Machining Center (VMC). It's a standard command for
disabling coolant systems.
9.M19-SPINDLE LOCK
10.M20-SPINDLE UNLOCK
M19-SPINDLE LOCK
In the context of CNC programming, M19 is a code used
to orient the spindle to a specific angular position. This is
often done before a tool change to ensure the tool is in a
desired orientation, or for other specialized machining
operations.
Elaboration:
Spindle Orientation:
M19 is a command that instructs the CNC machine to
stop the spindle and position it to a specific angle, as
defined by parameters within the code.
Tool Change:
It's commonly used before a tool change (M06) to align
the spindle so that the tool changer can properly pick up
or insert the new tool,
M20-SPINDLE UNLOCK
In the context of CNC machines, M20 is an M-code that
typically means "Spindle Orientation Cancel" or "Reset
M19". It essentially reverts the spindle to its default
position or stops any previous orientation command.
Elaboration:
M19 (Oriented Spindle Stop):
The M19 code is used to stop the spindle at a specific,
pre-defined position on the spindle's rotation cycle. This
is often used for tool changes or other operations where
precise spindle orientation is needed.
M20 (Spindle Orientation Cancel/Reset):
The M20 code cancels the effect of M19 and returns the
spindle to its default, or non-oriented, state. This means
the spindle will not be stopped at a specific position until
another M19 command is executed.
11.M30-PROGRAM END AND RESET
12.M98-SUB-PROGRAM CALL
13.M99-SUB-PROGRAM END
M30-PROGRAM END AND RESET
In the context of a Vertical Machining Center (VMC), M30
is a CNC code that signals the end of the program and
resets the machine to its initial state. It effectively stops
the program execution and then rewinds to the
beginning of the program file.
Explanation:
M30: End of Program:
This code tells the VMC that the current machining
operation has concluded.
Reset:
After signaling the end of the program, M30 also initiates
a reset, returning the machine to its initial state, ready
for the next program.
Rewind:
M30 ensures that the program file is rewound to the
beginning, so the next time the program is run, it starts
from the top,
M98-SUB-PROGRAM CALL
In VMC (Vertical Machining Center) programming, M98 is
a G-code command used to call a subprogram. It allows
you to execute a separate set of instructions within your
main program
Calling the Subprogram:
The M98 command initiates the call to a subprogram.
It's followed by a program number (e.g., M98 P1000)
which identifies the subprogram to be executed.
You can optionally include a loop count (L) to specify how
many times the subprogram should be executed.
Subprogram Execution:
Once the VMC encounters M98, it will jump to the
specified subprogram.
Returning to the Main Program:
The subprogram is defined by the instructions it contains.
When the subprogram is finished, it will typically have an
M99 command which instructs the VMC to return to the
main program where it left off.
M99-SUB-PROGRAM END
In the context of Vertical Machining Centers (VMCs) and
CNC programming, M99 is the command to return to the
main program after executing a subprogram or loop back
to the beginning of the program. It essentially signals the
end of a subprogram or initiates a loop.
Returning from Subprograms:
When a main program calls a subprogram (using M98),
the execution jumps to the subprogram.
Once the subprogram finishes, the M99 command at the
end of the subprogram instructs the machine to return to
the line immediately following the M98 call in the main
program.