EditNC - CNC Program Editor and Backplotter

Copyright © 2017 NFR Partners Inc.

EditNC by NFR Partners


What is CNC?

CNC stands for Computer Numerical Control and refers to the operation of a machine tool via motors, switches, and so on, with a computer controlling the whole shebang. The tool itself may be as small as a benchtop lathe or as large as the gantry mills used to machine airplane wing spars. If you really needed an answer to this question, then you probably won't be very interested in the rest of this.

Back to Top

What is a G-code?

G-Codes are simply commands. They are usually expressed as the letter G following by some digits, for example G1, G2, and G3. G1 orders the machine to perform a straight-line move, G2 orders a clockwise arc or circle, and G3 orders a counterclockwise arc or circle. Address words usually accompany G-codes to supply necessary information to complete the command.

Back to Top

Can I get a bit more on G-codes?

G0 is generally used to denote a rapid traverse. For example, the command G0 X5.0 Z3.5 would cause the tool to move to an X position on 5.0 and a Z position of 3.5 as quickly as possible.

G1 is used to move the tool in a straight line at a feedrate you specify. This is a bit more complicated than it might first appear since moving from point A to point B at a specific rate often involves moving 3 machine axes at three different rates. G1 is usually called linear interpolation. The command G1 X4.5 Y3.0 Z-2.5 F20.0 would cause the tool to move to the specified XYZ position at a rate of 20 inches or millimeters per minute.

G2 is where things can start to get more complicated. It's always used to make an arc, moving clockwise at a rate you specify. The G2 format you'll see most creates an arc in the XY plane and specifies the arc center incrementally - for example G2 X-0.26 Y1.14 I0.5 J0.0 means "Starting from where the tool is now, move clockwise in an arc. The center of the arc has an X value 0.5 greater than the current position (from I0.5) and the same Y value as the current position (J0.0). Stop when you get to X-0.26 and Y1.14. Travel at whatever feedrate I last specified."

Things get more complex if you need an arc that's not parallel to the XY plane. Some machines allow G2 commands in the YZ and ZX planes, in which case Z axis center references are handled by the K-word. Some machines will create a helix with a G2. Some will create a circle with one G2, others may be limited to less than 90 degrees.

You can usually assume that a controller's G2 command makes a clockwise arc,  but not that it will be specified as described above. Some controllers require absolute center coordinates rather than relative, and some require an arc radius rather than a center, and some use all of these methods in various combinations. The EIA standards specify incremental centers but early lobbying by some folks (the Postprocessor Writer's Guild?) appears to have created a situation whereby there are actually several ways to define a circle center.

If you really need to know more, click here.

G3 is like a G2, just think counterclockwise.

G4 is like some folks we've all worked with. It does nothing for a specified time. It just dwells - you'll have to check your controller manual to see what follows the G4. Some use X, F, or P words in milliseconds, some allow an S word to specify spindle revolutions, and some allow nothing at all and default to about a half second. 

G5 thru G89 will be dealt with as time permits. For now, the important ones to look up somewhere else are G17, G18, and G19. These have a dramatic effect on G2 and G3. Also, G53 thru G59 can transform your whole program (pun intended) and those in the G80 range can make a "hole" lot of difference.

G90 indicates that programmed values are to be treated as absolute, or actual coordinate values. If the programs issues a G1 X5.0 Z 2.0 , then the tool moves to that position. A venerable German tool maker once told us how he remembers that G90 means absolute - he said that the German word for absolute is obsolute and that the "o" looks like the "0" in G90. Actually, the German word for absolute starts with an "a", so either he couldn't spell (possible) or we misunderstood (likely). Either way, it's a good way to remember.

G91 indicates that programmed values are to be treated as incremental, or relative coordinate values.  If the programs issues a G1 X5.0 Z 2.0 , then the tool moves five units in the positive X direction and two in the positive Z direction. The same tool maker (see G90) said that the "i" in the German inkrement looked like the "1" in G91.

Back to Top

What is DNC?

As usual, there's more than one answer - even for the abbreviation. Some say it's Direct Numerical Control (the original wording) and some say Distributed Numerical Control. All definitions include computer to machine tool communication, or what could be termed "tape elimination". Then they differ based on including or excluding some or all of the following capabilities:

Drip feeding a controller

Accepting data from a controller

Storing and organizing libraries of CNC programs

Operating as a network 

Originally, "DNC" defined an ambitious approach that involved controlling multiple machine tools directly from a central computer. This was during the "NC" days prior to CNC and was really a kind of hybrid CNC/DNC approach. The central computer was connected directly to machine servos. Eventually, as more and more tape elimination systems were developed, "DNC" was adopted to describe them instead, especially since the central computer approach was not very successful.

Back to Top

What is/are "Serial Communications"?

The short answer, which you probably don't really care to know, is that serial communications is a  bit by bit data transfer method. In a computer, each character is made up of a group of "bits", an abbreviation for binary digits. In most computers, each character contains 8 bits. When communicating via a serial link, a couple of additional bits are tacked on for various reasons. If a computer is transferring data to a CNC controller at a speed of 9600bps (bits per second) and each character requires 10 bits to transfer, then 960 characters per second can be sent down the wire. Seven bit character codes are also widely used, so the "divide by 10" method is slightly pessimistic for these. This is different from parallel communications, where each bit in a character has its own data path and the whole character gets sent in one shot. On PC's, printer ports use parallel methods and comm ports use serial methods.

The long answer, which you may well need to know, is complicated enough that we gave it it's own page - see the table of contents.

Back to Top

What is XModem?

XModems are used to transfer "X Files". (See serial communications)

Back to Top

How are CNC machines programmed?

Several methods are used. The most basic method is to simply do the necessary geometric calculations with a calculator and write the program directly using G-codes, M-codes, and so on. The program is then keyed directly into the controller (usually called MDI, for Manual Data Input) or keyed into a computer and transferred to the controller via punched tape or some other medium.

Some controllers can be programmed using a "conversational" method offered by the controller vendor. This may involve a more advanced language or hitting buttons with symbols on them. (Screaming at the control is not "conversational programming").

Specialized languages such as APT have been available since the sixties and continue to be used. These create a controller-neutral tool path, usually called a CL File (Cutter Location or Center Line - take your choice), which is then converted to a CNC program acceptable to a given CNC control. A separate postprocessor is generally used for each CNC control or control family.  APT will perform complex geometric calculations and has provided "modern" features like tool path associativity since its inception.

Graphically oriented CAD/CAM systems for design and NC programming became generally available in the late seventies. Like APT, they usually create a neutral file usually called a CL File although their CL File format is generally far different from traditional APT CL File formats.

Parametric programs are used for family of parts programming and these can be written in any programming language. APT, Fortran, BASIC, C, whatever...

Back to Top

What is APT?

It stands for Automatically Programmed Tool,  it's a programming language, and to some extent it's an architecture. An Association of Computing Machinery document states that it is the oldest programming language of any kind still in use. (It resulted from a study done at the MIT Servomechanism Laboratory in 1952 under the sponsorship of the Air Materiel Command. A prototype ran on the Whirlwind computer in 1955. We believe that the first commercially available version was released by IBM in 1958 for the IBM 704 computer.) It has been listed in most dictionaries for decades. It offered tool path associativity, macros, transformations, pocketing, five axis tool control, complex surface definition and machining, complex tool shapes, and many other modern features before any CAD/CAM system (as defined today) even existed. The shelf life of an APT program exceeds that of most other archival storage methods. It defined an API  back in the sixties. A knowledge of APT  capabilities and architecture helps you evaluate other CNC programming methods and some basics can be found under APT Language and APT Architecture.

APT methods did not adapt well to a graphics world and most people consider it obsolete.

Back to Top

What is a CL file ?

A CL file is a CNC program in a neutral format that is created by a CAD/CAM system, APT, or some other type of NC programming system. It is considered neutral because it is not formatted for any particular machine tool. There is no single standard CL file format, and there is no single standard even for CL file contents. Two common formats of "ASCII" CL files are shown here - each describes the same tool path. A traditional APT CL file is discussed after the table.

A traditional APT CL file is not human readable without translating from an internal integer and floating point format into numbers and letters. The data itself is similar, but an APT CL file contains more information, especially regarding circles. If the files above are used with a machine tool that  does not support circular interpolation (that is, has no G2 or G3 command) then the postprocessor must generate the short linear moves made to form the arcs. With an APT CL file, this would not be necessary. For each arc, the APT CL file would contain a type 3000 record containing the coordinates of the center and the tool axis vector (angle), the radius, as well as the  linear moves needed to make the arc if they are needed. For each actual move generated by a motion statement, a type 5000 record would be present containing all points necessary to complete the motion.

For the statement reading GOTO/ -1.50, 1.250, 5.0 in the CL files above (which would probably result in G0X-1.5Y1.25) the type 5000 record would contain the following:

5 5000 5 bb 0 -1.5 1.25 5.0

broken down as:

5 = Record number

5000 = Record type

5 = Code for 'First or only record in this move'

bb = Geometry name used to create motion - blank in this case

0 = Subscript applied to name, if any

-1.5 = X

1.25 = Y

5.0 = Z

Back to Top

What is a postprocessor?

A postprocessor is a program that reads a CL file and produces a CNC program for a specific machine tool. Some "posts" are custom written for a specific tool/controller combination and others are generated via systems provided by postprocessor vendors. There are also generic posts that support, for example, 3 axis machining centers with many specific features customized using tables.

A postprocessor should be able to produce correct output for automatic tool changers, cycles, tool offsets, origins, circular and other interpolation, and other features specific to a tool/controller combination. The output from a postprocessor should be usable in the controller without further modification.

Creating a postprocessor using specialized packages is a fairly simple task. Writing custom posts has always been somewhat of a black art practiced by folks with a bizarre love of terms like "tool axis vector", "linearization", "zero-suppression", and "modality".

Back to Top

What is "Dumb APT"?

This is a term often used to describe a CL file that actually consists of APT statements. Typically, they contain no geometry definitions, but consist mainly of postprocessor commands, linear moves ( GOTO/ X,Y,Z ) and possibly some arcs. Since they're in APT format, they can be processed by APT (creating yet another CL file) or in may cases, directly by a postprocessor. 

Dumb APT programs are created by CAD/CAM systems (and even some APT processors), not by dumb APT programmers. They are called "dumb" simply because they describe the tool path directly and contain no part geometry. An APT program written by a human would almost always describe at least some of the part geometry.

Back to Top

Why am I confused by the letters I, J, and K?

Possibly because they commonly apply to two different aspects of CNC programming.

 In a CNC program (the one with the G and M codes)  I, J, and K are used to specify the center of an arc or circle and refer to positions on the X, Y, and Z axes - as in G2 X3.0 Y4.5 I0.5 J0.3125.

In a CL file or in APT, they are used to position the tool axis vector - as in GOTO/X,Y,Z,I,J,K .You can think of the tool axis vector as a tool centerline (think mill here, not lathe or punch press) that is exactly one unit long - say, one inch. That makes it a "unit vector". I, J, and K are used here to describe how the tool is tilted with respect to the Z axis.  I, J, and K simply define the other end of the unit vector along X, Y, and Z. On a three axis machine, the tool doesn't tip, so the tool centerline stays parallel with Z - therefore I, J, and K will always be 0, 0, 1 because (using the tool tip as a reference) you can find the other end of the vector by moving 0 in X, 0 in Y, and 1 in Z. 

If you are programming a five axis machine in a CAD/CAM system, position the tool at X=2, Y=3, and Z=4 and tip the tool five degrees around the Y axis you'll probably see the CL file output as GOTO/ 2.0, 3.0, 4.0, 0.0872, 0.0, 0.9962 . Here, we moved the top of the unit vector a bit in X and, of course the Z component got a bit smaller as a result. A postprocessor would read this and probably output G1 X2.0 Y3.0 Z4.0 A90.0 B5.0 - not an I, J, or K in the whole block!. 

Enough already. The short answer is that you see I, J, and K in CNC programs as circle centers and in CL files and APT programs (and math texts) as unit vector components. 

Back to Top

What is an inverse-time feedrate?

Feedrate refers to the various was of specifying the rate at which the tool moves through the material. It's usually specified in a CNC program via an "F-word", as in F30.0. For simple milling, the rate is usually expressed in millimeters or inches per minute. Although this is conceptually simple, it gets complicated if you think about it. For a machine tool to drive the cutter from one point in space to another at the rate you specify, each axis probably needs to move at a different speed. In a curve, the edge of the cutter will be feeding at a different rate than the center.

If you have a rotary axis on your machine, you may get to enjoy using the exciting inverse time feedrate method. Here, you need to know what "units per minute" feedrate you need and the distance the cutter will traverse in the move you're working on. (This can get complicated for rotary moves and programmers often ignore that detail - usually ok to do). Once you have the distance, multiply it by 60 and divide it into the desired UPM feedrate. Put that number in the F-word. Do this for each move involving linear and rotary motion. Now you know why almost all multi-axis (more than 3) programs are written using APT or a CAD/CAM system, and you have an interesting question to ask your postprocessor vendor - "How does it handle inverse time feedrates?"

APT and many CAD/CAM systems create a FEDRAT/ statement in the CL file (e.g. FEDRAT/30.0,IPM ) which is usually translated by the postprocessor to an F-word.


Back to Top

CNC Programming survival information for students, computer programmers, prospective CNC programmers, liberal arts majors, managers, and systems administrators. "I am in much dismay at having got into so amazing a quagmire & botheration with these Numbers" -  Augusta Ada Byron, later Countess of Lovelace, arguably the world's first technical writer.