CNC Programming Instructions and Structures

CNC Programming Instructions

A comprehensive guide to understanding the structure, commands, and implementation of CNC machining programs, essential for anyone working with the cnc machine definition.

1. Program Structure

1.1 Words and Addresses

In a machining program, the smallest functional unit is called a word. A word is the basic information unit of a machining program. It consists of letters representing addresses, special characters, and numbers. For example: X2500.0 is a word indicating the X-direction dimension is 2500 mm; F1200 is a word indicating the feed rate is 1200 mm/min. This fundamental concept is crucial to understanding the cnc machine definition.

The ISO standard specifies the meanings of address characters for dimension words, which form the backbone of how instructions are communicated within the cnc machine definition. These standardized addresses ensure consistency across different CNC systems and manufacturers.

1) Preparatory Function G Codes

Preparatory function G codes are used to specify the relative motion trajectory of the tool and workpiece, machine coordinate system, coordinate plane, tool radius compensation, tool length compensation, coordinate offset, and various other machining operations.

The "Numerical Control Machine Tools - Preparatory Function G and Auxiliary Function M Codes in Perforated Tape Program Block Format" (JB/T 3208-1999) specifies that G codes consist of the letter G followed by two digits, from G00 to G99, totaling 100 types. For specific regulations, please refer to Appendix A-1. This standardization is part of what defines the cnc machine definition across different manufacturers.

2) Auxiliary Function M Codes

Auxiliary functions are commands that control the on/off functions of the machine tool or system, such as commands to start or stop the coolant pump, spindle forward rotation, reverse rotation, stop commands, program end commands, etc. The M codes specified in the JB/T 3208-1999 standard also include 100 types from M00 to M99. For specific regulations, please refer to Appendix A-2. These auxiliary functions are integral to the complete cnc machine definition, enabling the full range of machine operations.

3) Modal and Non-modal Commands

Modal commands, also known as persistent commands, remain effective once used in a program block until another command from the same group appears. Non-modal commands are only valid within the current program block.

In the G and M standard tables in Appendix A, commands marked with the same symbol in the second column are modal commands of the same group, and the rest are non-modal commands. Understanding the difference between these command types is essential for effective programming within the cnc machine definition framework.

4) Expansion of G and M Codes

With the development of numerical control technology, the number of G codes and M codes in some CNC systems has exceeded 100. There are now systems using three-digit or even four-digit codes to expand the function set, allowing for more complex operations and greater flexibility in the cnc machine definition. This expansion reflects the evolving nature of CNC technology and its increasing capabilities.

1.2 Program Blocks and Formats

A program block is a combination of words required to complete a certain action. For example, the program block "G90 G01 X60 Y60 F300" indicating a linear motion function consists of five words, where G90 represents absolute dimensions, G01 represents linear interpolation, X60 represents the X-axis coordinate, Y60 represents the Y-axis coordinate, and F300 represents the feed rate. This structure is fundamental to how instructions are organized within the cnc machine definition.

The program block format refers to the regulations on the order and writing method of words in a program block. Different CNC systems generally have different program block formats. There are various program block formats, such as fixed program block format, program block format using separators, program block format using address characters, etc. Currently, the most commonly used is the program block format using address characters, as shown in Table 2-4.

Table 2-4: Program Block Format
Symbol Function
N Sequence number
G Preparatory function
X, Y, Z, U, V, W Coordinate dimension words
I, J, K Arc center coordinates
F Feed function
S Spindle speed
T Tool function
M Auxiliary function
LF End symbol

In the program block using address characters, the number of words is variable, so the length of the program block is also variable. Therefore, this form of program block is also called an address-variable program block. The advantage of the address-variable program block format is that the information contained in the program block is highly readable and easy to edit and modify manually, providing a convenient way for the CNC system to interpret and execute the CNC machining program within the cnc machine definition framework.

Example of a CNC Program Block Structure

N100 Sequence G90 G01 Preparatory X60.0 X Coordinate Y45.5 Y Coordinate F300 Feed Rate S1500 Spindle Speed M03 Auxiliary

This diagram illustrates how different address words combine to form a complete program block in the cnc machine definition.

2. Basic Instructions Detailed Explanation

2.1 Instructions Related to Coordinate Systems

In the program in section 2.4.1, instructions such as G91 and G17 are used, which are all related to coordinate systems. These fundamental coordinate system instructions form an essential part of the cnc machine definition, enabling precise control over tool movements relative to the workpiece.

1) G90 and G91 Instructions

The G90 instruction indicates that the programming dimensions in the program are given in absolute coordinates in a certain coordinate system. The G91 instruction indicates that the programming dimensions in the program are relative to the starting point of this segment, that is, the programming dimensions are the movement increments of each axis in this program segment. Therefore, G91 is also called the incremental coordinate instruction.

G90 and G91 are modal instructions of the same group and cannot be used at the same time, meaning only one of them is allowed in the same program block. All coordinate values after G90 are absolute coordinate values; the coordinate values after G91 are incremental coordinate values. When the G90 instruction appears, the coordinate values are absolute coordinate values.

G90 is the default instruction. In actual programming, the G91 instruction is often used because part drawings are usually dimensioned in incremental mode; of course, there are also cases where dimensions are relative to a certain reference point, in which case the G90 instruction may be used. Understanding when to use each mode is crucial for accurate programming within the cnc machine definition.

3) G92 Instruction

The G92 instruction is used to set the coordinate value of the tool in the workpiece coordinate system. It is a modal instruction, and its set value remains valid until it is reset. The G92 instruction is only meaningful when using absolute value programming.

Programming format:

G92 X__ Y__ Z__

This instruction determines the current workpiece coordinate system by setting the relative position between the tool starting point and the coordinate system origin. X, Y, Z are used to specify the distance from the tool tip starting point to the workpiece origin in the X, Y, and Z directions.

Figure 2-14: Setting Work Coordinate System with G92 Command
Origin Tool Current Point X=60 Y=60 G92 X60 Y60 Z50 X Y

The G92 command establishes the workpiece coordinate system relative to the tool position, a fundamental concept in the cnc machine definition.

Using the G92 instruction can only establish the workpiece coordinate system; the tool does not move, and the tool must be placed in the position required by the program. This instruction also has the function of compensating for the workpiece installation error on the machine tool. That is, when using this instruction, after the first part is processed, the system will measure the workpiece size. If it is found that the workpiece is not installed accurately and causes an error, there is no need to reinstall the workpiece. Simply modify the set coordinate values to eliminate this processing error, demonstrating the flexibility built into the cnc machine definition.

2.2 Instructions Related to Control Methods

1) G00 Instruction - Rapid Positioning Instruction

Programming format:

G00 X__ Y__ Z__

The G00 instruction is used to move the tool from the current positioning point to the next positioning point specified in the program block at a rapid feed rate preset by the CNC system. This rapid movement is a fundamental aspect of the cnc machine definition, allowing for efficient non-cutting movements between machining operations.

Note:

The movement trajectory of G00 is not necessarily a straight line. If not paid attention to, collisions may easily occur. Programmers must be aware of this behavior when working within the cnc machine definition to avoid costly mistakes.

Comparison of G00 and G01 Motion Paths
G00 Rapid Positioning Start End Rapid, non-linear path G01 Linear Interpolation Start End Straight line path F___ (Feed rate specified)

Understanding the difference between rapid positioning (G00) and linear interpolation (G01) is essential for safe and efficient machining within the cnc machine definition.

3. Macro Instructions

Macro instructions are functions designed by CNC system manufacturers to facilitate users, similar to high-level languages. Users can use variables for arithmetic operations, logical operations, and mixed operations of functions. They can use provided loop statements, branch statements, and subroutine call statements to control the process flow. The use of macro instructions is highly beneficial for programming various parameterized part machining programs, reducing or even eliminating tedious numerical calculations in manual programming, and simplifying the program. This powerful feature significantly enhances the flexibility and capability of the cnc machine definition.

Although the use of various CAD/CAM software to compile CNC machining programs has become mainstream in CNC programming, flexible, efficient, and fast macro program programming is still an important programming method and has wide application space in actual production processes. For example, some typical cavity machining and fixed cycle programs in CNC devices can be implemented by macro programs internally.

Macro instructions vary significantly among different CNC system manufacturers (see Figure 2-24), and must be used with reference to the corresponding programming manual. The following is a brief introduction using macro instructions of a certain domestic CNC system as an example, demonstrating how these extensions enhance the basic cnc machine definition.

Example of Macro Instruction Structure

%
O0001 (Main program)
G21 G17 G40 G80 G90

(Set macro variables)
#100 = 50.0 (Diameter)
#101 = 10.0 (Depth)
#102 = 2.0 (Stepover)

(Call macro program)
M98 P1000 (Macro program for pocket machining)

M30
%

O1000 (Macro program)
(Parameterized pocket machining)
G00 X[#100/2] Y0 Z50
G01 Z-#102 F100
G01 X0 F200

(Loop for pocket layers)
#103 = 0
WHILE [#103 LT #101] DO 1
    G02 I-[#100/2 - #103] J0 F300
    #103 = #103 + #102
END 1

G00 Z50
M99
%

This example shows how macro variables and loop structures can create flexible, parameterized programs that adapt to different part dimensions, extending the capabilities defined in the basic cnc machine definition.

Macro Instruction Capabilities

Macro instructions significantly enhance programming capabilities beyond basic G and M codes, expanding the cnc machine definition with advanced programming features.

The true power of macro instructions lies in their ability to create generic programs that can be easily adapted to different part dimensions and machining requirements through variable adjustments. This eliminates the need to write separate programs for similar parts, greatly improving programming efficiency and reducing errors. Manufacturers continue to enhance their macro programming capabilities, pushing the boundaries of what can be achieved within the cnc machine definition.

4. Subprogram Programming Methods

In a machining program, if some machining contents are completely the same or similar, to simplify the program, these repeated program blocks can be listed separately into a program, which is called a subprogram, and the original program is called the main program. When a subprogram execution instruction appears during the execution of the main program, the subprogram is executed. After the subprogram is executed, the system continues to execute the main program. This modular approach is a key aspect of efficient programming within the cnc machine definition.

In addition, to further simplify the program, a subprogram can call another subprogram to实现 subprogram nesting. The format of a subprogram is similar to that of the main program. At the beginning of the subprogram, a subprogram number must be specified to serve as the call entry address. The M99 instruction is used at the end of the subprogram to control the system to return to the main program after executing the subprogram.

Main Program and Subprogram Structure

Main Program N10 G21 G17 G40 N20 G00 X100 Y100 S1500 M03 N30 M98 P1000 (Call Subprogram) N40 G00 X200 Y200 N50 M98 P1000 (Call Subprogram Again) N60 M30 Subprogram O1000 N10 G01 Z-5 F100 N20 G01 X150 Y150 F200 N30 G00 Z5 N40 M99 (Return to Main Program)

Subprograms allow for code reuse and modular programming, a fundamental concept in efficient implementation of the cnc machine definition.

The use of subprograms offers several advantages within the cnc machine definition framework: it reduces program length, minimizes the chance of errors, simplifies program debugging, and makes program maintenance easier. When a machining feature needs modification, it only needs to be changed in one place (the subprogram) rather than in every occurrence throughout the main program.

Subprogram nesting is another powerful feature, allowing one subprogram to call another. Most CNC systems support multiple levels of nesting (typically up to 4 or 8 levels), further expanding the programming flexibility within the cnc machine definition. This hierarchical structure enables the creation of complex machining operations from simpler, reusable components.

When implementing subprograms, it's important to follow consistent naming conventions for subprogram numbers and to document the purpose of each subprogram, along with any required parameters or initial conditions. This practice enhances program readability and maintainability, ensuring that the cnc machine definition is implemented effectively across different programming projects.

滚动至顶部