Method, device and equipment for optimizing abnormal tool axis of numerical control tool path and storage medium
By parsing NC files to obtain tool position sequence and projecting it onto a unit sphere, abnormal tool axes are identified and optimized, solving the problem of tool axis optimization without a workpiece geometry model. This achieves efficient and accurate tool axis optimization, improving the stability and quality of CNC machining.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHENZHEN QIANJI SOFTWARE CO LTD
- Filing Date
- 2026-04-29
- Publication Date
- 2026-07-10
AI Technical Summary
Existing technologies struggle to effectively optimize CNC tool axes without a workpiece geometry model. This is especially true when there are local tool axis anomalies, where regenerating the NC program is costly and difficult to apply. Furthermore, traditional methods fail to differentiate for abnormal tool axes, resulting in insufficient repair or over-smoothing.
By parsing NC files to obtain ordered tool position sequence, tool axis vectors are generated and projected onto a unit sphere. The arc lengths of adjacent vectors are calculated to identify abnormal tool axes. Optimization is performed using tool axis vectors from neighboring tool positions. Interpolation or overall smoothing strategies are used to adjust abnormal tool axes, reducing overall optimization costs.
It enables accurate identification and optimization of abnormal tool axes without the need for workpiece geometry models and NC program regeneration, ensuring toolpath stability, reducing tool axis optimization costs, avoiding misjudgments and omissions, and improving machining quality and safety.
Smart Images

Figure CN122363053A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of CNC machining and computer-aided manufacturing technology, and in particular to a method, apparatus, electronic device, and storage medium for optimizing abnormal CNC toolpaths. Background Technology
[0002] With the development of multi-axis CNC machining technology, tool axis direction control has become one of the key factors affecting machining quality and safety. In applications such as complex surface machining and five-axis linkage machining, the tool axis direction usually changes continuously with the toolpath, and its rationality is directly related to the smoothness of machine tool movement, the quality of machined surface, and the ability to avoid interference or collision.
[0003] Existing tool axis optimization and control methods primarily focus on the internal mechanisms of computer-aided manufacturing (CAM) systems. These methods typically rely on workpiece geometry, tool models, and drive curves or surface information to plan and optimize the tool axis direction during toolpath generation or subsequent recalculation. These methods generate theoretically continuous and smooth tool axis directions through geometric or kinematic constraints, ultimately outputting a new numerical control (NC) program. When a complete geometric model is available and the NC program can be regenerated, this technology can achieve good overall planning results. However, when local tool axis anomalies occur during machining, and regenerating the NC program is costly, or when only NC files are available on-site but a workpiece geometry model is lacking, existing methods become unsuitable. Summary of the Invention
[0004] The present invention provides a method, apparatus, electronic device, and storage medium for optimizing abnormal CNC toolpaths, thereby reducing the cost of toolpath optimization based on NC files to a certain extent.
[0005] In a first aspect, the present invention provides a method for optimizing a CNC toolpath with an abnormal tool axis, the method comprising:
[0006] The NC file representing the toolpath trajectory is parsed to obtain an ordered tool position sequence; wherein, the ordered tool position sequence includes the spatial coordinate information of each tool position in the toolpath trajectory and the tool axis rotation angle information;
[0007] Based on the tool axis rotation angle information and the post-processing type of the NC file, a tool axis vector is generated;
[0008] Identify abnormal tool axes based on the difference between two adjacent tool axis vectors;
[0009] Within the trajectory segment where the abnormal tool axis is located, several adjacent tool points are selected, and the tool axis vector of the abnormal tool axis is optimized based on the tool axis vectors corresponding to the adjacent tool points; wherein, the trajectory segment is a portion of the tool points extracted from the ordered tool point sequence with the location of the abnormal tool axis as the center point.
[0010] In one embodiment of the present invention, assuming the tool axis rotation angle information is A around the X-axis, B around the Y-axis, and C around the Z-axis, a tool axis vector is generated based on the tool axis rotation angle information and the post-processing type of the NC file, including:
[0011] In the case of the post-processing type being AC, the tool axis vector ;
[0012] In the case of the post-processing type being BC, the tool axis vector .
[0013] In one embodiment of the present invention, identifying abnormal tool axes based on the difference between two adjacent tool axis vectors includes:
[0014] Project the tool axis vector onto a unit sphere and calculate the arc length between the current tool axis vector and the previous tool axis vector.
[0015] If the arc length is greater than the preset arc length, the current tool axis vector is determined to be an abnormal tool axis.
[0016] In one embodiment of the present invention, let the current tool axis vector be... The previous tool axis vector of the current tool axis is Projecting the tool axis vector onto a unit sphere and calculating the arc length between the current tool axis vector and the previous tool axis vector, including:
[0017] Will and Performing the dot product operation, we get and The cosine of the angle between them;
[0018] Perform inverse trigonometric function operations on the cosine value to obtain the arc length between the current tool axis vector and the previous tool axis vector.
[0019] In one embodiment of the present invention, several neighboring tool points are selected within the trajectory sub-segment where the abnormal tool axis is located, and the tool axis vector of the abnormal tool axis is optimized based on the tool axis vectors corresponding to the neighboring tool points, including:
[0020] The abnormal tool axis density is obtained by calculating the ratio of the abnormal tool axis corresponding to the tool position point within the trajectory sub-segment to the number of tool positions within the trajectory sub-segment.
[0021] When the abnormal tool axis density is less than or equal to the preset density, the tool axis vector corresponding to the two tool points adjacent to the abnormal tool axis is interpolated to obtain the optimized tool axis vector, and the tool axis vector of the abnormal tool axis is replaced with the optimized tool axis vector.
[0022] When the abnormal tool axis density is greater than the preset density, an overall smoothing strategy is applied to the tool axis vector corresponding to the tool position in the trajectory sub-segment to obtain the optimized tool axis vector corresponding to the tool position in the trajectory sub-segment, and the tool axis vector of the tool position in the trajectory sub-segment is replaced with the optimized tool axis vector.
[0023] In one embodiment of the present invention, the spatial coordinates of the tool position point of the abnormal tool axis are defined. The spatial coordinates of the two tool positions adjacent to the abnormal tool axis are respectively and The tool axis vector of the abnormal tool axis is The two tool axis vectors adjacent to the two tool positions adjacent to the abnormal tool axis are respectively and The optimized tool axis vector is obtained by interpolating the tool axis vectors corresponding to the two tool points adjacent to the abnormal tool axis, and the tool axis vector of the abnormal tool axis is replaced with the optimized tool axis vector, including:
[0024] calculate and Distance between ,as well as and Distance between ;
[0025] according to and Calculate the spherical interpolation coefficients ;
[0026] Quaternion spherical linear interpolation is performed on the abnormal tool axis. This yields the optimized tool axis vector; where, for and The angle between them;
[0027] Replace the abnormal tool axis vector with an optimized tool axis vector.
[0028] In one embodiment of the present invention, let the current tool axis vector within the trajectory segment be... The nearest tool axis vectors to the current tool axis within the trajectory sub-segment are: A global smoothing strategy is applied to the tool axis vectors corresponding to the tool positions within the trajectory sub-segment to obtain optimized tool axis vectors corresponding to the tool positions within the trajectory sub-segment. The tool axis vectors of the tool positions within the trajectory sub-segment are then replaced with the optimized tool axis vectors, including:
[0029] The current tool axis vector is calculated using a one-dimensional Gaussian kernel. With the adjacent tool axis vector Weighting coefficients ;in, For kernel bandwidth parameters;
[0030] Based on the weighting coefficients and the corresponding nearest tool axis vectors Calculate the weighted tool axis vector ;
[0031] The weighted tool axis vector is normalized to a unit sphere. The optimized tool axis vector is obtained, and the tool axis vector of the tool position within the trajectory sub-segment is replaced with the optimized tool axis vector.
[0032] Secondly, the present invention provides an optimization device for abnormal CNC toolpath tool axis, the optimization device comprising:
[0033] The file parsing module is used to parse the NC file representing the toolpath trajectory to obtain an ordered tool position sequence; wherein, the ordered tool position sequence includes the spatial coordinate information of each tool position in the toolpath trajectory and the tool axis rotation angle information;
[0034] The vector generation module is used to generate a tool axis vector based on the tool axis rotation angle information and the post-processing type of the NC file;
[0035] The anomaly detection module is used to identify abnormal tool axes based on the difference between two adjacent tool axis vectors;
[0036] The tool axis optimization module is used to select several neighboring tool points within the trajectory sub-segment where the abnormal tool axis is located, and optimize the tool axis vector of the abnormal tool axis according to the tool axis vector corresponding to the neighboring tool points; wherein, the trajectory sub-segment is a portion of the tool points intercepted in the ordered tool point sequence with the location of the abnormal tool axis as the center point.
[0037] Thirdly, the present invention provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the optimization method for abnormal CNC toolpaths of any of the above claims.
[0038] Fourthly, the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the optimization method for abnormal CNC toolpaths of any of the above claims.
[0039] Fifthly, the present invention provides a computer program product, including a computer program, which, when executed by a processor, causes the computer to perform the optimization method for abnormal CNC toolpaths described in any of the preceding claims.
[0040] This invention provides a method for optimizing abnormal tool axes in CNC toolpaths. By parsing the NC file to obtain a complete and ordered sequence of tool position points, a comprehensive and accurate data foundation is provided for subsequent tool axis vector generation and anomaly identification. Then, the tool axis vectors are projected onto a unit sphere, and abnormal tool axes are identified by calculating the arc length of adjacent vectors. For tool axis vectors with anomalies, the tool axis vectors of the abnormal tool axes are optimized based on the tool axis vectors corresponding to the adjacent tool position points. This eliminates the need to optimize the entire CNC toolpath file, thereby reducing the cost of tool axis optimization based on NC files to a certain extent. Attached Figure Description
[0041] To more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are merely some embodiments of the present invention, and those skilled in the art can obtain other embodiments based on these drawings without creative effort.
[0042] Figure 1 This is a flowchart illustrating a method for optimizing abnormal tool axes in CNC toolpaths according to an embodiment of the present invention.
[0043] Figure 2 This is a schematic diagram of a unit vector projected onto a unit sphere according to an embodiment of the present invention.
[0044] Figure 3 This is a schematic diagram illustrating the process of selecting different optimization strategies according to an embodiment of the present invention.
[0045] Figure 4(a) is a schematic diagram of quaternion interpolation on a unit sphere provided in an embodiment of the present invention.
[0046] Figure 4(b) is the front view corresponding to Figure 4(a).
[0047] Figure 5 This is a schematic diagram of the structure of a CNC toolpath abnormality tool axis optimization device provided in an embodiment of the present invention.
[0048] Figure 6 This is a schematic diagram of an electronic device provided according to an embodiment of the present invention. Detailed Implementation
[0049] Embodiments of the present invention will now be described in more detail with reference to the accompanying drawings. While some embodiments of the present invention are shown in the drawings, it should be understood that the present invention can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of the present invention. It should be understood that the drawings and embodiments of the present invention are for illustrative purposes only and are not intended to limit the scope of protection of the present invention.
[0050] In practical industrial applications, CNC machining sites often encounter situations where only existing NC files are available, but a complete workpiece geometric model cannot be obtained. For example, the NC program may originate from a third-party system, a historical project, or an external supplier, or the original CAM project may be unavailable due to data security concerns, version inconsistencies, or other reasons. In such scenarios, if the NC file contains local tool axis anomalies introduced by numerical errors, resampling, interpolation accuracy limitations, or data conversion, the problem can escalate.
[0051] Traditional tool axis optimization methods that rely on geometric models are difficult to apply directly, and regenerating the NC program may also destroy the original machining verification results and increase machining risks.
[0052] For the generated NC files, there are solutions in related technologies for post-processing correction of the tool axis direction. However, these solutions often treat the tool axis direction as a regular three-dimensional Euclidean vector, using uniform linear interpolation, spline interpolation, or overall smoothing to adjust the tool axis direction. The lack of differentiation in the distribution of abnormal tool axes within the toolpath sequence can easily lead to insufficient repair or excessive overall smoothing.
[0053] Therefore, how to perform reasonable geometric modeling, anomaly identification, and targeted repair of the tool axis direction based solely on the NC file itself, without requiring a workpiece geometry model or regenerating the NC program, has become a technical problem that needs to be solved in the existing technology.
[0054] Based on this, the present invention provides an optimization method for abnormal tool axes in CNC toolpaths. By parsing the NC file to obtain a complete and ordered sequence of tool position points, a comprehensive and accurate data foundation is provided for subsequent tool axis vector generation and anomaly identification. Then, the tool axis vector is projected onto a unit sphere, and the abnormal tool axis is identified by calculating the arc length of adjacent vectors. For tool axis vectors with anomalies, the tool axis vector of the abnormal tool axis is optimized based on the tool axis vectors corresponding to the adjacent tool position points. This eliminates the need to optimize the entire CNC toolpath file, thereby reducing the tool axis optimization cost based on the NC file to a certain extent.
[0055] Please see Figure 1The present invention provides a method for optimizing a CNC toolpath with an abnormal tool axis. This method may include the following steps.
[0056] Step S110: Parse the NC file representing the toolpath trajectory to obtain an ordered tool position sequence; wherein, the ordered tool position sequence includes the spatial coordinate information of each tool position in the toolpath trajectory and the tool axis rotation angle information.
[0057] In this embodiment, the CNC toolpath refers to the trajectory of the tool on the workpiece during CNC machining. It is the core basis for the machine tool to execute machining instructions and directly determines the machining shape and accuracy. An abnormal tool axis is a tool axis whose direction changes abruptly from the direction of the adjacent tool axis, which does not meet the requirements for the smoothness of the toolpath trajectory. This will lead to abrupt changes in the cutting angle and fluctuations in the cutting force.
[0058] In this embodiment, the full name is Numerical Control file, which is a file that stores CNC machine tool machining programs. It contains information such as G-code, M-code, toolpath, and machining parameters, and represents the toolpath. By parsing the NC file, tool position information can be extracted, and the instructions in the file can be converted into calculable and analyzable structured data.
[0059] In this embodiment, the ordered tool position sequence is a set of all tool positions arranged in the order of toolpath execution. Each tool position is a coordinate point on the toolpath trajectory and is the basic unit for tool axis attitude control. Spatial coordinate information refers to the position parameters of the tool position in three-dimensional space, typically represented by (x, y, z), used to determine the spatial position of the tool. Tool axis rotation angle information refers to the rotation angles of the tool axis around the X, Y, and Z axes of the machine tool, represented by A (around the X-axis), B (around the Y-axis), and C (around the Z-axis), respectively, used to determine the spatial attitude of the tool axis.
[0060] Step S120: Generate a tool axis vector based on the tool axis rotation angle information and the post-processing type of the NC file.
[0061] In this embodiment, the tool axis vector is a unit vector representing the spatial direction of the tool axis. It is derived from the tool axis rotation angle and is represented by (i,j,k). It can accurately describe the direction of the tool axis and is the core basis for judging whether the tool axis is abnormal.
[0062] In this embodiment, the post-processing type of the NC file is the axis configuration type of the CNC machine tool, the core of which is the combination method of the machine tool's rotary axes. Common types include AC machine type (A-axis + Z-axis) and BC machine type (B-axis + Z-axis). Different types of machine tools have different methods for calculating the tool axis distance. In other embodiments, the post-processing type of the NC file may also include turning, mill-turn, three-axis milling, four-axis milling, etc.
[0063] Step S130: Identify abnormal tool axes based on the difference between two adjacent tool axis vectors.
[0064] In this embodiment, identifying abnormal tool axes by the difference between adjacent tool axis vectors can more accurately capture abrupt changes in tool axis direction, avoiding missed or false detections caused by small changes in tool axis angle but abrupt changes in direction. The difference between two adjacent tool axis vectors can be determined based on the distance between the two vectors or the angle between the two adjacent tool axis vectors. When the distance or angle exceeds the corresponding threshold, it indicates that the tool axis swing is large, and the point is determined to be an abnormal point that needs correction.
[0065] Understandably, in some cases, due to the complexity of the machining process, tool axis control strategies (such as maintaining tool tip stability, avoiding interference, and optimizing cutting force direction) may cause the tool axis direction to deviate from its local trend at certain points. These types of tool axes need to be manually screened and eliminated. Therefore, after identifying an abnormal tool axis, it can be sent to a professional operator for confirmation. Once the professional operator has eliminated points mistakenly identified as abnormal tool axes, or confirmed that the identification is correct, subsequent operations can proceed.
[0066] Step S140: Select several neighboring tool points within the trajectory sub-segment where the abnormal tool axis is located, and optimize the tool axis vector of the abnormal tool axis according to the tool axis vector corresponding to the neighboring tool points; wherein, the trajectory sub-segment is a portion of tool points intercepted in the ordered tool point sequence with the location of the abnormal tool axis as the center point.
[0067] In this embodiment, the trajectory segment is a continuous segment of tool positions extracted from an ordered sequence of tool positions, with the tool position where the abnormal tool axis is located as the center point. The extraction range can be adjusted according to the machining accuracy requirements (usually including several tool positions before and after), and is used to select neighboring tool positions for optimization to ensure the locality and specificity of the optimization.
[0068] In this embodiment, the adjacent tool points are tool points within the trajectory sub-segment that are not the tool points of the abnormal tool axis. Their corresponding tool axis vectors can reflect the movement trend of the normal tool axis and provide a reference for the optimization of the abnormal tool axis. For example, by selecting 5 tool points before and after the abnormal tool axis, a total of 10 adjacent tool points are obtained, and the trajectory sub-segment includes a total of 11 tool points.
[0069] In this embodiment, different smoothing strategies can be adopted according to the different distributions of abnormal tool axes. If there are many abnormal tool axis points within the trajectory segment, smoothing can be achieved by using weighted averaging and normalization for that trajectory segment. Multiple iterations can be performed to apply weighted averaging to the abnormal tool axes, reducing their amplitude and achieving toolpath smoothing. Conversely, when there are isolated abnormal tool axis points within the trajectory segment, a smoothing interpolation algorithm can be used to bring the abnormal tool axis back to a path consistent with the local variation trend of the tool axis, based on the normal tool axes surrounding it.
[0070] In the above embodiments, an ordered tool position sequence is obtained by parsing the NC file, covering spatial coordinates and tool axis rotation angles, providing accurate and complete data support for subsequent tool axis vector generation and anomaly identification. Identifying abnormal tool axes by the differences between adjacent tool axis vectors allows for more accurate capture of abrupt changes in tool axis direction, avoiding missed or false detections caused by minor changes in tool axis angle but abrupt changes in direction. Then, optimization is performed on a segment-by-segment basis using neighboring tool axis vectors, ensuring smooth connection between the optimized tool axis vector and surrounding normal tool axis vectors, preventing secondary abrupt changes in the optimized tool axis direction, and guaranteeing the stability of the toolpath trajectory.
[0071] In some embodiments, the tool axis rotation angle information is defined as A around the X-axis, B around the Y-axis, and C around the Z-axis. In step S120, generating the tool axis vector based on the tool axis rotation angle information and the post-processing type of the NC file may include the following steps.
[0072] Step S121: When the post-processing type is AC, the tool axis vector... .
[0073] Step S122: When the post-processing type is BC, the tool axis vector... .
[0074] In this embodiment, A around the X-axis, B around the Y-axis, and C around the Z-axis are the three rotational degrees of freedom of the tool axis. A-axis is the rotation angle of the tool axis around the X-axis of the machine tool, B-axis is the rotation angle around the Y-axis, and C-axis is the rotation angle around the Z-axis. These three together determine the spatial orientation of the tool axis. The tool axis information is based on common conventions: A around the X-axis, B around the Y-axis, and C around the Z-axis, and the initial direction is obtained by right-multiplying the initial tool axis (0,0,1) by a rotation (i,j,k).
[0075] In this embodiment, the AC type refers to a post-processing type of CNC machine tool, which means that the machine tool adopts a combination of A-axis (rotation around the X-axis) and C-axis (rotation around the Z-axis) without a B-axis, and is often used in curved surface machining scenarios. The BC type is another post-processing type of CNC machine tool, which means that the machine tool adopts a combination of B-axis (rotation around the Y-axis) and C-axis (rotation around the Z-axis) without an A-axis, and is suitable for machining inclined surfaces at different angles.
[0076] In this embodiment, the tool axis vector formula is a mathematical formula derived based on the machine tool post-processing type. It is used to convert the tool axis rotation angles (A, B, C) into tool axis vectors (i, j, k) in three-dimensional space. The derivation of the formula is based on the principle of conversion between spherical coordinates and Cartesian coordinates.
[0077] In the above embodiments, a dedicated tool axis vector calculation formula is designed for the two mainstream post-processing types. This formula is derived based on the machine tool axis configuration principle and can accurately convert the tool axis rotation angle into a tool axis vector, avoiding abnormal tool axis identification errors caused by vector calculation deviations and providing a reliable vector basis for subsequent abnormal identification.
[0078] In some embodiments, in step S130, identifying abnormal tool axes based on the difference between two adjacent tool axis vectors may include the following steps.
[0079] Step S131: Project the tool axis vector onto a unit sphere and calculate the arc length between the current tool axis vector and the previous tool axis vector.
[0080] Step S132: If the arc length is greater than the preset arc length, the current tool axis vector is determined to be an abnormal tool axis.
[0081] In this embodiment, the unit sphere is a sphere with a radius of 1, and the tool axis vector is a unit vector (with a magnitude of 1), whose endpoint falls exactly on the unit sphere. By projecting the tool axis vector onto the unit sphere, the directional differences of the three-dimensional vectors can be converted into the distance between two points on the sphere.
[0082] In this embodiment, as Figure 2 As shown, projection is the process of mapping the tool axis vector onto a unit sphere. Essentially, it preserves the direction information of the vector and ignores the magnitude (since the tool axis vector is a unit vector, the magnitude is always 1), which facilitates the calculation of directional differences.
[0083] In this embodiment, the current tool axis vector and the previous tool axis vector are two adjacent tool axis vectors in an ordered tool position sequence, corresponding to the tool axis posture of the current tool position and the previous tool position, respectively. The difference between the two directly reflects the changing trend of the tool axis direction. The arc length is the shortest path length between the endpoints of the two tool axis vectors on a unit sphere, and its value is equal to the angle (radian value) between the two vectors. It can accurately quantify the directional difference between the two tool axis vectors. The larger the arc length, the greater the directional difference. The preset arc length is a manually set threshold for judging abnormal tool axes. It is adjusted according to factors such as machining accuracy, tool type, and workpiece material. If the arc length exceeds this threshold, it indicates that the sudden change in the tool axis direction exceeds the allowable range and is judged as abnormal.
[0084] In the above embodiments, unit spherical projection can avoid angle calculation errors caused by vector magnitude deviation, and arc length can more accurately reflect the degree of abrupt change in the tool axis direction, reducing the false positive and false negative rates. In addition, converting the tool axis direction difference into a specific arc length value provides a clear quantitative standard for anomaly judgment, avoiding inconsistencies in recognition caused by subjective judgment, and ensuring uniformity of recognition standards under different processing scenarios.
[0085] In some embodiments, let the current tool axis vector be... The previous tool axis vector of the current tool axis is In step S131, the tool axis vector is projected onto a unit sphere, and the arc length between the current tool axis vector and the previous tool axis vector is calculated. This may include the following steps.
[0086] Step S1311: ... and Performing the dot product operation, we get and The cosine of the angle between them.
[0087] Step S1312: Perform inverse trigonometric function operation on the cosine value to obtain the arc length between the current tool axis vector and the previous tool axis vector.
[0088] In this embodiment, and These represent the current tool axis vector and the previous tool axis vector, respectively. The i, j, and k in parentheses are the components of the vector on the X, Y, and Z coordinate axes, respectively, and are used to calculate the dot product and the angle between the vectors.
[0089] In this embodiment, the dot product operation is the dot product of two vectors, and the formula is: The result is equal to the product of the magnitudes of the two vectors and the cosine of the included angle. Since the tool axis vector is a unit vector with a magnitude of 1, the dot product result is equal to the cosine of the included angle.
[0090] In this embodiment, the inverse trigonometric function operation refers to the inverse cosine function operation (arccos), which is used to convert the cosine value obtained by the dot product into the angle (in radians) between two vectors. This angle is the arc length between the endpoints of the two vectors on a unit sphere. That is, the arc length is... .
[0091] In this embodiment, the angle (arc length) between two tool axis vectors can be accurately calculated through dot product and inverse trigonometric function operations. The calculation error is small, ensuring the accuracy of anomaly identification and avoiding misjudgments caused by incorrect arc length calculation. The calculation process is simple, requiring no complex geometric calculations, and has a fast calculation speed, enabling real-time processing of tool axis vectors in the toolpath trajectory, thus meeting the real-time requirements of CNC machining.
[0092] In some embodiments, step S140 may include the following steps: selecting several neighboring tool points within the trajectory sub-segment where the abnormal tool axis is located, and optimizing the tool axis vector of the abnormal tool axis based on the tool axis vector corresponding to the neighboring tool points.
[0093] Step S141: Calculate the ratio of the abnormal tool axis corresponding to the tool position point within the trajectory sub-segment to the number of tool positions within the trajectory sub-segment to obtain the abnormal tool axis density.
[0094] Step S142: When the abnormal tool axis density is less than or equal to the preset density, interpolation is performed using the tool axis vectors corresponding to the two tool positions adjacent to the abnormal tool axis to obtain the optimized tool axis vector, and the tool axis vector of the abnormal tool axis is replaced with the optimized tool axis vector.
[0095] Step S143: When the abnormal tool axis density is greater than the preset density, an overall smoothing strategy is adopted for the tool axis vector corresponding to the tool position in the trajectory sub-segment to obtain the optimized tool axis vector corresponding to the tool position in the trajectory sub-segment, and the tool axis vector of the tool position in the trajectory sub-segment is replaced with the optimized tool axis vector.
[0096] In this embodiment, the abnormal tool axis density is the ratio of the number of abnormal tool axes to the total number of tool positions within a trajectory sub-segment. This ratio is used to quantify the concentration of abnormal tool axes and distinguish between "a few isolated abnormalities" and "a large number of continuous abnormalities." The preset density is a manually set threshold for distinguishing the degree of abnormality, adjusted according to the machining scenario, and used to select the corresponding optimization strategy. Specifically, the abnormal tool axis density... It can be represented as: .in, This represents the number of abnormal tool axes within the trajectory sub-segment; This represents the total number of abnormal tool axes within the trajectory sub-segment. A preset density is defined. .when At that time, a small number of abnormal cutter shafts appeared in that section. For example, with a preset density of 20%, a density ≤20% indicates a small number of abnormalities, while a density >20% indicates a large number of continuous abnormalities.
[0097] In this embodiment, interpolation is a numerical calculation method that uses two adjacent normal tool axis vectors to calculate the optimized tool axis vector of the abnormal tool axis through a specific algorithm. This ensures a smooth transition between the optimized vector and adjacent vectors, making it suitable for optimizing a small number of isolated anomalies. It is understood that in other embodiments, interpolation can be performed using multiple adjacent normal tool axis vectors with different interpolation coefficients to obtain the optimized tool axis vector of the abnormal tool axis. The interpolation coefficients can be determined based on the distance to the tool position of the abnormal tool axis; the greater the distance, the lower the weighting coefficient.
[0098] In this embodiment, the overall smoothing strategy is to adjust all tool axis vectors within the trajectory sub-segment as a whole, so that the tool axis vectors of the entire sub-segment transition smoothly, eliminating the influence of multiple consecutive abnormal tool axes, which is suitable for the optimization of a large number of consecutive abnormalities.
[0099] In the above embodiments, different optimization strategies are selected based on the density of abnormal tool axes. For a small number of abnormalities, interpolation can preserve local trajectory details, while for a large number of abnormalities, overall smoothing can ensure overall continuity. This makes the optimized tool axis vector more closely match the motion trend of the normal toolpath trajectory, improving toolpath stability. In addition, interpolation optimization is simple and efficient, while the overall smoothing strategy, although computationally more complex, can completely solve the problem of continuous abnormalities. Combining the two ensures both optimization accuracy and efficiency.
[0100] Please see Figure 3 This invention identifies abnormal tool axes based on the toolpath sequence, then the operator confirms whether it is an abnormal tool axis, determines if it is an isolated abnormal tool axis, and then applies different optimization strategies. It is understood that in some embodiments, if the operator still feels the optimization is not satisfactory after the first optimization, the optimization process can continue based on the newly generated ordered tool point sequence until a satisfactory result is achieved. Then, the original NC file can be updated based on the optimization results of the abnormal tool axis.
[0101] In some embodiments, the spatial coordinates of the tool position point of the abnormal tool axis are set. The spatial coordinates of the two tool positions adjacent to the abnormal tool axis are respectively and The tool axis vector of the abnormal tool axis is The two tool axis vectors adjacent to the two tool positions adjacent to the abnormal tool axis are respectively and In step S142, the tool axis vectors corresponding to the two tool points adjacent to the abnormal tool axis are interpolated to obtain the optimized tool axis vector, and the tool axis vector of the abnormal tool axis is replaced with the optimized tool axis vector. This may include the following steps.
[0102] Step S1421: Calculate and Distance between ,as well as and Distance between .
[0103] Step S1422: According to and Calculate the spherical interpolation coefficients .
[0104] Step S1423: Perform quaternion spherical linear interpolation on the abnormal tool axis. This yields the optimized tool axis vector; where, for and The angle between them.
[0105] Step S1424: Replace the tool axis vector of the abnormal tool axis with the optimized tool axis vector.
[0106] In this embodiment, , , These represent the spatial coordinates of the tool position point where the abnormal tool axis is located, the previous adjacent tool position point, and the next adjacent tool position point, respectively, used to calculate the distance between the abnormal tool axis and the adjacent tool position points. Distance and These are the straight-line distances between the abnormal tool position and the adjacent tool positions before and after it, respectively. They are used to reflect the spatial relationship between the abnormal tool position and the adjacent tool positions. The closer the distance, the greater the reference value of the adjacent tool axis vector to the abnormal tool axis.
[0107] In this embodiment, the spherical interpolation coefficient t is based on the distance and The calculated interpolation weight coefficients take values in the range [0,1]. The closer the distance, the greater the weight of the corresponding neighboring tool axis vector, making the optimized vector more closely match the normal tool axis vector that is closer.
[0108] In this embodiment, quaternion spherical linear interpolation (Slert) is an algorithm for unit vector interpolation. It performs uniform interpolation along the great circle of a unit sphere, ensuring that the interpolated vector remains a unit vector with a smooth direction transition, avoiding abrupt changes in vector direction or magnitude deviations caused by linear interpolation. Slert is a stable and smooth interpolation algorithm that can adjust the abnormal tool axis to conform to the trend of local tool axis changes, based on the normal tool axis around the abnormal tool axis. As shown in Figure 4(a), and These are perspective views of the two tool axes adjacent to the abnormal tool axis, respectively. Figure 4(b) is the front view corresponding to Figure 4(a). Wherein, and The included angle between them is , and The angle between Therefore, quaternary spherical linear interpolation can be expressed as: Based on the interpolation results, the optimized tool axis vector can be obtained.
[0109] In this embodiment, after interpolation is completed, the optimized tool axis vector can be replaced with the original abnormal tool axis vector to optimize the tool axis path and enable the tool axis to transition smoothly.
[0110] In the above embodiments, quaternion spherical linear interpolation is used. Compared with traditional linear interpolation, this ensures that the optimized tool axis vector is always a unit vector with a smooth directional transition, avoiding abrupt changes in the tool axis direction after interpolation and improving toolpath stability. The interpolation coefficient is calculated based on the distance between abnormal tool points and adjacent tool points, with closer distances resulting in greater weights. This makes the optimized vector more closely match the normal tool axis movement trend, avoiding trajectory deviations caused by blind interpolation.
[0111] In some embodiments, the current tool axis vector within the trajectory segment is set as follows: The nearest tool axis vectors to the current tool axis within the trajectory sub-segment are: In step S143, an overall smoothing strategy is applied to the tool axis vector corresponding to the tool position within the trajectory sub-segment to obtain the optimized tool axis vector corresponding to the tool position within the trajectory sub-segment, and the tool axis vector of the tool position within the trajectory sub-segment is replaced with the optimized tool axis vector, which may include the following steps.
[0112] Step S1431: Calculate the current tool axis vector using a one-dimensional Gaussian kernel. With the adjacent tool axis vector Weighting coefficients ;in, This refers to the kernel bandwidth parameter.
[0113] Step S1432: Based on the weighting coefficients and the corresponding neighboring tool axis vectors Calculate the weighted tool axis vector .
[0114] Step S1433: Normalize the weighted tool axis vector to a unit sphere. The optimized tool axis vector is obtained, and the tool axis vector of the tool position within the trajectory sub-segment is replaced with the optimized tool axis vector.
[0115] In this embodiment, and These represent the current tool axis vector (which can be an abnormal or normal tool axis vector) and the neighboring tool axis vectors within the trajectory sub-segment, respectively. The neighboring tool axis vectors are the other tool axis vectors within the sub-segment besides the current vector, and are used to calculate the weighted average.
[0116] In this embodiment, the one-dimensional Gaussian kernel is a weighting function based on a Gaussian distribution. Its core characteristic is "the closer the distance, the greater the weight," used to calculate the weighting coefficients between the current tool axis vector and the vectors of neighboring tool axes, achieving weighted smoothing. In this embodiment, the kernel bandwidth parameter... It can be determined based on the radius corresponding to the current tool axis vector. For example, if the radius R=5, then the current tool axis vector is selected. The first 5 tool axis vectors and the last 5 tool axis vectors are used as the neighboring tool axis vectors. Then it can be set to... It is understandable that, in some other embodiments, the kernel bandwidth parameter... This can be set by the operator to adjust the concentration of weights. Weighting coefficients. It is calculated by a one-dimensional Gaussian kernel and reflects the degree of influence of the neighboring tool axis vector on the current tool axis vector. The closer to the current vector, the larger the weight coefficient, and vice versa.
[0117] In this embodiment, the weighted tool axis vector The intermediate vector is obtained by weighting the neighboring tool axis vectors using weighting coefficients. It integrates the information of all neighboring tool axis vectors within the sub-segment and reflects the overall trend of the tool axis vectors within the sub-segment.
[0118] In this embodiment, normalization is the process of weighting the tool axis vector. The process of converting to a unit vector is described by the formula: ( for (The modulus length) ensures that the optimized tool axis vector is a unit vector, which meets the requirements for representing the tool axis vector.
[0119] It should be noted that the above overall smoothing process can be iterated multiple times. By weighting and averaging the abnormal tool axis, the swing amplitude of the abnormal tool axis can be reduced, thereby achieving the purpose of smoothing the tool path and tool axis.
[0120] In the above embodiments, one-dimensional Gaussian kernel weighted smoothing is used, which can smooth abnormal tool axes while preserving the details of the toolpath trajectory to the greatest extent, avoiding trajectory distortion caused by over-smoothing, and balancing smoothness and detail preservation. By weighted averaging of the vectors of all adjacent tool axes within a sub-segment, the optimized tool axis vector conforms to the overall motion trend of the tool axis within the sub-segment, eliminating the influence of multiple consecutive abnormal tool axes and ensuring a smooth transition of the tool axis direction throughout the sub-segment. The normalization step ensures that the optimized tool axis vector is always a unit vector, avoiding tool axis attitude control errors caused by vector magnitude deviation, ensuring the stability of the machine tool machining process, and reducing tool wear and machine tool failure.
[0121] Please see Figure 5 One embodiment of the present invention provides an optimization device for abnormal CNC toolpath tool axis. The optimization device may include: a file parsing module, a vector generation module, an anomaly identification module, and a tool axis optimization module.
[0122] The file parsing module is used to parse the NC file representing the toolpath trajectory to obtain an ordered tool position sequence; wherein, the ordered tool position sequence includes the spatial coordinate information of each tool position in the toolpath trajectory and the tool axis rotation angle information.
[0123] The vector generation module is used to generate a tool axis vector based on the tool axis rotation angle information and the post-processing type of the NC file.
[0124] The anomaly identification module is used to identify abnormal tool axes based on the difference between two adjacent tool axis vectors.
[0125] The tool axis optimization module is used to select several neighboring tool points within the trajectory sub-segment where the abnormal tool axis is located, and optimize the tool axis vector of the abnormal tool axis according to the tool axis vector corresponding to the neighboring tool points; wherein, the trajectory sub-segment is a portion of the tool points intercepted in the ordered tool point sequence with the location of the abnormal tool axis as the center point.
[0126] The specific functions and effects of the optimization device for abnormal CNC toolpaths can be explained by referring to other embodiments in this specification, and will not be repeated here. Each module in the optimization device for abnormal CNC toolpaths can be implemented entirely or partially through software, hardware, or a combination thereof. Each module can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0127] Please see Figure 6 One embodiment of the present invention can provide an electronic device, the electronic device comprising:
[0128] A memory, and one or more processors communicatively connected to the memory;
[0129] The memory stores instructions that can be executed by the one or more processors, which, when executed by the one or more processors, enable the one or more processors to implement the optimization method for abnormal CNC toolpaths described in any of the above embodiments.
[0130] One embodiment of the present invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the optimization method for abnormal CNC toolpaths of any of the above embodiments.
[0131] This specification also provides a computer program product containing instructions that, when executed by a computer, cause the computer to perform the optimization method for abnormal CNC toolpaths described in any of the above embodiments.
[0132] It is understood that the specific examples in this document are only intended to help those skilled in the art better understand the embodiments described herein, and are not intended to limit the scope of the invention.
[0133] It is understood that in the various embodiments described in this specification, the sequence number of each process does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments described in this specification.
[0134] It is understood that the various implementation methods described in this specification can be implemented individually or in combination, and the implementation methods in this specification are not limited in this respect.
[0135] Unless otherwise stated, all technical and scientific terms used in the embodiments of this specification have the same meaning as commonly understood by one of ordinary skill in the art. The terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the scope of this specification. The term "and / or" as used in this specification includes any and all combinations of one or more of the associated listed items. The singular forms "a," "the," and "the" as used in the embodiments of this specification and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise.
[0136] It is understood that the processor in this invention can be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method implementation can be completed by the integrated logic circuitry in the processor's hardware or by instructions in software form. The processor can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this specification. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this specification can be directly embodied in the execution of a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in memory; the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above method.
[0137] It is understood that the memory in this invention can be volatile memory or non-volatile memory, or may include both. Specifically, the non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM). It should be noted that the memory in the systems and methods described herein is intended to include, but is not limited to, these and any other suitable types of memory.
[0138] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in the embodiments of the present invention are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.
[0139] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this specification.
[0140] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the aforementioned method implementations, and will not be repeated here.
[0141] In the several embodiments provided in this specification, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0142] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.
[0143] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0144] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of this specification, in essence, or the parts that contribute to the prior art, or parts of the technical solutions, can be embodied in the form of software products. These computer software products are stored in a storage medium and include several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this specification. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0145] The above description is merely a specific embodiment of this specification, but the scope of protection of this invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this specification should be included within the scope of protection of this specification. Therefore, the scope of protection of this invention should be determined by the scope of the claims.
Claims
1. A method for optimizing the tool axis in CNC toolpath abnormalities, characterized in that, The method includes: The NC file representing the toolpath trajectory is parsed to obtain an ordered tool position sequence; wherein, the ordered tool position sequence includes the spatial coordinate information of each tool position in the toolpath trajectory and the tool axis rotation angle information; Based on the tool axis rotation angle information and the post-processing type of the NC file, a tool axis vector is generated; Identify abnormal tool axes based on the difference between two adjacent tool axis vectors; Within the trajectory segment where the abnormal tool axis is located, several adjacent tool points are selected, and the tool axis vector of the abnormal tool axis is optimized based on the tool axis vectors corresponding to the adjacent tool points; wherein, the trajectory segment is a portion of the tool points extracted from the ordered tool point sequence with the location of the abnormal tool axis as the center point.
2. The method according to claim 1, characterized in that, Let the tool axis rotation angle information be A around the X-axis, B around the Y-axis, and C around the Z-axis. Based on the tool axis rotation angle information and the post-processing type of the NC file, a tool axis vector is generated, including: In the case of the post-processing type being AC, the tool axis vector ; In the case of the post-processing type being BC, the tool axis vector .
3. The method according to claim 1, characterized in that, Based on the difference between two adjacent tool axis vectors, abnormal tool axes are identified, including: Project the tool axis vector onto a unit sphere and calculate the arc length between the current tool axis vector and the previous tool axis vector. If the arc length is greater than the preset arc length, the current tool axis vector is determined to be an abnormal tool axis.
4. The method according to claim 3, characterized in that, wherein... The current tool axis vector is The previous tool axis vector of the current tool axis is Projecting the tool axis vector onto a unit sphere and calculating the arc length between the current tool axis vector and the previous tool axis vector, including: Will and Performing the dot product operation, we get and The cosine of the angle between them; Perform inverse trigonometric function operations on the cosine value to obtain the arc length between the current tool axis vector and the previous tool axis vector.
5. The method according to claim 1, characterized in that, Within the trajectory sub-segment where the abnormal tool axis is located, several adjacent tool position points are selected, and the tool axis vector of the abnormal tool axis is optimized based on the tool axis vectors corresponding to the adjacent tool position points, including: The abnormal tool axis density is obtained by calculating the ratio of the abnormal tool axis corresponding to the tool position point within the trajectory sub-segment to the number of tool positions within the trajectory sub-segment. When the abnormal tool axis density is less than or equal to the preset density, the tool axis vector corresponding to the two tool points adjacent to the abnormal tool axis is interpolated to obtain the optimized tool axis vector, and the tool axis vector of the abnormal tool axis is replaced with the optimized tool axis vector. When the abnormal tool axis density is greater than the preset density, an overall smoothing strategy is applied to the tool axis vector corresponding to the tool position in the trajectory sub-segment to obtain the optimized tool axis vector corresponding to the tool position in the trajectory sub-segment, and the tool axis vector of the tool position in the trajectory sub-segment is replaced with the optimized tool axis vector.
6. The method according to claim 5, characterized in that, Let the spatial coordinates of the tool position point of the abnormal tool axis be... The spatial coordinates of the two tool positions adjacent to the abnormal tool axis are respectively and The tool axis vector of the abnormal tool axis is The two tool axis vectors adjacent to the two tool positions adjacent to the abnormal tool axis are respectively and The optimized tool axis vector is obtained by interpolating the tool axis vectors corresponding to the two tool points adjacent to the abnormal tool axis, and the tool axis vector of the abnormal tool axis is replaced with the optimized tool axis vector, including: calculate and Distance between ,as well as and Distance between ; according to and Calculate the spherical interpolation coefficients ; Quaternion spherical linear interpolation is performed on the abnormal tool axis. This yields the optimized tool axis vector; where, for and The angle between them; Replace the abnormal tool axis vector with an optimized tool axis vector.
7. The method according to claim 5, characterized in that, Let the current tool axis vector within the trajectory sub-segment be... The nearest tool axis vectors to the current tool axis within the trajectory sub-segment are: A global smoothing strategy is applied to the tool axis vectors corresponding to the tool positions within the trajectory sub-segment to obtain optimized tool axis vectors corresponding to the tool positions within the trajectory sub-segment. The tool axis vectors of the tool positions within the trajectory sub-segment are then replaced with the optimized tool axis vectors, including: The current tool axis vector is calculated using a one-dimensional Gaussian kernel. With the adjacent tool axis vector Weighting coefficients ;in, For kernel bandwidth parameters; Based on the weighting coefficients and the corresponding nearest tool axis vectors Calculate the weighted tool axis vector ; The weighted tool axis vector is normalized to a unit sphere. The optimized tool axis vector is obtained, and the tool axis vector of the tool position point within the trajectory sub-segment is replaced with the optimized tool axis vector.
8. A device for optimizing the tool axis of an abnormal CNC toolpath, characterized in that, The optimization device for abnormal CNC toolpaths includes: The file parsing module is used to parse the NC file representing the toolpath trajectory to obtain an ordered tool position sequence; wherein, the ordered tool position sequence includes the spatial coordinate information of each tool position in the toolpath trajectory and the tool axis rotation angle information; The vector generation module is used to generate a tool axis vector based on the tool axis rotation angle information and the post-processing type of the NC file; An anomaly detection module is used to identify abnormal tool axes based on the difference between two adjacent tool axis vectors; The tool axis optimization module is used to select several neighboring tool points within the trajectory sub-segment where the abnormal tool axis is located, and optimize the tool axis vector of the abnormal tool axis according to the tool axis vector corresponding to the neighboring tool points; wherein, the trajectory sub-segment is a portion of the tool points intercepted in the ordered tool point sequence with the location of the abnormal tool axis as the center point.
9. An electronic device, characterized in that, The system includes a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the optimization method for abnormal CNC toolpaths of any one of claims 1 to 7.
10. A computer storage medium, characterized in that, It stores a computer program, which, when executed by a processor, implements the optimization method for abnormal CNC toolpaths as described in any one of claims 1 to 7.