Você está na página 1de 46

5.

0 - CNC Programming language


2011 Autodesk

Review: CNC process


Solid Model
CAM Application

Post Process

Generate toolpaths
Verify
Writes G-code file

Run G-code file on CNC


machine

Solid Model

CAM
(Toolpath |
Verify | Post
Process)
(G-Code File)

CNC Machine

2011 Autodesk

%
O01111 (FACE
(T2 D=0.375 )
N10 G90 G94 G17
N15 G20
N20 G28 G91 Z0.

Lesson Overview

5.1 - CNC Language & Structure


5.2 - CNC Editor
5.3 - Alphabetic & Special Character Codes
5.4 - G&M Codes
5.5 - Select G codes in detail
5.6 - Canned Cycles

2011 Autodesk

objectives
List sequence of operations in a typical CNC program.
List most commonly used G/M-codes and their meaning.
List most commonly used special characters and their purpose.
Describe the organization, motion, and actions of a simple CNC
program.

2011 Autodesk

5.1 - CNC language


CNC Machines are accurate and powerful
industrial robots.
Language: RS-274D set by Electronics Industry
Association (EIA).
Developed in 1960s when computers had little
memory.
Slang: G-code, because many codes begin with
letter G.

2011 Autodesk

%
O62806 (FACE-CONTOUR)
N10 G90 G94
N15 G20
N20 G28 G91 Z0.
N25 G90
N30 M09
N35 T1 M06
N40 T3
N45 S8149 M03
N50 G54
N55 M08
N60 G00 X4.495 Y-3.9294
N65 G43 Z0.8 H01
N70 Z0.2
N75 G01 Z0.0425 F20.
N80 G18 G03 X4.4575 Z0.005 I0.0375
N85 G01 X-0.2575 F32.59
N90 X-0.436
N95 G17 G02 Y-3.7486 J0.0904
N100 G01 X4.636
N105 X4.6375
N110 G03 Y-3.5677 J0.0904
N115 G01 X-0.4375
N120 G02 Y-3.3869 J0.0904
N125 G01 X4.6375
N130 G03 Y-3.2061 J0.0904
N135 G01 X-0.4375
N140 G02 Y-3.0253 J0.0904
N145 G01 X4.6375

Cnc language
Very efficient and compact language.
Standardizedsort of.

Not strictly enforced.


Many variations due to different manufacturers and machine options.

Most common dialect: Fanuc

Rhymes with Panic


A Japanese company.

About 100 words.


About 30 used often.

2011 Autodesk

CNC Language
G-code is a simple ASCII text file.
Can be read/edited in any text editor.
You DO NOT need to learn every code or how to write program by
hand.

CAM Post Processor should produce perfect code.

CAM software should do it all, but


It helps to know the most common codes.

Work more efficiently.


Credibility with subordinates.

2011 Autodesk

CNC Program structure


Instructions are performed in order written.
Reads like a book:

Left -> Right


Top -> Down

Each line (row) is called a Block.


Arranged in predictable sequence that promotes safety and
readability.

2011 Autodesk

Cnc program structure

Typical sequence shown.


Most simple program:
One tool.
One operation.

2011 Autodesk

1)
2)
3)
4)
5)
6)
7)
8)
9)
10)

Program Start.
Load Tool.
Spindle ON.
Coolant ON.
Rapid above part.
Machining operation.
Coolant OFF.
Spindle OFF.
Move to Safe Position.
End Program.

Example CNC Program


Block
%
O0001 (PROJECT1)
(T1 0.25 END MILL)
N1 G17 G20 G40 G49 G80 G90
N2 T1 M6
N3 S9200 M3
N4 G54
N5 M8
N6 G00 X-0.025 Y-0.275
N7 G43 Z1. H1
N8 Z0.1
N9 G01 Z-0.1 F18.
N10 G41 Y0.1 D1 F36.
N11 Y2.025
N12 X2.025
N13 Y-0.025
N14 X-0.025
N15 G40 X-0.4
N16 G00 Z1.
Figure 1: Simple CNC Program

2011 Autodesk

Description
Start of program.
Program number (Program Name).
Tool description for operator.
Safety block to ensure machine is in safe mode.
Load Tool #1.
Spindle Speed 9200 RPM, On CW.
Use Fixture Offset #1.
Coolant On.
Rapid above part.
Rapid to safe plane, use Tool Length Offset #1.
Rapid to feed plane.
Line move to cutting depth at 18 IPM.
CDC Left, Lead in line, Dia. Offset #1, 36 IPM.
Line move.
Line move.
Line move.
Line move.
Turn CDC off with lead-out move.
Rapid to safe plane.

Purpose
Start
Program

Change
Tool
Move
To
Position

Machine
Contour

Example CNC Program


Block
N17 M5
N18 M9
(T2 0.25 DRILL)
N19 T2 M6
N20 S3820 M3
N21 M8
N22 X1. Y1.
N23 G43 Z1. H2
N24 Z0.25
N25 G98 G81 Z-0.325 R0.1
F12.
N26 G80
N27 Z1.
N28 M5
N29 M9
N30 G91 G28 Z0
N31 G91 G28 X0 Y0
N32 G90
N33 M30
%
Figure 1: Simple CNC Program

2011 Autodesk

Description
Spindle Off.
Coolant Off.
Tool description for operator.
Load Tool #2.
Spindle Speed 3820 RPM, On CW.
Coolant On.
Rapid above hole.
Rapid to safe plane, use Tool Length Offset 2.
Rapid to feed plane.
Drill hole (canned) cycle, Depth Z-.325, F12.
Cancel drill cycle.
Rapid to safe plane.
Spindle Off.
Coolant Off.
Return to machine Home position in Z.
Return to machine Home position in XY.
Reset to absolute positioning mode (for safety).
Reset program to beginning.
End Program.

Purpose
Change
Tool

Move
To
Position
Drill
Hole
End
Program

5.2 - Cnc editor

A CNC Editor is a ASCII* text editor and CNC machine


communications application.

View/Edit G-code file.


Backplot G-code file.
Transmit via RS-232 Serial communications to machine.

*ASCII (American Standard for Information Interchange) is used to


represent text in computers and communications equipment.

2011 Autodesk

Hsmworks editor Interface

2011 Autodesk

5.3 Alphabetic codes/Special characters

ABCDEFGHIJKLMNOPQRSTUVWXYZ
% () / ;

2011 Autodesk

Alphabetic codes/Special characters


Every letter of alphabet is used.
Some used more than once.

Meaning changes depending on G-code in same block.


Example: G02 Y-3.3869 I0.0904 J0.0904

I, J = Arc Center data

Example: G83 Z-.62 F15. R.05 I.15 J.01 K.005

2011 Autodesk

I, J = Peck drill parameters

Alphabetical codes (most common)


Code
A
B
C
D
F
G
H
I
J
K
M
N
O

Meaning
Rotation about X-axis.
Rotation about Y-axis.
Rotation about Z-axis.
Cutter diameter compensation (CDC) offset address.
Feed rate.
G-Code (preparatory code).
Tool length offset (TLO).
Arc center X-vector, also used in drill cycles.
Arc center Y-vector, also used in drill cycles.
Arc center Z-vector, also used in drill cycles.
M-Code (miscellaneous code).
Block Number.
Program Number.

Table 3: Common Alphanumeric Address Codes

2011 Autodesk

Alphabetical codes (most common)


Code
P
Q
R
S
T
X
Y
Z

Meaning
Dwell time.
Used in drill cycles.
Arc radius, also used in drill cycles.
Spindle speed in RPM.
Tool number.
X-coordinate.
Y-coordinate.
Z-coordinate.

Table 3: Common Alphanumeric Address Codes (Continued)

2011 Autodesk

Special characters
%
Marks start and end of program.
()
Operator comments.
/
Block Delete. This line ignored when the Block Delete
switch* is ON.
;
End of Block (line).

*This is a toggle switch on the CNC Control labeled, Block


Delete.

2011 Autodesk

modality
Modal: Remains in effect until cancelled or superseded by
another code.
Non-Modal: Active only in current block.

2011 Autodesk

5.4 - G & M codes

G1 G2 G3 G4 G28 G40 G41 G42 G43


G54 G55 G56 G57 G58 G59 G80 G81
G82 G83 G84 G90 G91 G98 G99
M0 M1 M2 M3 M4 M5 M6 M8 M9 M30

2011 Autodesk

G&M codes
G-code syntax
Overview of common g-codes

Only the ones you should know.

M-codes

Purpose of M-codes.
M-codes you should know.

2011 Autodesk

G-Codes
Begin with letter G.
Called Preparatory codes because they prepare machine for
certain type of motion.
Followed by 1 or 2 digit number.
Older machines required leading zeros:

Example: G01

Newer machines do not:

Example: G1

2011 Autodesk

G-Codes (Most common)


Code
G0
G1
G2
G3
G4
G28
G40
G41
G42
G43
G54
G55
G56

Meaning
Rapid motion. Positions machine for non-milling
moves.
Line motion at a specified feed rate.
Clockwise arc.
Counterclockwise arc.
Dwell.
Return to machine home position.
Cutter Diameter Compensation (CDC) off.
Cutter Diameter Compensation (CDC) left.
Cutter Diameter Compensation (CDC) right.
Tool length offset (TLO).
Fixture Offset #1.
Fixture Offset #2.
Fixture Offset #3.

Table 1: Common G-Codes and their meaning.


2011 Autodesk

G-Codes (Most common)


Code

Meaning

G57

Fixture Offset #4.

G58

Fixture Offset #5.

G59

Fixture Offset #6.

G80

Cancel drill cycle.

G81

Simple drill cycle.

G82

Simple drill cycle with dwell.

G83

Peck drill cycle.

G84

Tap cycle.

G90

Absolute coordinate programming mode.

G91

Incremental coordinate programming mode.

G98

Drill cycle return to Initial point (R).

G99

Drill cycle return to Reference plane (last Z Height)

Table 1: Common G-Codes and their meaning (Continued)

2011 Autodesk

M-Codes
Begin with the letter M.
Called Miscellaneous codes because they control machine
auxiliary options:

Coolant.
Spindle direction.

Followed by 1 or 2 digit number.


Only one M-code per block of code.

2011 Autodesk

M-codes (most common)


Code

Meaning

M0

Program stop. Press Cycle Start button to continue.

M1

Optional stop. Only executed if Op Stop switch on the CNC control is


turned ON.

M2
M3
M4
M5
M6
M8
M9
M30

End of program.
Spindle on Clockwise.
Spindle on Counterclockwise.
Spindle stop.
Change tool.
Coolant on.
Coolant off.
End program and press Cycle Start to run it again.

Table 2: Common M-Codes

2011 Autodesk

5.5 - Select G-codes (in detail)

G0 G1 G2 G3
G17 G18 G19
G43 G40 G41 G42
G54-G59

2011 Autodesk

Motion
Planes
Tool Offsets
Fixture Offsets

G-codes (g0 - rapid)


Commands machine to move as fast as possible.
Caution: G0 does not move in a straight line.

Each axis driven at max rate independently.


Result: Dogleg move.

2011 Autodesk

G-codes (g1 - linear)


Moves machine in a straight line at a programmed feed rate.
Example: G1 X1. Y1.1255 F32.

Read: Move in straight line from current position to X1. Y1.1255


at a feed rate of 32 inches per minute.

2011 Autodesk

G-codes (g2/g3)
G2 = Clockwise arc.
G3 = Counterclockwise arc.
Arcs must line in a major plane (XY, XZ, YZ).
I,J are incremental distance are incremental distance arc start to
center.

2011 Autodesk

G-Codes (G17/g18/g19)
Mostly for 3D machining
G17 = XY Plane
G18 = XZ Plane
G19 = YZ Plane

2011 Autodesk

G-codes (G40/G41/G42)

Cutter diameter compensation.


A fudge factor used to compensate for tool wear and deflection.
A key to high precision machining!
Highly restrictive in its use (see Lesson 6: 2D Toolpaths).
G40 = OFF
G41 = LEFT
G42 = RIGHT

2011 Autodesk

G-codes (G43)

Tool length compensation.


Adjusts for different length tools.
Used with a H register.
Example: G43 H1 Z1.
Read: Move to Z1. taking into account the tool length stored in
register H1.
H1 register is set by machine tool operator (See Lesson 5: Set
Tool Length Offset).

2011 Autodesk

G-codes (g54 G59)


Work Coordinate Offset (WCS).
Call a machine WCS register.
XY shifts CNC from Machine Coordinates to CNC program
coordinates.
Z along with TLO shifts CNC from Machine Coordinates to CNC
program coordinates, taking into account each tools unique
length (how far it extends from machine spindle face).

2011 Autodesk

5.6 - Canned cycles


Special codes that act like a Macro or subprogram.
Used for hole making
One block of code may command many
moves.

Makes programs much easier to read and debug.

2011 Autodesk

Canned cycle vs. expanded code


Canned Cycle
N70 G98 G83 X1. Y1. Z-1.04 R0.06 Q0.15 P0 F9.
N75 G80

2011 Autodesk

Equivalent Motion: Expanded


Code
N70 Z0.06
N75 Z0.04
N80 G01 Z-0.19 F9.
N85 G00 Z0.06
N90 Z-0.11
N95 G01 Z-0.34
N100 G00 Z0.06
N105 Z-0.26
N110 G01 Z-0.49.
N115 G00 Z0.06
N120 Z-0.41
N125 G01 Z-0.64.
N130 G00 Z0.06
N135 Z-0.56
N140 G01 Z-0.79
N145 G00 Z0.06
N150 Z-0.71
N155 G01 Z-0.94.
N160 G00 Z0.06
N165 Z-0.86
N170 G01 Z-1.04.
N175 G00 Z0.25

G-codes (G81)

Simple drill cycle.


Drill in/Rapid out.
Example: G98 G81 X.5 Y.5 Z-1. R.1 F9.5
R is rapid plane (sets retract Z).
G98/G99 controls how much tool retracts between holes.
Read: Go to X.5, Y.5, Z.1 (set by R.1) and drill to depth Z-1. at a
feed rate of 9.5 in/min.

2011 Autodesk

G-codes (g82)
Spot drill cycle.
Same as drill cycle but with dwell to produce a clean face, set by
P-value.
Example: G98 G82 X.5 Y.5 Z-.0925 P.1 R.1 F9.5
P.1 = .1 second dwell after reaching Z-.0925 then rapid retract.

2011 Autodesk

G-codes (G84)
Tapping cycle.
Feed rate is determined by spindle speed and thread lead.
Many machines have rigid tapping.

Can tap on machine without special attachments.


Spindle rotation precisely controlled by servo.
Will reverse at hole bottom and back out again.

2011 Autodesk

G-codes (g90)
Absolute positioning mode.
All CAM-generated programs positions should be in Absolute
mode.

2011 Autodesk

G-codes (G91)
Incremental positioning.
Only has one purpose with CAM-generated programs: fully
retract spindle in XY or Z.
Example:

G91 G28 Z0. (RETRACT IN Z)


G90 (RESET TO ABSOLUTE)

2011 Autodesk

G-CODES (G98)
Used in drill cycle to control
clamp clearing.
Commands tool to jump to
previous Z (Initial Rapid
Height) between holes.

2011 Autodesk

G-codes (g99)
Used in drill cycle to control
clamp clearing.
Commands tool to jump to Z
set by R-value (Rapid Height)
between holes.

2011 Autodesk

summary

CNC Program is called a G-code file.


A simple ASCII character file.
Can be read in any text editor.
Fanuc is common standard.
Programs should follow a predictable specific sequence of events.
G-codes = Preparatory commands.
M-codes = Miscellaneous commands.

2011 Autodesk

summary

Alphabetic address codes:

Can have different meanings depending on which G-code


accompanied by.

Special characters (see list).


Canned Cycles (G80-G84) work like a macro.
G0 is rapid (not necessarily a straight line).
G1 is straight line move at programmed feed rate.

2011 Autodesk

summary
G2 is Clockwise arc.
G3 is Counterclockwise arc.
CAM software should output absolutely edit-free code.

If not -contact the manufacturer.

You should know the most commonly used codes so you can
work efficiently.

2011 Autodesk

Você também pode gostar