A method for quickly aligning a casting based on a macro program
By using a macro-program-based automatic alignment method, which utilizes trigonometric functions and CNC system variable programming, rapid alignment of castings can be achieved. This solves the problems of low efficiency and difficulty in guaranteeing accuracy in traditional methods. It is highly adaptable and suitable for efficient machining on CNC machine tools.
Patent Information
- Application Number
- CN202411668953.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-20
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2044-11-20
AI Technical Summary
Traditional casting alignment methods rely on employee experience, which is inefficient, difficult to guarantee accuracy, and labor-intensive, making them unsuitable for the high-efficiency and high-precision requirements of CNC machine tools.
A macro-program-based approach is adopted, which uses trigonometric functions to measure and calculate the straight line deviation angle, compiles a macro program for alignment, and automatically aligns the casting by using local variables, common variables, and system variables of the CNC system. This generates NC code with its own macro program, enabling rapid alignment of the casting.
It improves alignment efficiency, reduces human error, is highly adaptable, easy to promote, and is especially suitable for the efficient processing of large castings.
Smart Images

Figure CN119717689B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of machining technology, and in particular relates to a method for quickly aligning castings based on macro programs. Background Technology
[0002] In my country's foundry industry, the quality of castings directly affects product performance and service life. During production, alignment is a crucial step in improving casting precision. Traditional alignment methods rely heavily on employee experience and skill levels, resulting in low efficiency and difficulty in guaranteeing accuracy. Due to uneven allowances in the casting blank, before machining, the workpiece needs to be aligned with the machine tool's XY plane using markings made by a fitter. Then, machining is performed on vertical, horizontal, or gantry machining centers based on these markings. This particular casting uses a vise for alignment. The upper surface has already been machined horizontally. Because the workpiece held in the vise is a square view, it cannot be offset; it can only be leveled using wedges or shims (parallel to the X or Y direction of the worktable). This increases the operator's workload, requiring frequent clamping and tightening, demanding a high level of skill from the worker, and resulting in low alignment efficiency.
[0003] The application of CNC machine tools in the casting industry is becoming increasingly widespread, and their high precision and efficiency have brought about revolutionary changes in casting processing. However, casting alignment remains a challenge during CNC programming. To address this, we propose a method for rapid casting alignment based on macro programming. This method utilizes the powerful parametric programming capabilities of macro programs to achieve rapid casting alignment by extracting and calculating the characteristic parameters of the casting. A macro program is a programmable CNC instruction that allows operators to define custom programming elements such as variables, logical judgments, and loops within the CNC system. This macro-program-based method for rapid casting alignment offers advantages such as improved alignment efficiency, guaranteed alignment accuracy, strong adaptability, and ease of implementation. Summary of the Invention
[0004] The purpose of this invention is to provide a method for quickly aligning castings based on macro programs, which realizes automatic alignment of castings and solves the problems of low alignment efficiency, high labor intensity, and frequent clamping.
[0005] To achieve the objective of this invention, a method for rapidly aligning castings based on a macro program is provided, comprising the following steps:
[0006] Step 1: Use trigonometric functions to measure and calculate the angle of deviation of the line;
[0007] Step 2: Compile the macro-finding program;
[0008] Step 3: Modify the post-processor of the programming software;
[0009] Step 4: Modify the program generated by the post-processing program and call the program to perform machining on the cutting tool.
[0010] Furthermore, step 1 specifically involves automatically calculating the alignment using the arctangent trigonometric function principle. First, the relative coordinates of points A and B1 are obtained by measurement, and then the straight line deflection angle is calculated.
[0011] Furthermore, step 2 specifically involves using the local variables, common variables, and system variables of the CNC system to automatically correct the coordinate angles, perform variable programming, and automatically store the calculation results into the machine tool memory.
[0012] Furthermore, step 2 includes the following steps:
[0013] 2.1 Main Program of the Macro Program Based on FANUC CNC System
[0014] 2.2 Explanation of arithmetic macro programs;
[0015] 2.3 The machine tool operates according to the macro program.
[0016] Furthermore, the 2.2 arithmetic macro program is interpreted as follows:
[0017] The tool moves to point A, the machine tool program is started, the current machine tool mechanical coordinates X and Y are automatically read, and the corresponding coordinates are read into the common variables of the CNC machine tool system.
[0018] The program is paused;
[0019] When the cutting tool moves to point B1, the machine tool program is started, and the current machine tool mechanical coordinates X and Y are automatically read and the coordinates are read into the common variables of the CNC machine tool.
[0020] The program is paused;
[0021] Start the machine tool program, subtract the X-axis values from the common variables, and then read them back into the common variables;
[0022] Subtract the Y-axis values from the common variables and then read them into the common variables;
[0023] After calculating the angle between the two points, the result is written into the aforementioned common variable for later use.
[0024] The program has ended and the calculation is complete.
[0025] Furthermore, the machine tool 2.3 operates according to the macro program calculation, and the operation is as follows:
[0026] 2.3.1 The machine tool calls a 90-degree chamfering tool. In manual mode, the tool is moved to point A by handwheel. In automatic tool operation mode, the alignment program is run. The program executes program segments and stops automatically when a stop is encountered.
[0027] 2.3.2 Use the handwheel to move the tool to point B1, continue running the alignment program, and stop when the stop program is encountered;
[0028] 2.3.3 Continue running the alignment program, and the machine tool will automatically write the calculation results into the machine tool's public variables.
[0029] Furthermore, step 3 specifically involves writing the macro program for the required rotation angle into the software post-processor to generate an NC code program with its own macro program; the variable in the machine tool is #, which is replaced with & in the program; in the software post-processor, an automatic variable rotation command is added before the fixed position program segment of the tool, and the rotation is canceled after the tool program ends.
[0030] Furthermore, step 4 involves establishing the origin coordinates by tool setting and calling up the alignment program to process the casting during the machining process.
[0031] An electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the aforementioned method for rapidly aligning castings based on a macro program.
[0032] A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the aforementioned method for rapidly aligning castings based on a macro program.
[0033] Compared with the prior art, the significant advancement of this invention lies in the fact that it achieves automatic calculation and alignment by compiling macro programs and modifying the post-processing program of the programming software, thereby enabling rapid clamping, avoiding errors in manual alignment operations, greatly reducing alignment time and improving processing efficiency. It is highly adaptable and easy to promote, and its alignment is even more significant for large castings, showing good application prospects.
[0034] To more clearly illustrate the functional characteristics and structural parameters of the present invention, further explanation is provided below in conjunction with the accompanying drawings and specific embodiments. Attached Figure Description
[0035] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:
[0036] Figure 1This is a flowchart of the method for rapidly aligning castings based on macro programs according to the present invention;
[0037] Figure 2 This is a mathematical principle model diagram of the present invention;
[0038] Figure 3 This is a diagram showing the calculation results of the macro program of the present invention. Detailed Implementation
[0039] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0040] This invention provides a method for rapidly aligning castings based on macro programs, combined with... Figure 1 This includes the following steps:
[0041] Step 1: Use trigonometric functions to measure and calculate the angle of deviation of the line: combined with Figure 2 The automatic calculation and alignment adopts the principle of arctangent trigonometric function. First, the relative coordinates of two points A and B1 are obtained by measurement, and then the deviation angle α of the straight line is calculated.
[0042] Step 2: Compile the alignment macro program: Use the local variables, common variables, and system variables of the CNC system to automatically align the coordinate angles, perform variable programming, and automatically store the calculation results in the machine tool memory;
[0043] 2.1 Main program of the computational macro program based on the FANUC CNC system:
[0044] %O6666 (Main Program)
[0045] #500=#5021(X1)#501=#5022(Y1);
[0046] M00;
[0047] #502=#5021(X2)#503=#5022(Y2);
[0048] M00;
[0049] #504 = #502 - #500;
[0050] #505 = #503 - #501;
[0051] #506 = ATAN[#505] / [#504];
[0052] M30;
[0053] 2.2 Explanation of the arithmetic macro program:
[0054] The tool moves to point A, the machine tool program is started, the current machine tool mechanical coordinates X and Y are automatically read, and the corresponding coordinates are read into the common variables of the CNC machine tool system.
[0055] The program is paused;
[0056] When the cutting tool moves to point B1, the machine tool program is started, and the current machine tool mechanical coordinates X and Y are automatically read and the coordinates are read into the common variables of the CNC machine tool.
[0057] The program is paused;
[0058] Start the machine tool program, subtract the X-axis values from the common variables, and then read them back into the common variables;
[0059] Subtract the Y-axis values from the common variables and then read them into the common variables;
[0060] After calculating the angle between the two points, the result is written into the aforementioned common variable for later use.
[0061] The program has ended and the calculation is complete.
[0062] 2.3 The machine tool operates according to the macro program calculations:
[0063] 2.3.1 The machine tool calls the 90-degree chamfering tool. In manual mode, the tool is moved to point A by handwheel. In automatic tool operation mode, the alignment program O6666 is run. The program executes the program segment and automatically stops when it encounters the stop program M00.
[0064] 2.3.2 Use the handwheel to move the tool to point B1, continue running the alignment program, and stop when the stop program is encountered;
[0065] 2.3.3 Continue running the alignment program, and the machine tool will automatically write the calculation results into the machine tool's public variables.
[0066] Combination Figure 3 The results seen in the machine tool background after the macro program calculation are shown in #504 and #505. The values in #506 are the calculated differences, and the value of 0.4442613 is the angle that needs to be rotated.
[0067] Step 3: Modify the programming software post-processor: Write the macro program for the required rotation angle into the software post-processor to generate an NC code program with its own macro program; the variable in the machine tool is #, which is replaced with & in the program. Since # in the machine tool program represents only a comment and has no practical meaning, but the machine tool program needs to use the machine tool variable # for calculation, other symbols need to be used for output in the machine tool program. Therefore, the program & replaces # in the program to provide an efficient and stable program; in the software post-processor, add an automatic variable rotation command before the fixed position program segment of the tool, and cancel the rotation after the tool program ends.
[0068] 1) Open the "MPFANUC" post-processing file with Word or Notepad, search for the program name part "*progno,e", and add two lines of characters after "pbld,n,*t,'M6',e" respectively: "pbld,n,&506=ATAN[&505] / [&504]',e" and "pbld,n,'G68X0Y0R&506',e".
[0069] 2) In the tool change section "#Tool change", similarly, add two lines of characters after "pbld,n,*t,"M6",e": "pbld,n,"&506=ATAN[&505] / [&504]",e" and "pbld,n,"G68X0Y0R&506",e".
[0070] 3) In the tool change end section "#End of tool path,toolchange", add a line of characters "pbld,n,"G0Z100.",scoolant,strcantext,e" before "pcanl,pbld,n,"G69",e".
[0071] 4) Before the program ends, add the characters "pbld, n, &506=0", e before "n,"m30",e.
[0072] Step 4: Modify the program generated by the post-processor and call the program to perform machining. The modified program is shown below:
[0073] %O0002 (Workpiece Main Program)
[0074] G0G 17G40G49G80G90
[0075] T25M6 (Tool Selection)
[0076] #506 = ATAN[#505] / [#504] (Calculate the angle between the two points and write the result into the public variable #506 for later use.)
[0077] G68X0Y0R#506 (calls the angle value in parameter #506, and then rotates the workpiece around its zero point in coordinates;)
[0078] G0G90X-464.695Y-156.531S5000M3
[0079] G43H25Z100.M8
[0080] X-464.07Y-156.218
[0081] ………slightly
[0082] G69 (Cancel coordinate rotation function)
[0083] G00Z100.M9
[0084] M01
[0085] T2M6 (Call Tool)
[0086] #506 = ATAN[#505] / [#504] (Calculate the angle between the two points and write the result into the public variable #506 for later use.)
[0087] G68X0Y0R#506 (calls the angle value in parameter #506, and then rotates the workpiece around its zero point in coordinates;)
[0088] G0G90X-464.695Y-156.531S5000M3
[0089] G43H2Z100.M8
[0090] G1Z-10.F200.
[0091] X-40.105F2000.
[0092] ………slightly
[0093] G69 (Cancel coordinate rotation function)
[0094] G91G28Z0.M9
[0095] M01
[0096] T6M6 (Call Tool)
[0097] #506 = ATAN[#505] / [#504] (Calculate the angle between the two points and write the result into the public variable #506 for later use.)
[0098] G68X0Y0R#506 (calls the angle value in parameter #506, and then rotates the workpiece around its zero point in coordinates;)
[0099] G0G90X-464.695Y-1 56.531S5000M3
[0100] G43H2Z100.M8
[0101] ………slightly
[0102] G0Z100.M9
[0103] G69 (Cancel coordinate rotation function)
[0104] #506 = 0 (Assign the value 0 to the machine tool's public variable #506)
[0105] G91G28Y0
[0106] M30 (Program End)
[0107] %
[0108] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.
[0109] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.
Claims
1. A method for rapidly aligning castings based on macro programs, characterized in that, Includes the following steps: Step 1: Use trigonometric functions to measure and calculate the line deflection angle: Automatic calculation and alignment uses the principle of arctangent trigonometric functions. First, the relative coordinates of points A and B1 are obtained by measurement, and then the line deflection angle is calculated. Step 2: Compile the alignment macro program: Use the local variables, common variables and system variables of the CNC system to automatically align the coordinate angles, perform variable programming, and automatically store the calculation results in the machine tool memory; 2.1 Main program of the computational macro program based on the FANUC CNC system; 2.2 Explanation of the computational macro program: When the tool moves to point A, the machine tool program is started, and the current machine tool mechanical coordinates X and Y are automatically read and the corresponding coordinates are read into the common variables of the CNC machine tool system; The program is paused; When the cutting tool moves to point B1, the machine tool program is started, and the current machine tool mechanical coordinates X and Y are automatically read and the coordinates are read into the common variables of the CNC machine tool. The program is paused; Start the machine tool program, subtract the X-axis values from the common variables, and then read them back into the common variables; Subtract the Y-axis values from the common variables and then read them into the common variables; After calculating the angle between the two points, the result is written into the aforementioned common variable for later use. The program has ended and the calculation is complete. 2.3 The machine tool operates according to the macro program calculation; Step 3: Modify the post-processor of the programming software; Step 4: Modify the program generated by the post-processing program and call the program to perform machining on the cutting tool.
2. The method for rapidly aligning castings based on a macro program according to claim 1, characterized in that the machine tool in step 2.3 operates according to the macro program calculation, wherein the operation is as follows: 2.3.1 The machine tool calls a 90-degree chamfering tool. In manual mode, the tool is moved to point A by handwheel. In automatic tool operation mode, the alignment program is run. The program executes program segments and stops automatically when a stop is encountered. 2.3.2 Use the handwheel to move the tool to point B1, continue running the alignment program, and stop when the stop program is encountered; 2.3.3 Continue running the alignment program, and the machine tool will automatically write the calculation results into the machine tool's public variables.
3. The method for rapidly aligning castings based on macro programs according to claim 1, characterized in that, Step 3 specifically involves writing the macro program for the required rotation angle into the software post-processor to generate an NC code program with its own macro program; the variable in the machine tool is #, which is replaced with & in the program; in the software post-processor, an automatic variable rotation command is added before the fixed position program segment of the tool, and the rotation is canceled after the tool program ends.
4. The method for rapidly aligning castings based on macro programs according to claim 1, characterized in that, Step 4 involves establishing the origin coordinates by setting the tool and calling up the alignment program to process the casting.
5. An electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements a method for rapidly aligning castings based on a macro program as described in any one of claims 1-4.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by the processor, the program implements a method for rapidly aligning castings based on a macro program as described in any one of claims 1-4.
Citation Information
Patent Citations
Alignment method for boring composite-angle high-precision hole
CN117358989A
Coordinate system alignment device and alignment method
CN118699879A