41. CNC Programming

• We need to be able to direct the position of the cutting tool. As the tool moves we will cut metal (or perform other processes).

• Obviously if we plan to indicate positions we will need to coordinate systems.

• The coordinates are almost exclusively Cartesian and the origin is on the workpiece.

• For a lathe, the infeed/radial axis is the x-axis, the carriage/length axis is the z-axis. There is no need for a y-axis because the tool moves in a plane through the rotational center of the work. Coordinates on the work piece shown below are relative to the work.

• For a tool with a vertical spindle the x-axis is the cross feed, the y-axis is the in-feed, and the z-axis is parallel to the tool axis (perpendicular to the table). Coordinates on the work piece shown below relative to the work.

• For a tool with a horizontal spindle the x-axis is across the table, the y-axis is down, and the z-axis is out. Coordinates on the work piece shown below relative to the work.

• Some common programming languages include, (note: standards are indicated with an *)

ADAPT: (ADaptation of APT) A subset of APT

*APT: (Automatically Programmed Tool) A geometry based language that is compiled into an executable program.

AUTOSPOT: A 2D language developed by IBM. Later combined with ADAPT.

COMPACT/COMPACTII: A higher level language designed for geometrical definitions of parts, but it doesn’t require compilation.

EXAPT: A European flavor of APT

*G-Codes (EIA RS-274 G&M codes)

MAPT: (Microcomputer APT): Yet another version of APT

UNIAPT: APT controller for smaller computer systems

Other Proprietary languages

• These languages have many similarities, but the syntax varies.

41.1 G-Codes

• This language was originally designed to be read from paper tapes. As a result it is quite simple.

• The language directs tool motion with simple commands

• Note, I show programs with spaces to improve readability, but these are not necessary.

• A basic list of ‘G’ operation codes is given below. These direct motion of the tool.

• A program is given for the sample part below. Complete the last few lines.

• The following is an example of circular interpolation. This is valid for both milling and turning. Note that here we move to the start point, the command indicates the direction (clockwise or counterclockwise). The I, J values indicate the center of rotation, and the X, Y values indicate the point to stop at. We can also cut circular paths on other planes by resetting the cutting planes (G17, G18, G19).

• When cutting, it is useful to change our point of reference. When doing mathematics we tend to dimension relative to a main origin (absolute). In fact a machine will need to have coordinates specified with reference to a main origin. But when we examine parts we tend to refer to local origins for features. (Consider how you dimension details on a drawing.) These relative points refer to as local origins. We can also do moves as distances to the next point.

• When using the prolight mill we can add program elements to request that an external device (ie robot) load or unload parts. We will assume that the robot has been connected to the robotic interface port available. This port has four inputs and two outputs. The example below assumes that the input #1 indicates a part has been dropped off and the mill can start. Output #1 will be turned on to request that the robot pick up a part and load new stock.

• In previous examples we calculated the cutter offsets by hand. Modern NC machines keep a record of the tool geometry. This can then be used to automatically calculate offsets (you don’t need to put the tool size in the program).

• The best way to think of tool compensation is when cutting a profile, should we be to the left or right of the line.

• In the previous example we notice how the shape is distorted by how the cutter navigates the corners. There are additional commands to help with these problems.

• Typical commanded cycles include,

rectangular pocket milling

circular pocket milling

slot or elongated hole milling

peck drilling

tapping

Problem 41.1 Develop the part program for the component shown below.

41.2 APT

• This language allows tools to be programmed using geometrical shapes. This puts less burden on the programmer to do calculations in their heads.

• APT programs must be converted into low level programs, such as G-codes.

• An example of an APT program is given below.

• Some samples of the geometrical and motion commands follow. These are not complete, but are a reasonable subset.

• GEOMETRY: The simplest geometrical construction in APT is a point

p=POINT/x,y,z: a cartesian point

p=POINT/l1,l2: intersection of two lines

p=POINT/c: the center of a circle

p=POINT/YLARGE,INTOF,l,c: the largest y intersection of a line and a circle

*Note: we can use YSMALL,XLARGE,XSMALL in place of YLARGE

• GEOMETRY: Lines are one of the next simplest definitions,

l=LINE/x1,y1,z1,x2,y2,z2: endpoint cartesian components

l=LINE/p1,p2: endpoints

l=LINE/p,PARLEL,l: a line through a point and parallel to another line

l=LINE/p,PERPTO,l: a line through a point and perpendicular to a line

l=LINE/p,LEFT,TANTO,c: a line from a point, to a left tangency point on a circle

l=LINE/p,RIGHT,TANTO,c: a line from a point, to a right tangency point on a circle

l=LINE/LEFT,TANTO,c1,LEFT,TANTO,c2: defined by tangents to two circles

l=LINE/LEFT,TANTO,c1,RIGHT,TANTO,c2: defined by tangents to two circles

l=LINE/RIGHT,TANTO,c1,LEFT,TANTO,c2: defined by tangents to two circles

l=LINE/RIGHT,TANTO,c1,RIGHT,TANTO,c2: defined by tangents to two circles

• GEOMETRY: Circles are very useful for constructing geometries

c=CIRCLE/x,y,z,r: a center and radius

c=CIRCLE/CENTER,p,RADIUS,r: a center point and a radius

c=CIRCLE/CENTER,p,TANTO,l: a center and a tangency to an outside line

c=CIRCLE/p1,p2,p3: defined by three points on the circumference

c=CIRCLE/YLARGE,l1,YLARGE,l2,RADIUS,r: tangency to two lines and radius

*Note: we can use YSMALL,XLARGE,XSMALL in place of YLARGE

• GEOMETRY: More complex geometric constructions are possible

PLANE/: defines a plane

QUADRIC/a,b,c,d,e,f,g,h,i,j: define a polynomial using values

GCONIC/a,b,c,d,e,f: define a conic by equation coefficients

LCONIC/p1,p2,...: defines a conic by lofting (splining) points

RLDSRF/: a ruled surface made of two splines

POLCON/: define a surface using cross sections

PATERN/: will repeat a motion in a linear or circular array

• Once we have constructed points, lines and circles we can then proceed to direct the tool to follow the path.

• MOTION: We can use the basic commands to follow the specified geometry

FROM/p: specify a start point

FROM/x,y,z: specify a start point

GOTO/p: move to a final point

GOTO/x,y,z: move to a final point

GOTO/TO,p: move until the tool touches a point

GOTO/TO,l: move until the tool touches a line

GOTO/TO,c: move until the tool touches a circle

GOLFT/l1,TO,l2: go on the left of l1 until the tool touches l2

GORGT/l1,TO,l2: go on the right of l1 until the tool touches l2

GOBACK/l1,TO,l2: reverses direction along l1 to l2

GOBACK/l1,TO,c1: reverses direction along l1 to c1

GOUP/l1,TO,l2: goes up along l1 to l2

GODOWN/1l,TO,l2: goes down along l1 to l2

GODLTA/x,y,z: does a relative move

Note: TO can be replaced with PAST, ON to change whether the tool goes past the structure, or the center stops on the structure.

• MOTION: The following commands will create complex motion of the tool

POCKET/: will cut a pocket

PSIS/: will call for the part surface

• As would be expected, we need to be able to issue commands to control the machine.

• CONTROL: The following instructions will control the machine outside the expected cutting tool motion.

CUTTER/n1,n2: defines diameter n1 and radius n2 of cutter

MACHIN/n,m: uses a post processor for machine ‘n’, and version ‘m’

COOL/ANT/n: either MIST, FLOOD or OFF

TURRET/n: sets tool turret to new position

TOLER/n: sets a tolerance band for cutting

FEDRAT/n: sets a feedrate n

SPINDL/n,CW: specifies n rpm and direction of spindle

• We can also include some program elements that are only used for programming

• PROGRAM: The following statements are programming support instructions

REMARK: starts a comment line that is not interpreted

$$: also allows comments, but after other statements

NOPOST: turns off the post processor that would generate cutter paths

CLPRNT: prints a sequential history of the cutter center location

SQRTF(n): calculates the floating point square root

FINI: stop program

PARTNO/n: allows the user to specify the part name

LOOPST and LOOPND: loop instructions

RESERV/n,m: defines an array of size ‘n’ by ‘m’

JUMPTO/n: jump to line number

• Note: variables can also be defined and basic mathematical operations can be performed.

• Note: macro functions are also available.

41.3 Proprietary CNC Codes

• NC code Example (for the Dyna Milling Machine)

41.4 Graphical Part Programming

• Basically,

1. Part geometry is entered in 2D or 3D.

2. Tool geometry and machine tool type are entered.

3. Speeds and feeds are entered or calculated based on tool and work material.

• These programs are usually built into better CAD systems or are available as stand alone software

• Some machine tools have these programmers built into the controller.

41.5 CNC Cutter Paths

• When we have simple features, paths are easy to generate. These features include,

steps

pockets

holes

etc.

• Typically paths for these will repeat as shown below,

• For complex surfaces we want to contour appropriately. These surfaces will almost always be represented with spline patches.

• Recall that a spline patch can be represented parametrically

• A simple algorithm to cut the surface is shown below.

41.6 CNC Controllers

• NC control programs are essentially quite simple. The source code for a basic controller is given below.

41.7 Problems

Problem 41.2 Examine the part below. It is set up so that the origin is at the bottom left. The cutting tool has a diameter of 1/2”, and the material is 1/8” thick.

a) Write the equations needed to find the tangency point on the top left of the piece.

b) Develop an NC program to mill the part. The program should be complete and include all instructions required. If necessary, assume a location for the tangency point.

Answer 41.2 a)

b)

Problem 41.3 Examine the part below. It is set up so that the origin is at the bottom left corner. The cutting tool has a diameter of 1/2”, and the material is 1/8” thick. Develop an NC program to mill the part. The program should be complete and include all instructions required.