CNC programming: steps to start creating

CNC programming

We dedicate a large number of complete guides on the CNC machining technology. Now it's time to take a step further and focus on something like CNC programming, which we have already referred to in other articles, but which we will see here in more detail.

This way you can get to know these better programming codes for industrial machines and how they can be easily modified or optimized to suit your needs.

There are what are known as post-processors, programs that convert a CNC program into a code specific to a particular machine. Some post-processors can perform bi-directional translations, that is, convert a proprietary code into a standard code and vice versa. On the other hand, CNC simulators are programs that allow simulating the execution of a CNC program on a virtual machine. By simulating the execution of a proprietary program, its operation can be analyzed and an equivalent program can be generated in a standard language.

Introduction to CNC

linux cnc

CNC stands for Computer Numeric Control. It is a manufacturing process that uses computer-controlled machine tools to cut and shape a wide variety of materials, from metals to plastics. Unlike manual machining, CNC machines perform repetitive tasks with exceptional accuracy and speed, following pre-programmed digital instructions.

In order to carry out machining, the design of the part that needs to be created begins, something that can be done using CAD software. This design can be converted automatically or manually into what is known as CNC code, which will be the one that Turn the design into a real part through the CNC machine.

At the heart of the machine is a CNC controller, a circuit that will be responsible for interpreting the CNC program and translating it into electrical signals that control the movements of the axes of the machineAs you may know, machines have different axes, depending on the model. The most common are the X axis that moves horizontally, the Y axis for movement perpendicular to the X axis, and the Z axis for vertical movement up or down. This is how the tool or head manages to carve the required design. Some machines could have more axes, or be multi-tool, although this is not of interest to us now…

The tool used can be a milling cutter, a drill bit, a turning blade, etc. This is how the machining is done through movements, just as a document that you send to print converts the code into the printed form. Remember that documents that are going to be printed are transformed into a page description language (Page Description Language, or PDL), such as PostScript or PS, PCL (Printer Control Language), etc. This language is a set of instructions that the printer uses to interpret and represent the document on paper.

Back to the CNC, the part can be static, held firmly to the work table while the tool moves. At other times the part can be rotating at high speed and the tool can remain static, removing excess material and shaping the part. But both to move the part and to move the tool, the CNC controller acts as an interpreter that translates the programming language into physical actions:

  1. Reading the code: The controller reads the CNC program line by line.
  2. Acting: Each line of code contains specific instructions, such as the position to which the tool should move, the cutting speed, or the amount of material to remove.
  3. Signal generation: The controller generates electrical signals that are sent to the servo motors that control the axes and the spindle.
  4. Execution: Servo motors receive the signals and move the axes and tool precisely, following the program instructions.

Basic CNC programming

types of CNC machines

Generally the CNC code It is not written manually, but is translated from a CAD design automatically by the software. However, there may be some occasions when you need to create CNC code from scratch, or you have an existing CNC program that you only need to make some optimizations or modifications to in order to create a variant of the initial part.

Although each CNC machine manufacturer usually has its own dialect of G and M code, the underlying basis and logic are very similar. This means that it is possible to transform a program written in a proprietary language into an equivalent program in a standard language.

Therefore, it is important to know this language APT (Automatically Programmed Tools), a high-level programming language that was instrumental in the development of numerical control systems. Although it has been largely superseded by more modern, machine-specific languages, APT remains a historical and conceptual benchmark in the field of CNC programming:

Key lyrics

One of the things to know about CNC code is the key letters that will appear in the programming lines and that you should know thoroughly:

  • O – Program Number: to uniquely identify a CNC program. It usually starts with O followed by a number, for example O001, which would indicate the first program.
  • N – Sequence Number: Used to specify the order of execution within a CNC program. It starts with N followed by a number, for example, N100.
  • G – Preparatory Function: Specifies the preparatory function for the machine, such as selecting a specific coordinate system, turning on the coolant, or setting a specific operation mode. It starts with G followed by a number, for example, G00, G01, G02. G00 indicates rapid positioning, G01 for linear interpolation, and G02 for clockwise circular interpolation…
  • X, Y, Z – Axis Designations: These specify the target coordinates for the tool, and are followed by a numeric value, for example, X10.0, Y20.0, Z5.0. In this example, the tool would be moved to coordinates (10, 20, 5).
  • R – Radio Designation: Used to assign the radius of a circular arc during interpolation. For example, G02 X10.0 Y20.0 R5.0, which would create a clockwise arc with a radius of 5 units.
  • F – Ground Speed ​​Designation: Sets the feed rate, or the speed at which the tool moves relative to the workpiece. For example, an F100 sets the feed rate to 100 units per minute.
  • S – Spindle Speed ​​Designation: Determines the spindle rotation speed. For example, S2000 will generate a spindle speed of 2000 RPM or revolutions per minute.
  • H – Tool Length Offset Designation: offset between the tool tip and the spindle nose. An H1, for example, indicates that you select the offset for tool number 1 that has been defined with this ID in the CNC machine's tool table.
  • D – Tool Radius Offset Designation: for the offset between the tool radius and the programmed path. Example could be a D2, indicating that the tool radius offset number 2 defined in the ID table is selected.
  • T – Tool Designation: Specifies the tool number to be used. For example, a T4 selects tool number 4 from the tool table.
  • M – Miscellaneous Function: Miscellaneous functions, such as turning the spindle on or off, activating the coolant, or stopping the program. For example, an M03 and M30 mean to start the spindle clockwise and end the program simultaneously.

These key letters and their corresponding functions form the basis of CNC programming, enabling precise and repeatable machining operations.

G-codes

Called G or general codes, and they are:

  • G00: rapid transverse positioning.
  • G01: linear interpolation.
  • G02: circular interpolation, clockwise (CW).
  • G03: circular interpolation, counterclockwise (CCW).
  • G17: XY plane.
  • G18: XZ plane.
  • G19: YZ plane.
  • G20 / G70: English or Imperial units, such as inches, etc.
  • G21 / G71: SI metric units, such as millimeters, etc.
  • G40: cancel tool compensation.
  • G41: tool compensation to the left.
  • G42: tool compensation to the right.
  • G43: tool length compensation (positive).
  • G44: tool length compensation (negative).
  • G49: cancel tool length compensation.
  • G80: cancel canned cycles.
  • G81: drilling cycle.
  • G82: reaming cycle.
  • G83: deep drilling cycle.
  • G90: absolute positioning.
  • G91: incremental positioning.

M-Codes

Between the general codes M, we have:

  • M00: stop the program.
  • M01: optionally stop the program.
  • M02: end the program.
  • M03: turn the spindle clockwise.
  • M04: turn the spindle counterclockwise.
  • M05: stop the spindle.
  • M06: tool change.
  • M08: turn on the coolant.
  • M09: turn off the coolant.
  • M10: turn on the gags.
  • M11: turn off the gags.
  • M30: stop the program and restart at startup.
Depending on the machine, there may be other additional codes, but these are the most common ones. Also, the + and – signs can be used in front of numbers to change the direction.

Code format

Now that you know more or less the CNC codes, we have to see the format that the complete program or code must have, since it has a specific format commonly known as word address format, a standard structure used to write computer numerical control programs. Each program line is called a block and is composed of several instructions or words.

CNC code example

To finish, let's see a CNC code example and the description of what it would do, so that you can understand in a more practical and visual way how it works:

N100 G01 X10.0 Y20.0 Z5.0 F100.0 S2000.0 T4 M03

In this case, the code will mark sequence number 100, perform a 01 setup for linear interpolation, then specify the CNC tool target coordinates for the X, Y, and Z axis (10, 20, 5), set the feed rate to 100 units, the spindle revolutions will be 2000 RPM, use tool 4, and turn the spindle clockwise…


Be the first to comment

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.