Drexel Autonomous systems lab

Lesson 1
Basic Machine code

Return DASL -131 Main


FIGURE 1

Lesson 1 covers the basic G and M codes used in programming Computer Numeric Control (CNC)  machines to operate properly. Figure 1 is an example of Numeric Control (.NC) file used to command the machine to move in XYZ axis and perform other functions. The following are the topics to be covered.

Section 1 - Code Structure
Section 2 - G codes
Section 3 - M codes
Section 4 - Other or Reference Codes

 

Section 1 - Code Structure 

CNC codes gives the machine specific instructions to move and operate different functions of the machine.  When you first look a NC code you will most likely come across the header.  The header should be commented out denoted by ().  Within these () should have PROGRAM NAME, DATE GENERATED, AUTHOR, AND TOOL.  This tile format may change later for MasterCAM X2 Automated generation of code. Note the percent sign % defines start and end of program.

Example 1:
%
(PROGRAM NAME - EX1)
(DATE = DD-MM-YY - 25-17-08)
(1/4 FLAT ENDMILL)
%

Following the header the "meat" of the code will start.  Each line is started by a line number.  Line numbers a very important when coming to debugging code.  Line number start with N followed by a number. For a rule of thumb the user should skip numbers or count by tens just encase a line needs to be created. For instance N0 N2 N4 N6 is an increment of 2 and N0 N10 N20 N30 is and increment of 10. There a lots of different ways to do this so it is preference of the user. Note Header is not numbered.

Section 2 - G codes

  G codes operate tool path generation/parameters or positioning of the tool. The following is a list of basic G codes with descriptions.

G00 - Rapid traverse: Moves X, Y, Z axis at a fast rate (machine default), should typically be used above the part.

G01 - Liner Interpolation: Moves X, Y, Z axis at a user rate (reference Feed rate), should be used for cutting operations.

G02 - CW Circular Interpolation: Moves tool in an X and Y combination to make a helical pass at specified feed rate.  (reference R)

G03 - CCW Circular Interpolation: (reference R)

G20 - Programming in Inches: Initializes the machine to traverse in X, Y, Z in units of inches.

G21 - Programming in Millimeters: Initializes the machine to traverse in X, Y, Z in units of millimeters.

G90 - Absolute Programming coordinates:  Initializes the machine to reference all measurements from Cartesian zero.

Example 2: When generating the tool path the tool diameter needs be taken into account. For this example a 1/2 inch flat end mill will be used.  The machine will cut a Island out of a 1.5 x 2.5 piece of stock to match the below dimensions.


FIGURE 2

%
(PROGRAM NAME - EX2)
(DATE = DD-MM-YY - 25-17-08)
(1/2 FLAT ENDMILL)
N000 G20
N002 G90
N004 G01 X0 Y0 Z0
N006 Y1.5
N008 X1.75
N010 G02 X2.25 Y.75 R.75
N012 G01 Y0
N014 X0
%

Install NCPlot v1.2 To test this code. Copy and paste the Code into the left window.  Then press the Plot Program Button shown in figure 3. Notice it plots the tool path not the geometry shown in the drawing.  Install CNCSimulator to see the the tool path but also see the desired dimensions cut.  In order to accomplish a "cut" add N005 Z-.0625 to code shown in example 3. 


FIGURE 3
 

Example 3:
%
(PROGRAM NAME - EX3)
(DATE = DD-MM-YY - 25-17-08)
(1/2 FLAT ENDMILL)
N000 G20
N002 G90
N004 G01 X0 Y0 Z0
N005 Z-.0625
N006 Y1.5
N008 X1.75
N010 G02 X2.25 Y.75 R.75
N012 G01 Y0
N014 X0
%

In CNCSimulator Copy and paste example 3 code into the blue panel and run.   Follow arrows to run program in figure 4.


FIGURE 4

Section 3 - M codes

M codes operate the global machine functions. The following is a list of basic M codes with descriptions.

M03 - Spindle ON Clockwise: Turns the motor ON at a specified speed in ft/min (reference S).

M05 - Spindle OFF: Turns motor OFF.

M08 - Coolant/Flood ON: Turns coolant pump ON.

M09 - Coolant/Flood OFF: Turns coolant pump OFF.

M30 - End Program/Reset to Start: This code is located at end of program. It ends program and resets the code to beginning for another execution.

Example 4: Below is the NC code from example 3 edited for proper machine use.  The code turns spindle and coolant ON and OFF. Also terminates and resets the code at end.

%
(PROGRAM NAME - EX4)
(DATE = DD-MM-YY - 25-17-08)
(1/2 FLAT ENDMILL)
N000 G20
N002 G90
N003 S1500 M3 M8
N004 G01 X0 Y0 Z0 F5
N005 Z-.0625
N006 Y1.5
N008 X1.75
N010 G02 X2.25 Y.75 R.75
N012 G01 Y0
N014 X0
N015 M5 M9
N016 M30
%
 

Section 4 - Other or Reference Codes

Feed Rate (F)
    Refer to section Lesson 3 (Not available)

Spindle Speed (S)
    Refer to section Lesson 3 (Not available)

Return DASL -131 Main
 

Valid XHTML | Valid CSS | Copyright Roy J. Gross | Design by SmallPark