CNC programming analysis of curve processing

In machinery, mold manufacturing industry, often encounter curve processing. For simple curves—arcs, the G code provides G2, C3, I, J, K, and R instructions, making it easy to write NC programs. However, for some complicated and special curves—ellipses, parabolas, involutes, etc., of course, there are more complicated high-order curves, and conventional means cannot do anything about it. According to many years of work practice, the author wrote a G code program to solve such problems through special tools and software. There are three commonly used methods: 1 Use the power of G code to write a macro program. 2 Use the tool software Mastercam to generate the curve program. 3 Use C language (or other language) to generate the program's main data file, and then manually add function statements at the end of the file to become a program that can be run. Each of these three methods has its own advantages, disadvantages, and scope of application and can complement each other.

1.G code macro program

It provides variables, arithmetic operation instructions (add, subtract, multiply, divide), function functions (SIN, COS, TAN, ...), and control instructions (IF - GO-TO, WHILE - DO). Clever use of these instructions can solve many simple and regular curves, such as sinusoids and parabolas. Example 1: Sine curve (Figure 1).

Main program main program

...

G65P9910AOB360. C100. F100

...

Set local variables

#l=0

#2=360.00

#3=100.00

#9=100.00

09910 (subroutine)

WHILE[#1IE#2]DO1

#10=#3*SIN[#1]

G90Gl#lY#10F#9

#1=#1+10.

END1

Of course, this method can also express more complicated curves. The macro program is short and refined and is suitable for devices with small storage space. With strong adaptability, it is possible to perform roughing only by changing one or two data. However, it is obscure and difficult to understand, the logic is complex, errors in the process are not easy to find, and there is nothing that can be done about a particularly complex curve. This kind of method has higher requirements for programmers. It must be very proficient in G code, including infrequent instructions. It must have a solid and advanced knowledge of mathematics and be familiar with CNC machining operations.

Mastercam software application

2. Use Mastercam software

This software is widely used in CNC processing, interface affinity, easy to learn and easy to use, can solve the G code macro program can not solve the problem. Take the workpiece given in this article as an example. As shown in Figure 2, the curve is defined by some discrete coordinate points (for measurement), as shown in the attached table.

With Mastercam processing, the operation flow is as follows: 1 First create points, and draw all known points by coordinate values. 2 Concatenate all points in the Spline curve. 3 Select the processing method. 4 generate processing programs. Specific steps are as follows:

The first step, Create-Point-Position, then directly enters the coordinate values, first x-axis and then y-axis, separated by commas. The second step, after all the given data has been input, commands Create-Spline-Auto-matic. The system prompts to select the first point, the second point, and the last point. Once the click is completed, the system automatically generates Spline-like data. Curve. Step 3, command Toolpaths-Finish-Chain, click the right (end) end of the curve with the mouse, select the End here command, after confirming Done, the tool parameters dialog box will pop up, select the appropriate tool according to the need, and then switch to Finish parameters. The dialog box, shown in Figure 3, selects the cutting parameters. In this process, we must pay special attention to the determination of several important parameters: 1Linearization determines the machining accuracy. The smaller the value is, the higher the precision is, and the longer the program is, 0.01 is generally sufficient. 2Compensa-tion type is intended to select the type of tool compensation. Commonly used are Computer and Con-trol. The computer calculates the tool path based on the actual tool condition and generates the program without tool compensation. Control does not consider the tool specification and generates a tool compensation program. 3Compensation direction, select tool compensation direction, generally depends on the processing method and operation method. After the above parameters are determined, the management menu pops up, as shown in Figure 4. Step 4. Click the Post button to open the post-processing dialog box. As shown in Figure 5, determine the CNC machine operating system. The FANUC system is selected here. The file is MPLFAN. Note: The post-processing file starts with MPL, followed by the abbreviated numerical control operating system. If you want to change to another system, select via the change Post button and select the Edit command, then click the 0K button to generate the program.

The machining of the workpiece has been tried several times: in the first processing, the coordinates of the given point are directly used, the two points are approximated as a straight line, and the program is written by the G1 command. The resulting curve is a 19-segment polyline, which is caused by too sparse discrete points. The second time, in AutoCAD2002, discrete points were splined with Spline spline commands, and the vertical line was used to divide the curve to divide its projection on the X axis, and the coordinates of the points were calculated to increase the number of points. And artificially insert a number of points between the original two points, all written into the program. Although this method can solve problems, it is cumbersome, and the program is huge and error-prone. The third time, Mastercam was used to connect discrete points together with splines to directly generate a program that meets the accuracy requirements. Compared with method two, the generated program is short and refined with high accuracy. The method is efficient, simple, and convenient, and it can solve the curve form given only discrete points, and has lower requirements for operators.

Curve processing data programming

3. Generating program data body in C language (or other language)

The shape of a product is a very complex curve equation. It is difficult (or even impossible) to write it out with a macro program, and Mastercam cannot input the function equation. At this point, the data body is generated using the C language.

Example: Turner curve equation is as follows:

0 ≤ x ≤ 22.1

Y=200.2+140.653√b

b=0.008754(x/168)+6.1455(x/168)2

-4.87544(x/168)3+0.568749(x/168)4

+0.76587(x/168)5

It is difficult to draw in Mastercam. Use C language to calculate its discrete points, the process is as follows:

#include"math.h"

#include"conio.h"

#include"stdio.h"

Main ()

{

Double a,b,d,c,i,e;

FILE*fp;

Fp=fopen("d:\s77.txt","w+");

For(i=0;i<22.1;i=i+0.1)/*3*/

{

c=i/168;

b=0.008754*c+6.1455*c*c-4.87544*c*c*c+

0.568749*c*c*c*c+0.76587*c*c*c*c*c;

d=0.3333*log(b);

e=exp(d);/*1*/

a=200.2+140.65*e;/*2*/

Printf("Z=%.4f",i);

Printf("X=%.4f\n",a);

Fprintf(fp,"z%.3fX%.3f\n",i,a);

The result is output to file S77.TXT*/

}

Printf ("ok");

Getch ()

}

The two sentences of procedure 12 use a formula a=eIna, b opens the third power and is 6/1/3. This program passes under TC2.0.

Run this program to get the s771.txt file, open with the editor (any one, such as Notepad), just add a functional sentence at the end of the head, is a usable program. Its principle is: any curve can be divided into numerous and very short curves, each very short curve can be considered approximately as a straight line. As the length of each curve tends to zero, the error with the straight line also tends to zero. A sufficient number of straight lines can be connected to replace one curve, so that the curve is transformed into a straight line of finite segments. The straight line program is easy to implement and the problem is simplified. In order to reduce the curve error as much as possible, the length of each curve should be as short as possible, so the cycle step length in the program (control curve length, note 0.1 in 3i=i+0.1) can be made very small. However, the procedures for doing this will be very large and there will be a large amount of redundant data. Curvature is proportional to the error, because the step length is fixed, the error is small in the place where the curvature is small, and there is a large amount of useless data when the curvature is zero (that is, straight line) (it can be completely discarded without affecting the program), and the curvature is large in the curve. The local error is larger. The new generation of machine tools has large CNC system capacity, so it is not necessary to consider the size of the program too much to ensure the accuracy of the curve (line profile) as the first priority. If you want to generate a short program without redundancy, you need to use mathematical knowledge such as quadratic derivation, which is very complicated and will not be discussed here.