Trajectory Fitting Method, Device, Equipment and Storage Medium
By fitting the point columns of three-dimensional space free curves in a straight line and an arc, the generality problem of trajectory fitting of three-dimensional space free curves in the prior art is solved, and efficient trajectory fitting suitable for machine tool processing is achieved.
Patent Information
- Application Number
- CN202210948225.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-09
- Publication Date
- 2025-06-10
- Estimated Expiration
- 2042-08-09
AI Technical Summary
The trajectory fitting method for plane free curves in the prior art cannot be directly applied to free curves in three-dimensional space, and there is a problem of low versatility.
By obtaining the point column composed of at least three spatial discrete points, the line fitting is performed using the least squares method according to the preset line fitting mode. If the line fitting fails, the arc fitting is performed to determine the fitting trajectory corresponding to the point column.
The trajectory fitting of three-dimensional space free curves is achieved, and the radius of curvature of the trajectory is easy to calculate. It is suitable for trajectory interpolation and speed planning in machine tool processing, and has high applicability and versatility.
Smart Images

Figure CN115373338B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of trajectory fitting, and particularly to a trajectory fitting method, device, equipment and storage medium. Background Art
[0002] In the field of machine tool machining, trajectory planning for the shape of the workpiece to be machined is a very important link in machine tool machining, and trajectory fitting is a significant technology in trajectory planning. At present, there are many studies on the trajectory fitting technology for planar free curves. Although the existing trajectory fitting technologies are relatively mature, these technologies are mainly for planar free curves and cannot be directly applied to free curves in three-dimensional space, resulting in the problem of low generality. Summary of the Invention
[0003] The main purpose of the present invention is to provide a trajectory fitting method, device, equipment and storage medium, aiming to solve the technical problem that the trajectory fitting method for planar free curves in the existing technology is not applicable to free curves in three-dimensional space and has low generality.
[0004] To achieve the above object, the present invention adopts the following technical solutions:
[0005] In the first aspect, the present invention provides a trajectory fitting method, and the method includes:
[0006] Obtain a point sequence composed of at least three spatial discrete points;
[0007] According to a preset straight line fitting mode, use the least squares method to perform straight line fitting on the point sequence to obtain a first fitting straight line;
[0008] When the straight line fitting fails, use the least squares method to perform circular arc fitting on the point sequence to obtain a fitting circular arc, where the straight line fitting fails means that the first fitting straight line does not meet the preset error condition;
[0009] Determine the fitting trajectory corresponding to the point sequence according to the first fitting straight line or the fitting circular arc.
[0010] Optionally, in the above trajectory fitting method, the step of using the least squares method to perform straight line fitting on the point sequence according to a preset straight line fitting mode to obtain a first fitting straight line includes:
[0011] When the preset straight line fitting mode is the first straight line fitting mode, use the least squares method to perform straight line fitting on the point sequence according to the starting point of the point sequence to obtain a first straight line;
[0012] When the preset straight line fitting mode is the second straight line fitting mode, use the least squares method to perform straight line fitting on the point sequence according to the end point of the point sequence to obtain a second straight line;
[0013] When the preset straight line fitting mode is the third straight line fitting mode, according to the midpoint of the line connecting the starting point and the ending point of the point sequence, the point sequence is linearly fitted by using the least square method to obtain a third straight line;
[0014] When the preset straight line fitting mode is the fourth straight line fitting mode, record the midpoints of the lines connecting any two points in the point sequence to obtain a point set;
[0015] For each recorded point in the point set, the point sequence is linearly fitted by using the least square method to obtain multiple candidate straight lines;
[0016] Calculate the sum of the distances from each point in the point sequence to the multiple candidate straight lines respectively, and determine the candidate straight line corresponding to the minimum sum of the distances as the fourth straight line;
[0017] Determine the first straight line, the second straight line, the third straight line or the fourth straight line as the first fitting straight line.
[0018] Optionally, in the above trajectory fitting method, the step of obtaining a point sequence composed of at least three spatially discrete points includes:
[0019] Obtain N discrete points in a three-dimensional space, where N is a positive integer and N≥3;
[0020] Extract any at least three discrete points from the N discrete points to obtain a point sequence composed of the i-th point to the m-th point, where both i and m are positive integers, and i<m≤N;
[0021] After the step of determining the fitting trajectory corresponding to the point sequence according to the first fitting straight line or the fitting circular arc, the method further includes:
[0022] Set the value of i to m - 1 and the value of m to m + 1 to obtain a new point sequence composed of the i-th point to the m-th point, and repeat the step of linearly fitting the point sequence by using the least square method according to the preset straight line fitting mode to obtain the fitting trajectory corresponding to the new point sequence until all the N discrete points are traversed to obtain multiple fitting trajectories;
[0023] Stitch the multiple fitting trajectories to obtain the final trajectory corresponding to the N discrete points.
[0024] Optionally, in the above trajectory fitting method, after the step of linearly fitting the point sequence by using the least square method according to the preset straight line fitting mode to obtain the first fitting straight line, the method further includes:
[0025] Calculate the distances from each point in the point sequence to the first fitting straight line respectively to obtain a maximum first distance;
[0026] Compare the maximum value of the first distance with the preset straight line fitting error value;
[0027] If the maximum value of the first distance is less than the preset straight line fitting error value, it is determined that the straight line fitting is successful;
[0028] Store the first fitted straight line into the fitting matrix, set the value of m to m + 1, re-obtain the point sequence formed by the i-th point to the m-th point, and return to the step of using the least squares method to perform straight line fitting on the point sequence according to the preset straight line fitting mode to obtain the first fitted straight line until the maximum value of the first distance is greater than or equal to the preset straight line fitting error value;
[0029] If the maximum value of the first distance is greater than or equal to the preset straight line fitting error value, it is determined that the straight line fitting fails, and execute the step of using the least squares method to perform circular arc fitting on the point sequence to obtain the fitted circular arc.
[0030] Optionally, in the above trajectory fitting method, after the step of using the least squares method to perform circular arc fitting on the point sequence to obtain the fitted circular arc, the method further includes:
[0031] Calculate the distances between each point in the point sequence and the fitted circular arc respectively to obtain the maximum value of the second distance;
[0032] Compare the maximum value of the second distance with the preset circular arc fitting error value;
[0033] If the maximum value of the second distance is less than the preset circular arc fitting error value, it is determined that the circular arc fitting is successful;
[0034] Store the fitted circular arc into the fitting matrix, set the value of m to m + 1, re-obtain the point sequence formed by the i-th point to the m-th point, and return to the step of using the least squares method to perform circular arc fitting on the point sequence to obtain the fitted circular arc until the maximum value of the second distance is greater than or equal to the preset circular arc fitting error value;
[0035] If the maximum value of the second distance is greater than or equal to the preset circular arc fitting error value, it is determined that the circular arc fitting fails, and execute the step of determining the fitting trajectory corresponding to the point sequence according to the first fitted straight line or the fitted circular arc.
[0036] Optionally, in the above trajectory fitting method, the step of determining the fitting trajectory corresponding to the point sequence according to the first fitted straight line or the fitted circular arc includes:
[0037] Judge whether there is a fitted circular arc stored in the fitting matrix;
[0038] If there is a fitted circular arc stored in the fitting matrix, the fitted circular arc stored in the fitting matrix most recently is determined as the fitting trajectory corresponding to the i-th point to the (m-1)-th point in the point sequence;
[0039] If there is no fitted circular arc stored in the fitting matrix, the fitted straight line stored in the fitting matrix most recently is determined as the fitting trajectory corresponding to the i-th point to the (m-1)-th point in the point sequence.
[0040] Optionally, in the above trajectory fitting method, before the step of performing circular arc fitting on the point sequence by using the least square method to obtain a fitted circular arc, the method further includes:
[0041] When the straight line fitting fails, it is judged whether the number of spatially discrete points in the point sequence is greater than three;
[0042] If the number of spatially discrete points in the point sequence is greater than three, the step of performing circular arc fitting on the point sequence by using the least square method to obtain a fitted circular arc is executed;
[0043] If the number of spatially discrete points in the point sequence is equal to three, the line connecting the first point and the second point in the point sequence is determined as the second fitted straight line;
[0044] The second fitted straight line is stored in the fitting matrix, and the step of determining the fitting trajectory corresponding to the point sequence according to the first fitted straight line or the fitted circular arc is executed.
[0045] In a second aspect, the present invention provides a trajectory fitting device, and the device includes:
[0046] A point sequence acquisition module, configured to acquire a point sequence composed of at least three spatially discrete points;
[0047] A straight line fitting module, configured to perform straight line fitting on the point sequence by using the least square method according to a preset straight line fitting mode to obtain a first fitted straight line;
[0048] A circular arc fitting module, configured to perform circular arc fitting on the point sequence by using the least square method when the straight line fitting fails, to obtain a fitted circular arc, where the straight line fitting fails means that the first fitted straight line does not meet the preset error condition;
[0049] A trajectory acquisition module, configured to determine the fitting trajectory corresponding to the point sequence according to the first fitted straight line or the fitted circular arc.
[0050] In a third aspect, the present invention provides a trajectory fitting device, and the trajectory fitting device includes a processor and a memory, and a trajectory fitting program is stored in the memory. When the trajectory fitting program is executed by the processor, the above trajectory fitting method is implemented.
[0051] Fourthly, the present invention provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by one or more processors, the above-mentioned trajectory fitting method is implemented.
[0052] One or more of the above technical solutions provided by the present invention may have the following advantages or at least achieve the following technical effects:
[0053] A trajectory fitting method, device, equipment and storage medium provided by the present invention obtain a point sequence composed of at least three spatial discrete points; according to a preset straight line fitting mode, use the least square method to perform straight line fitting on the point sequence to obtain a first fitting straight line; when the first fitting straight line does not meet the preset error condition, use the least square method to perform circular arc fitting on the point sequence to obtain a fitting circular arc; according to the first fitting straight line or the fitting circular arc, determine the fitting trajectory corresponding to the point sequence, achieving the purpose of fitting the trajectory of a three-dimensional space free curve. The fitting trajectory obtained from a spatial straight line or a spatial circular arc is convenient to calculate the curvature radius of the trajectory, providing convenience for operations such as trajectory interpolation, speed and acceleration planning after trajectory fitting in machine tool processing. Considering the characteristics of the machine tool processing field, it is more suitable for the spatial trajectory planning during machine tool processing and has high applicability; perform corresponding straight line fitting according to the preset straight line fitting mode, obtain the fitting straight line in different ways, and the error accuracy is controllable, which can meet the different requirements of different machine tools for trajectory fitting and has high generality. Description of the Drawings
[0054] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these provided drawings.
[0055] Figure 1 It is a schematic flowchart of the first embodiment of the trajectory fitting method of the present invention;
[0056] Figure 2 It is a schematic hardware structure diagram of the trajectory fitting equipment related to the present invention;
[0057] Figure 3 It is a schematic flowchart of the second embodiment of the trajectory fitting method of the present invention;
[0058] Figure 4 It is a schematic functional module diagram of the first embodiment of the trajectory fitting device of the present invention.
[0059] The realization, functional features and advantages of the present invention will be further described with reference to the embodiments and the accompanying drawings. Detailed implementation manners
[0060] To make the objectives, technical solutions and advantages of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Apparently, the described embodiments are only a part rather than all of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without any creative efforts shall fall within the protection scope of the present invention.
[0061] It should be noted that in the present invention, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements not only includes those elements but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or system. Without further limitations, the elements defined by the statement "include..." do not exclude the existence of additional identical elements in the process, method, article or system including such element. In the present invention, if there are descriptions involving "first", "second", etc., such descriptions of "first", "second", etc. are only for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the quantity of the indicated technical features. Thus, the features defined with "first", "second" may expressly or implicitly include at least one such feature. In the present invention, the suffixes such as "module", "component" or "unit" used to represent elements are only for the convenience of describing the present invention and have no specific meaning in themselves. Therefore, "module", "component" or "unit" can be used interchangeably.
[0062] For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances. In addition, the technical solutions of each embodiment can be combined with each other, provided that those of ordinary skill in the art can implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be considered that such a combination of technical solutions does not exist and is not within the protection scope required by the present invention.
[0063] With the development of the times, machine tool processing technology has been applied to all walks of life. Due to the differences in industries and the diversity of requirements, the geometric shapes of workpieces to be processed are also different, enabling the wide application of objects with the shape of a spatial free curve. To a certain extent, it has prompted technicians to develop trajectory fitting technologies with stronger functions, greater degrees of freedom, and better meeting the usage requirements.
[0064] Analysis of the existing technology reveals that most trajectory fittings are based on given discrete points, that is, by collecting the coordinate information of a series of points on the workpiece to be machined, a point cloud of coordinates is obtained, and through reverse reconstruction of the acquired point cloud, the geometric shape of the workpiece to be machined is reconstructed.
[0065] Currently, there are many studies on the trajectory fitting technology for planar free curves. For example, the technology of using straight lines and arcs to fit digital planar free curves based on dynamic design methods, and also, technologies such as studying straight lines and arcs to fit planar free curves based on genetic algorithms, fitting planar free curves by setting error precision, and fitting planar free curves by using planar spline curves.
[0066] Although the existing trajectory fitting technologies are relatively mature, these technologies are mainly for planar free curves and cannot be directly applied to free curves in three-dimensional space, resulting in the problem of low generality. At the same time, the existing trajectory fitting technologies often can only achieve trajectory fitting in a geometric sense. When the fitted trajectory is used subsequently, the radius of curvature needs to be calculated and the calculation amount is large, resulting in low utilization rate of the trajectory, and it cannot take into account the convenience of subsequent operations such as interpolation calculation and speed planning during machine tool processing, resulting in low interpolation efficiency.
[0067] In view of the technical problems that the trajectory fitting method for planar free curves in the existing technology is not applicable to free curves in three-dimensional space, with low generality and low utilization rate of the fitted trajectory, the present invention provides a trajectory fitting method, and the general idea is as follows:
[0068] Obtain a point sequence composed of at least three spatial discrete points; according to a preset straight line fitting mode, use the least squares method to perform straight line fitting on the point sequence to obtain a first fitted straight line; when the straight line fitting fails, use the least squares method to perform circular arc fitting on the point sequence to obtain a fitted circular arc, where the straight line fitting fails means that the first fitted straight line does not meet the preset error condition; determine the fitted trajectory corresponding to the point sequence according to the first fitted straight line or the fitted circular arc.
[0069] Through the above technical solutions, the purpose of trajectory fitting for free curves in three-dimensional space is achieved. The fitted trajectory obtained from a spatial straight line or a spatial circular arc is convenient for calculating the radius of curvature of the trajectory, providing convenience for operations such as trajectory interpolation, speed and acceleration planning after trajectory fitting in machine tool processing. Considering the characteristics of the machine tool processing field, it is more suitable for spatial trajectory planning during machine tool processing and has high applicability; perform corresponding straight line fitting according to the preset straight line fitting mode, obtain fitted straight lines in different ways, and the error precision is controllable, which can meet the different requirements of different machine tools for trajectory fitting and has high generality.
[0070] The following will combine with the accompanying drawings to elaborate in detail on the trajectory fitting method, device, equipment, and storage medium provided by the present invention through specific embodiments and implementation manners.
[0071] Embodiment 1
[0072] Referring to Figure 1 the flowchart shown in
[0073] A trajectory fitting device refers to a terminal device or a system device capable of establishing a communication connection. It can be a terminal device such as an embedded industrial control computer for controlling a machine tool, or a system device such as a control system for controlling a machine tool.
[0074] As Figure 2 shown, it is a schematic diagram of the hardware structure of the trajectory fitting device. The trajectory fitting device may include: a processor 1001, such as a CPU (Central Processing Unit), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Those skilled in the art can understand that Figure 2 the hardware structure shown in
[0075] does not constitute a limitation to the trajectory fitting device of the present invention, and it may include more or fewer components than those shown, or combine certain components, or have different component arrangements. Figure 2 Specifically, the communication bus 1002 is used to realize the connection and communication between these components; the user interface 1003 is used to connect to the client and conduct data communication with the client. The user interface 1003 may include an output unit, such as a display screen, and an input unit, such as a keyboard; the network interface 1004 is used to connect to the background control center and conduct data communication with the background control center. The network interface 1004 may include an input / output interface, such as a standard wired interface, a wireless interface, such as a Wi-Fi interface; the memory 1005 is used to store various types of data. These data may include, for example, instructions of any application program or method in the trajectory fitting device, as well as data related to the application program. The memory 1005 may be a high-speed RAM memory or a stable memory, such as a disk memory; optionally, the memory 1005 may also be a storage device independent of the processor 1001. Continuing to refer to Figure 2 , the memory 1005 may include an operating system, a network communication module, a user interface module, and a trajectory fitting program; the processor 1001 is used to call the trajectory fitting program stored in the memory 1005 and perform the following operations:
[0076] Obtain a point sequence composed of at least three spatially discrete points;
[0077] According to the preset straight line fitting mode, the least squares method is used to fit the point sequence into a straight line to obtain the first fitting straight line;
[0078] When the straight line fitting fails, the least squares method is used to fit the point sequence into an arc to obtain the fitting arc, where the straight line fitting failure means that the first fitting straight line does not meet the preset error condition;
[0079] According to the first fitting straight line or the fitting arc, the fitting trajectory corresponding to the point sequence is determined.
[0080] Based on the above trajectory fitting device, the following combines Figure 1 the shown process schematic diagram to describe the trajectory fitting method of this embodiment in detail. The method may include the following steps:
[0081] Step S100: Obtain a point sequence composed of at least three spatially discrete points.
[0082] Specifically, spatially discrete points refer to acquisition points with a certain distance interval in three-dimensional space. These acquisition points can be set based on the three-dimensional space free curve contour of the target processed product, so that the finally obtained trajectory can be used to control the processing part of the machine tool to process according to this trajectory, and a processed product corresponding to the spatial surface contour can be obtained. Among them, the target processed product can be a product sample obtained by the user based on drawing software, and different spatially discrete points can be represented by different coordinate information, while the sorting of the spatially discrete points can be set according to actual needs. A point sequence refers to a set composed of multiple points, here it is a set composed of at least three spatially discrete points. The number of spatially discrete points can be set according to actual situations. For example, a preset number of spatially discrete points are directly calibrated by the user, or several spatially discrete points are extracted from a large number of spatially discrete points calibrated by the user. At least three spatially discrete points are to ensure the successful progress of trajectory fitting. If there are less than three, the trajectory of the three-dimensional space free curve will become a broken line trajectory formed by two adjacent spatially discrete points, and a smooth trajectory cannot be obtained, and thus a processed product closer to the actual product surface contour cannot be obtained.
[0083] Step S300: According to the preset straight line fitting mode, use the least squares method to fit the point sequence into a straight line to obtain the first fitting straight line.
[0084] Specifically, there can be multiple straight line fitting modes, and the preset straight line fitting mode refers to any one of the multiple preset straight line fitting modes. The least squares method can find the best function matching of the data by minimizing the sum of the squares of the errors. Using the least squares method, unknown data can be simply obtained, and the sum of the squares of the errors between the obtained data and the actual data is minimized. Here, after using the least squares method to fit at least three spatially discrete points in the point sequence into a straight line, a fitting straight line, that is, the first fitting straight line, can be obtained.
[0085] Optionally, after obtaining the first fitted straight line, it can be determined whether the first fitted straight line meets the preset error condition. When the first fitted straight line meets the preset error condition, it is determined that the straight line fitting is successful; otherwise, it is determined that the straight line fitting fails. When the straight line fitting is successful, it can jump to step S700 for execution; when the straight line fitting fails, step S500 is executed. When the straight line fitting is successful, the first fitted straight line can be directly determined as the fitting trajectory, or the spatial discrete points in the point sequence can be added to continue the straight line fitting to obtain a new first fitted straight line as the fitting trajectory; when the straight line fitting fails, the arc fitting method can be used to try to obtain the fitting trajectory.
[0086] Step S500: When the straight line fitting fails, use the least squares method to perform arc fitting on the point sequence to obtain a fitted arc, where the straight line fitting failure means that the first fitted straight line does not meet the preset error condition.
[0087] Specifically, when the straight line fitting fails, it means that the first fitted straight line obtained by performing straight line fitting on the spatial discrete points in the current point sequence does not meet the preset error condition and cannot be used as the fitting trajectory corresponding to the spatial discrete points in the current point sequence. At this time, the least squares method can be used to perform arc fitting on the spatial discrete points in the current point sequence again to obtain an arc, that is, the fitted arc.
[0088] Optionally, after obtaining the fitted arc, it can be determined whether the fitted arc meets the preset error condition. When the fitted arc meets the corresponding preset error condition, it is determined that the arc fitting is successful; otherwise, it is determined that the arc fitting fails. Further optionally, when the arc fitting is successful, step S700 can be executed; when the arc fitting fails, this round of process can be ended or step S100 can be returned to re-determine the point sequence.
[0089] Step S700: Determine the fitting trajectory corresponding to the point sequence according to the first fitted straight line or the fitted arc.
[0090] Specifically, when performing linear fitting on at least three spatially discrete points in a point sequence to obtain a first fitted line, the fitting trajectory corresponding to the point sequence can be determined based on the first fitted line, that is, the first fitted line can be directly determined as the fitting trajectory corresponding to the point sequence; alternatively, when it is determined that the first fitted line meets the preset error condition, the first fitted line can be determined as the fitting trajectory corresponding to the point sequence; when the obtained first fitted line does not meet the preset error condition, perform circular arc fitting on at least three spatially discrete points in the point sequence. After obtaining the fitted circular arc, the fitting trajectory corresponding to the point sequence can be determined based on the fitted circular arc, that is, the fitted circular arc can be directly determined as the fitting trajectory corresponding to the point sequence; alternatively, when it is determined that the fitted circular arc meets the corresponding preset error condition, the fitted circular arc can be determined as the fitting trajectory corresponding to the point sequence; or when it is determined that the fitted circular arc does not meet the corresponding preset error condition, end this round of process or return to step S100 to re-determine the point sequence.
[0091] Optionally, when it is determined that the first fitted line meets the preset error condition, the first fitted line can be temporarily stored, and then steps S100 and S300 are repeatedly executed to obtain a new point sequence and the corresponding new first fitted line, and the new first fitted line is temporarily stored. Repeating the above steps means executing multiple rounds of processes until it is determined that the new first fitted line does not meet the preset error condition. After performing circular arc fitting on the new point sequence to obtain a fitted circular arc, when it is determined that the fitted circular arc does not meet the corresponding preset error condition, the first fitted line temporarily stored most recently is used as the final result, that is, the first fitted line obtained from the previous round of process. After performing circular arc fitting on the new point sequence to obtain a fitted circular arc, when it is determined that the fitted circular arc meets the corresponding preset error condition, the fitted circular arc can be temporarily stored, and then steps S100, S300, and S500 are repeatedly executed to obtain a new point sequence and the corresponding new fitted circular arc, and the new fitted circular arc is temporarily stored. Continuing to repeat the above steps means executing multiple rounds of processes again until it is determined that the new fitted circular arc does not meet the corresponding preset error condition, and the fitted circular arc temporarily stored most recently is used as the final result, that is, the fitted circular arc obtained from the previous round of process. Among them, the new point sequence can be obtained by adding a subsequent spatially discrete point to the original at least three spatially discrete points, that is, the starting point in the point sequence corresponding to the final result of the above repeatedly executed process is the same as the starting point in the point sequence composed of the at least three spatially discrete points obtained at the beginning.
[0092] The method of this embodiment can be repeatedly executed for numerous spatially discrete points in practical applications to achieve trajectory fitting for numerous spatially discrete points, so that the obtained trajectory meets the requirements of practical applications on the basis of meeting the preset error condition. This method combines the linear fitting method and the circular arc fitting method, which not only realizes the linear fitting corresponding to different fitting modes, but also ensures the fitting success rate and reduces trajectory segmentation.
[0093] The trajectory fitting method provided in this embodiment obtains a point sequence composed of at least three spatially discrete points; according to a preset linear fitting mode, the least squares method is used to perform linear fitting on the point sequence to obtain a first fitting line; when the first fitting line does not meet the preset error condition, the least squares method is used to perform circular arc fitting on the point sequence to obtain a fitting circular arc; according to the first fitting line or the fitting circular arc, the fitting trajectory corresponding to the point sequence is determined, achieving the purpose of fitting the trajectory of a three-dimensional space free curve. The fitting trajectory obtained from a spatial straight line or a spatial circular arc is convenient for calculating the curvature radius of the trajectory, providing convenience for operations such as trajectory interpolation, speed and acceleration planning after trajectory fitting in machine tool processing, taking into account the characteristics of the machine tool processing field, being more suitable for spatial trajectory planning during machine tool processing, and having high applicability; corresponding linear fitting is performed according to the preset linear fitting mode to obtain fitting lines in different ways, and the error accuracy is controllable, which can meet the different requirements of different machine tools for trajectory fitting and has high generality.
[0094] Embodiment 2
[0095] Based on the same inventive concept, referring to Figure 3 , the second embodiment of the trajectory fitting method of the present invention is proposed, and this trajectory fitting method is also applied to a trajectory fitting device.
[0096] Next, in combination with Figure 3 the following flow schematic diagram, the trajectory fitting method of this embodiment will be described in detail. The method may include the following steps:
[0097] Step S100: Obtain a point sequence composed of at least three spatially discrete points;
[0098] Further, step S100 may include:
[0099] Step S110: Obtain N discrete points in a three-dimensional space, where N is a positive integer and N≥3;
[0100] Step S120: Extract any at least three discrete points from the N discrete points to obtain a point sequence composed of the i-th point to the m-th point, where i and m are both positive integers, and i<m≤N.
[0101] Specifically, N may be a relatively large number. Extracting at least three discrete points, correspondingly, the difference between i and m is at least 2. After obtaining N discrete points in a three-dimensional space, any at least three discrete points are extracted from these N discrete points. In this embodiment, the extraction of three discrete points is taken as an example for illustration. To ensure that trajectory fitting is achieved for all points in the N discrete points, when the first process of this method is executed for the first time, i can take the value of 1. Combining the limitation of extracting at least three discrete points, at this time m can take the value of 3. That is to say, the initial value of i is 1, and the initial value of m is 3.
[0102] In this embodiment, it is assumed that N = 10 discrete points are obtained. First, a point sequence A[1, 2, 3] composed of the 1st to 3rd points is extracted from these 10 discrete points.
[0103] Step S300: According to a preset line fitting mode, use the least squares method to perform line fitting on the point sequence to obtain a first fitted line.
[0104] Specifically, the number of preset line fitting modes and the corresponding specific line fitting methods can be set according to the actual situation. To be more comprehensive and adaptable to various application requirements, this embodiment provides four different line fitting methods. In practical applications, different representation symbols can be set for these four different line fitting methods. For example, a fitting mode value Mode is set, and the four different line fitting methods are represented by 1 - 4 respectively. Of course, other characters can also be used to represent different line fitting methods. Setting the fitting mode value can facilitate users to select a suitable line fitting method, that is, to obtain a preset line fitting mode. Then, based on the preset line fitting mode, perform line fitting on the point sequence by the least squares method to obtain a first fitted line, where the line fitting is a spatial line fitting operation.
[0105] Furthermore, step S300 may include:
[0106] Step S310: When the preset line fitting mode is the first line fitting mode, according to the starting point of the point sequence, use the least squares method to perform line fitting on the point sequence to obtain a first line.
[0107] In the first line fitting mode, the specific fitting method is to pass through the starting point of the point sequence, that is, the i-th point, and perform line fitting on the i-th to m-th points in the point sequence to obtain a straight line, that is, the first line.
[0108] In this embodiment, when the preset line fitting mode is the first line fitting mode, pass through the starting point of point sequence A, that is, the 1st point, and use the least squares method to perform line fitting on the 1st to 3rd points to obtain a first line.
[0109] Step S320: When the preset line fitting mode is the second line fitting mode, according to the end point of the point sequence, use the least squares method to perform line fitting on the point sequence to obtain a second line.
[0110] In the second line fitting mode, the specific fitting method is to pass through the end point of the point sequence, that is, the m-th point, and perform line fitting on the i-th to m-th points in the point sequence to obtain a straight line, that is, the second line.
[0111] In this embodiment, when the preset straight line fitting mode is the second straight line fitting mode, passing through the end point of the point sequence A, i.e., the 3rd point, the first to the 3rd points are linearly fitted by using the least square method to obtain the second straight line.
[0112] Step S330: When the preset straight line fitting mode is the third straight line fitting mode, according to the midpoint of the line connecting the start point and the end point of the point sequence (i.e., the midpoint of the line connecting the ith point and the mth point), the point sequence is linearly fitted by using the least square method to obtain the third straight line.
[0113] In the third straight line fitting mode, the specific fitting method is to first obtain the midpoint of the line connecting the start point of the point sequence, i.e., the ith point, and the end point of the point sequence, i.e., the mth point, and then passing through this midpoint, linearly fit the points from the ith point to the mth point in the point sequence to obtain a straight line, i.e., the third straight line.
[0114] In this embodiment, when the preset straight line fitting mode is the third straight line fitting mode, passing through the midpoint of the line connecting the 1st point and the 3rd point, the first to the 3rd points are linearly fitted by using the least square method to obtain the third straight line.
[0115] Step S340: When the preset straight line fitting mode is the fourth straight line fitting mode, according to the set of points corresponding to the midpoints of the lines connecting any two points in the point sequence, the point sequence is linearly fitted by using the least square method to obtain the fourth straight line.
[0116] Specifically, step S340 may include:
[0117] Step S341: When the preset straight line fitting mode is the fourth straight line fitting mode, record the midpoints of the lines connecting any two points in the point sequence to obtain a set of points;
[0118] Step S342: For each recorded point in the set of points, linearly fit the point sequence by using the least square method to obtain multiple candidate straight lines;
[0119] Step S343: Calculate the sum of the distances from each point in the point sequence to the multiple candidate straight lines respectively, and determine the candidate straight line corresponding to the minimum sum of distances as the fourth straight line.
[0120] In the fourth straight-line fitting mode, the specific fitting method is as follows: First, arbitrarily select two points from the point sequence. These two points can be repeatedly extracted points. Record the midpoint of the line connecting these two points. For all points in the point sequence, multiple ways of arbitrarily selecting two points can be combined. Record the midpoints of the line segments under all point-taking situations to obtain a point set. Then, for each recorded point in the point set, passing through this recorded point, use the least squares method to perform straight-line fitting on the i-th point to the m-th point in the point sequence to obtain the corresponding straight line. After performing this operation on all recorded points in the point set, multiple corresponding straight lines, that is, multiple candidate straight lines, can be obtained. Then, calculate the sum of the distances from each point in the point sequence to the candidate straight lines respectively, so that multiple sums of distances corresponding to the multiple candidate straight lines can be obtained. After the calculation is completed and these sums of distances are obtained, compare these sums of distances, select the minimum value of the sum of distances, and then determine the candidate straight line corresponding to this minimum value as the fitted straight line, that is, the fourth straight line.
[0121] In this embodiment, when the preset straight-line fitting mode is the fourth straight-line fitting mode, the point sequence A composed of the 1st point to the 3rd point can be combined in three ways of taking points: (1, 2), (1, 3), and (2, 3). Among them, the 1st point is repeated in two point-taking operations. Based on the above point-taking methods, record the midpoint of the line connecting the 1st point and the 2nd point, the midpoint of the line connecting the 1st point and the 3rd point, and the midpoint of the line connecting the 2nd point and the 3rd point. Recording these three midpoints constitutes a point set. Then, for each recorded point in the point set, that is, each midpoint, passing through this midpoint, perform straight-line fitting on the 1st point to the 3rd point in the point sequence A to obtain a straight line. After traversing all recorded points in the point set, three straight lines, that is, three candidate straight lines, can be obtained. Then, calculate the sum of the distances from the 1st point to the 3rd point in the point sequence A to the first candidate straight line respectively, the sum of the distances to the second candidate straight line respectively, and the sum of the distances to the third candidate straight line respectively. Then, select the minimum sum of distances from these three results. Assuming that the sum of the distances of the third candidate straight line is the smallest, correspondingly, the third candidate straight line can be determined as the fourth straight line.
[0122] It should be noted that the above three straight-line fitting methods are provided to meet different straight-line fitting requirements. In order to more accurately determine the most suitable fitting straight line and prevent the fitting straight lines obtained directly passing through the starting point, the ending point, and the midpoint of the line connecting the starting point and the ending point from being not appropriate enough when the number of discrete points in the point sequence is large, the fourth straight-line fitting method, that is, the fourth straight-line fitting mode, is added. It can be understood that the calculation amounts of the first to the third straight-line fitting modes are all small, but the accuracy is not high. However, they are completely sufficient for point sequences with a small number of points. The fourth straight-line fitting mode has a large calculation amount, but the error is small and the accuracy is high. When the user needs to fit a straight line more accurately to obtain a more accurate trajectory, this mode can be selected.
[0123] Step S350: Determine the first straight line, the second straight line, the third straight line, or the fourth straight line as the first fitted straight line.
[0124] In this embodiment, assuming that the corresponding straight line is obtained in any of the above ways, this step determines the obtained corresponding straight line as the first fitted straight line L1.
[0125] Four different straight line fitting methods are provided. In a one - out - of - four manner, a preset straight line fitting mode is selected based on user experience, and then straight line fitting is performed accordingly to obtain the first fitted straight line, achieving the effects of controllable fitting accuracy and meeting various fitting requirements.
[0126] Step S400: Determine whether the first fitted straight line meets the preset error condition. When the first fitted straight line meets the preset error condition, it is determined that the straight line fitting is successful; otherwise, it is determined that the straight line fitting fails.
[0127] Specifically, step S400 may include:
[0128] Step S410: Calculate the distances between each point in the point sequence and the first fitted straight line to obtain the maximum first distance.
[0129] In this embodiment, calculate the distances between the first point to the third point in the point sequence A and the first fitted straight line L1, and select the maximum value among them to obtain the maximum first distance dis_max1.
[0130] Step S420: Compare the maximum first distance with the preset straight line fitting error value.
[0131] In this embodiment, compare the maximum first distance dis_max1 with the preset straight line fitting error value wc_dis1, where the preset straight line fitting error value wc_dis1 can be a value set by the user.
[0132] Step S430: If the maximum first distance is less than the preset straight line fitting error value, it is determined that the straight line fitting is successful.
[0133] Correspondingly, the maximum first distance obtained based on the distances between each point in the point sequence and the first fitted straight line being less than the preset straight line fitting error value is the preset error condition, and the criterion for determining successful straight line fitting is that the first fitted straight line meets this preset error condition.
[0134] In this embodiment, assuming dis_max1 < wc_dis1, it indicates that the straight line fitting for the point sequence A composed of the first point to the third point is successful.
[0135] Step S440: Store the first fitted straight line into the fitting matrix, set the value of m to m + 1, re-obtain the point sequence formed by the i-th point to the m-th point, and return to the step of performing straight line fitting on the point sequence by using the least squares method according to the preset straight line fitting mode to obtain the first fitted straight line until the maximum value of the first distance is greater than or equal to the preset straight line fitting error value.
[0136] In this embodiment, when the straight line fitting is successful, the first fitted straight line L1 can be stored into the fitting matrix M. At the same time, set m = m + 1, that is, m = 4. Extract the first point to the fourth point from 10 discrete points, and then re-obtain the point sequence B[1, 2, 3, 4] formed by the first point to the fourth point. Repeat steps S300 and S400 to obtain the first fitted straight line L2. If after the comparison in step S420, dis_max1 < wc_dis1 is still satisfied, it can be determined that the straight line fitting of the current process is also successful. Then, this first fitted straight line L2 can also be stored into the fitting matrix M, and continue to take m = 5 to re-obtain the point sequence C[1, 2, 3, 4, 5] formed by the first point to the fifth point. Repeat steps S300 and S400 to obtain the first fitted straight line L3, and so on in a loop until dis_max1 ≥ wc_dis1.
[0137] In this embodiment, assume that the point sequence D[1, 2, 3, 4, 5, 6] formed by the first point to the sixth point is re-obtained, steps S300 and S400 are repeated to obtain the first fitted straight line L4. After the comparison in step S420, if dis_max1 ≥ wc_dis1, then after step S420, directly execute step S450.
[0138] Step S450: If the maximum value of the first distance is greater than or equal to the preset straight line fitting error value, determine that the straight line fitting fails, and execute the step of performing circular arc fitting on the point sequence by using the least squares method to obtain the fitted circular arc.
[0139] In this embodiment, based on the above settings, if dis_max1 ≥ wc_dis1, it means that the straight line fitting of the point sequence D formed by the first point to the sixth point fails. At this time, on this basis, step S500 can be executed to perform circular arc fitting on the point sequence D.
[0140] Step S500: When the straight line fitting fails, perform circular arc fitting on the point sequence by using the least squares method to obtain the fitted circular arc, where the straight line fitting failure means that the first fitted straight line does not meet the preset error condition.
[0141] Specifically, when the first fitted straight line does not meet the preset error condition, that is, when the maximum value of the first distances obtained based on the distances between the points in the point sequence and the first fitted straight line is greater than or equal to the preset straight line fitting error value, after determining that the straight line fitting fails, the least squares method can be used to perform circular arc fitting on the i-th point to the m-th point in the point sequence. This circular arc fitting is a spatial circular arc fitting operation. Spatial circular arc fitting is to fit a circular arc based on the given spatial discrete points, and this circular arc satisfies the following condition: the sum of the distances from the participating spatial discrete points to this circular arc is locally minimized. After performing circular arc fitting on the point sequence, the corresponding fitted circular arc can be obtained.
[0142] In this embodiment, based on the above settings, when the straight line fitting of the point sequence D fails, the least squares method can be used to perform circular arc fitting on the 1st point to the 6th point in the point sequence D to obtain the fitted circular arc Arc1.
[0143] Step S600: Determine whether the fitted circular arc meets the preset error condition. When the fitted circular arc meets the corresponding preset error condition, it is determined that the circular arc fitting is successful; otherwise, it is determined that the circular arc fitting fails.
[0144] Specifically, step S600 may include:
[0145] Step S610: Calculate the distances between the points in the point sequence and the fitted circular arc respectively to obtain the maximum value of the second distances.
[0146] In this embodiment, calculate the distances between the 1st point to the 6th point in the point sequence D and the fitted circular arc Arc1 respectively, and select the maximum value among them to obtain the maximum value of the second distances dis_max2.
[0147] Step S620: Compare the maximum value of the second distances with the preset circular arc fitting error value.
[0148] In this embodiment, compare the maximum value of the second distances dis_max2 with the preset circular arc fitting error value wc_dis2. Among them, the preset circular arc fitting error value wc_dis2 can be a value set by the user.
[0149] Step S630: If the maximum value of the second distances is less than the preset circular arc fitting error value, it is determined that the circular arc fitting is successful.
[0150] Correspondingly, the maximum value of the second distances obtained based on the distances between the points in the point sequence and the fitted circular arc being less than the preset circular arc fitting error value is the corresponding preset error condition, and the criterion for determining the success of the circular arc fitting is that the fitted circular arc meets this corresponding preset error condition.
[0151] In this embodiment, assuming dis_max2 < wc_dis2, it indicates that the circular arc fitting of the point sequence D composed of the 1st point to the 6th point is successful.
[0152] Step S640: Store the fitted circular arc into the fitting matrix, set the value of m to m + 1, re-obtain the point sequence formed by the i-th point to the m-th point, and return to the step of performing circular arc fitting on the point sequence using the least squares method to obtain the fitted circular arc until the second maximum distance is greater than or equal to the preset circular arc fitting error value.
[0153] In this embodiment, when the circular arc fitting is successful, the fitted circular arc Arc1 can be stored into the fitting matrix M. At the same time, set m = m + 1, that is, m = 7, and continue to extract the 1st point to the 7th point from 10 discrete points, then re-obtain the point sequence E[1, 2, 3, 4, 5, 6, 7] formed by the 1st point to the 7th point, return to execute steps S500 and S600 to obtain the fitted circular arc Arc2. If after the comparison in step S620, dis_max2 < wc_dis2 is still satisfied, it can be determined that the circular arc fitting of the current process is also successful, and then this fitted circular arc Arc2 can also be stored into the fitting matrix M, and continue to take m = 8 until dis_max2 ≥ wc_dis2.
[0154] In this embodiment, assume that when re-obtaining the point sequence F[1, 2, 3, 4, 5, 6, 7, 8] formed by the 1st point to the 8th point and repeating the execution of steps S500 and S600, the obtained fitted circular arc Arc3, after the comparison in step S620, dis_max2 ≥ wc_dis2, then after step S620, directly execute step S650.
[0155] Step S650: If the second maximum distance is greater than or equal to the preset circular arc fitting error value, then determine that the circular arc fitting fails, and execute the step of determining the fitting trajectory corresponding to the point sequence according to the first fitted straight line or the fitted circular arc.
[0156] In this embodiment, based on the above settings, if dis_max2 ≥ wc_dis2, it indicates that the circular arc fitting of the point sequence formed by the 1st point to the 8th point fails. At this time, on this basis, step S700 can be executed to obtain the fitting trajectory of the first stage.
[0157] Step S700: Determine the fitting trajectory corresponding to the point sequence according to the first fitted straight line or the fitted circular arc.
[0158] Specifically, when the straight line fitting of the point sequence corresponding to m = N is successful, the first fitted straight line corresponding to the current point sequence can be used as the fitting trajectory corresponding to the point sequence; when the straight line fitting of the point sequence corresponding to m = N fails, but the circular arc fitting continues to be successful, the fitted circular arc corresponding to the current point sequence can be used as the fitting trajectory corresponding to the point sequence.
[0159] For example, in this embodiment, assume that m = N = 3. After step S430, step S700 can be executed. That is, when the linear fitting of the point sequence A composed of points 1 to 3 is successful, the first fitting line L1 is used as the fitting trajectory corresponding to the point sequence A. Another example, in this embodiment, assume that m = N = 6. After step S630, step S700 can be executed. That is, when the circular arc fitting of the point sequence D composed of points 1 to 6 is successful, the fitting circular arc Arc1 is used as the fitting trajectory corresponding to the point sequence D. Correspondingly, assume that m = N = 7. When the circular arc fitting of the point sequence E composed of points 1 to 7 is successful, the fitting circular arc Arc2 is used as the fitting trajectory corresponding to the point sequence E.
[0160] When the linear fitting of the point sequence corresponding to m < N fails and the circular arc fitting also fails, based on the current point sequence, steps S300 - S420, S450 - 620, and S650 are executed, and step S700 will continue to be executed.
[0161] Correspondingly, step S700 may include:
[0162] Step S710: Determine whether there is a stored fitting circular arc in the fitting matrix.
[0163] In this embodiment, determine whether there is a stored fitting circular arc in the fitting matrix M.
[0164] Step S720: If there is a stored fitting circular arc in the fitting matrix, determine the fitting circular arc stored in the fitting matrix most recently as the fitting trajectory corresponding to the i-th point to the (m - 1)-th point in the point sequence.
[0165] In this embodiment, based on the above settings, assume that the circular arc fitting of the point sequence F composed of points 1 to 8 fails. After step S650, step S710 is executed, and it can be obtained that there is a stored fitting circular arc in the fitting matrix M. At this time, the fitting circular arc stored in the fitting matrix M most recently can be determined as the fitting trajectory corresponding to the i-th point to the (m - 1)-th point in the point sequence. That is to say, it can be obtained that there are stored fitting circular arcs Arc1 and Arc2 in the fitting matrix M. At this time, the fitting circular arc Arc2 stored in the fitting matrix M most recently can be determined as the fitting trajectory corresponding to points 1 to 7.
[0166] Step S730: If there is no stored fitting circular arc in the fitting matrix, determine the fitting line stored in the fitting matrix most recently as the fitting trajectory corresponding to the i-th point to the (m - 1)-th point in the point sequence.
[0167] In this embodiment, based on the above settings, assuming that the arc fitting of the point sequence D composed of the first to the sixth points fails, after executing steps S650 and S710, it can be obtained that there is no stored fitting arc in the fitting matrix M. At this time, the fitting line stored most recently in the fitting matrix M can be determined as the fitting trajectory corresponding to the i-th point to the (m - 1)-th point in the point sequence. That is to say, the first fitting line L3 stored most recently in the fitting matrix M can be determined as the fitting trajectory corresponding to the first point to the fifth point.
[0168] Further, after step S700, the method may further include:
[0169] Step S800: Set the value of i to m - 1 and the value of m to m + 1 to obtain a new point sequence composed of the i-th point to the m-th point, and repeat the step of performing linear fitting on the point sequence using the least squares method according to the preset linear fitting mode to obtain the fitting trajectory corresponding to the new point sequence until all the N discrete points are traversed to obtain multiple fitting trajectories.
[0170] Specifically, the fitting trajectory corresponding to the point sequence may not be the final trajectory corresponding to all N discrete points. In this case, when the arc fitting fails, the fitting trajectory corresponding to the previous point sequence of the current point sequence can be retained as the fitting trajectory in the first stage. That is, after obtaining the fitting trajectory corresponding to the i-th point to the (m - 1)-th point in the point sequence, i = m - 1 and m = m + 1 can be set to obtain a new point sequence composed of three discrete points, that is, taking the end point of the previous point sequence as the starting point of the starting point sequence of the next stage, re-extracting three spatial discrete points, and then repeating the above steps. It is also possible to continuously expand the end point of the new point sequence and continue to loop and execute the above steps until the fitting trajectory in the second stage is obtained. By looping in this way, fitting trajectories in multiple stages can be obtained, that is, multiple fitting trajectories can be obtained.
[0171] In this embodiment, based on the above settings, for the point sequence F composed of the first to the eighth points, if in step S700, the fitting arc Arc2 stored most recently in the fitting matrix M is finally determined as the fitting trajectory corresponding to the first point to the seventh point, then next, with i = m - 1 = 8 - 1 = 7 and m = m + 1 = 8 + 1 = 9, a new point sequence composed of the seventh point to the ninth point is obtained. After repeating all the above steps, assuming that the point sequence composed of the seventh point to the ninth point is successfully linearly fitted, a new point sequence composed of the seventh point to the tenth point will be obtained again. Assuming that the linear fitting fails at this time and arc fitting is performed to obtain the fitting arc Arc4, and assuming that the arc fitting is successful, the fitting arc obtained at this time can be used as the fitting trajectory corresponding to the point sequence composed of the seventh point to the tenth point. At this time, two fitting trajectories are obtained, namely the arc Arc2 and the arc Arc4.
[0172] Step S900: Stitch the multiple fitted trajectories to obtain the final trajectory corresponding to the N discrete points.
[0173] Specifically, after traversing the N discrete points, completing the fitted trajectories of all stages, and obtaining multiple fitted trajectories, all the fitted trajectories of all stages can be stitched to obtain the final trajectory corresponding to the N spatial discrete points.
[0174] In this embodiment, based on the above settings, after obtaining Arc2 and Arc4 in step S800, Arc2 and Arc4 can be stitched to obtain the final trajectory corresponding to 10 discrete points. At this time, the trajectory fitting of the N discrete points is considered completed.
[0175] On the basis of meeting the preset error condition, continuously increase as many spatial discrete points in the point sequence as possible, so as to obtain more fitted trajectories corresponding to spatial discrete points, minimize the segmentation of the trajectory of the three-dimensional space free curve, and increase the smoothness of the trajectory.
[0176] In another embodiment, before step S500, the method may further include:
[0177] Step A1: When the straight line fitting fails, determine whether the number of spatial discrete points in the point sequence is greater than three;
[0178] Step A2: If the number of spatial discrete points in the point sequence is greater than three, perform the step of using the least squares method to perform circular arc fitting on the point sequence to obtain the fitted circular arc;
[0179] Step A3: If the number of spatial discrete points in the point sequence is equal to three, determine the line connecting the first point and the second point in the point sequence as the second fitted straight line;
[0180] Step A4: Store the second fitted straight line into the fitting matrix, and perform the step of determining the fitted trajectory corresponding to the point sequence according to the first fitted straight line or the fitted circular arc.
[0181] Specifically, before the linear fitting fails and the curve fitting of step S500 needs to be performed, it is also possible to determine whether the number of spatial discrete points in the point sequence is greater than three, or in other words, to determine whether the difference between m and i is equal to 2; if the number of spatial discrete points in the point sequence is greater than three, or in other words, the difference between m and i is greater than 2, it is possible to jump to and execute step S500; if the number of spatial discrete points in the point sequence is equal to three, or in other words, the difference between m and i is equal to 2, at this time, the line connecting the first point and the second point in the point sequence can be determined as the second fitting line, or in other words, the line connecting the i-th point and the (i + 1)-th point can be determined as the second fitting line; after obtaining the second fitting line, the second fitting line can be stored in the fitting matrix for possible use in different situations when executing step S700. For example, when the fitting line stored in the fitting matrix most recently is to be used, the second fitting line can also be the fitting line stored in the fitting matrix most recently.
[0182] In this embodiment, if different from the hypothetical example in step S430, when comparing in step S420, based on the fact that the maximum first distance dis_max1 obtained from the distances between the points in point sequence A and the first fitting line L1 is ≥ wc_dis1, it is determined that the linear fitting based on point sequence A fails, and it is possible to directly jump to and execute step S450, thereby executing step S500 to perform circular arc fitting on point sequence A. At this time, in this implementation manner, before executing step S500, first determine whether the number of spatial discrete points in point sequence A is greater than three. Correspondingly, it can be obtained that the number of spatial discrete points in point sequence A is equal to three. At this time, the line connecting the 1st point and the 2nd point in point sequence A can be determined as the second fitting line Y1, and then step S700 is executed to determine it as the fitting trajectory corresponding to the 1st point to the 2nd point, completing the trajectory fitting in the first stage. Then, step S800 can be executed to perform the trajectory fitting in the second stage based on the 3rd point to the 5th point.
[0183] This implementation manner mainly provides an alternative solution for some situations where the linear fitting of a point sequence containing at least three spatial discrete points fails at the beginning, so as to meet the needs of more users.
[0184] For more implementation details in the specific implementation manners of the above method steps, reference can be made to the description of the specific implementation manner in Embodiment 1. For the sake of brevity of the specification, it will not be repeated here.
[0185] The trajectory fitting method provided in this embodiment can be applied to machine tool machining. Based on the given three-dimensional spatial discrete points, a trajectory fitting method with controllable error precision and relatively large fitting freedom and flexibility is proposed. At the same time, it can also take into account the different requirements for trajectory fitting in different situations such as trajectory interpolation, speed, and acceleration control in the machine tool machining scenario, has good versatility, and also lays a foundation for subsequent trajectory interpolation calculation, making the trajectory interpolation calculation more efficient.
[0186] Embodiment III
[0187] Based on the same inventive concept, with reference to Figure 4 , a first embodiment of the trajectory fitting device of the present invention is proposed. The trajectory fitting device can be a virtual device and is applied to a trajectory fitting device.
[0188] Next, with reference to Figure 4 the schematic diagram of functional modules shown below, the trajectory fitting device provided in this embodiment will be described in detail. The device may include:
[0189] A point sequence acquisition module, configured to acquire a point sequence composed of at least three spatially discrete points;
[0190] A straight line fitting module, configured to perform straight line fitting on the point sequence by using the least squares method according to a preset straight line fitting mode to obtain a first fitting straight line;
[0191] An arc fitting module, configured to perform arc fitting on the point sequence by using the least squares method to obtain a fitting arc when the straight line fitting fails, where the straight line fitting fails means that the first fitting straight line does not meet the preset error condition;
[0192] A trajectory acquisition module, configured to determine a fitting trajectory corresponding to the point sequence according to the first fitting straight line or the fitting arc.
[0193] Further, the straight line fitting module may include:
[0194] A first straight line fitting unit, configured to perform straight line fitting on the point sequence by using the least squares method according to the starting point of the point sequence to obtain a first straight line when the preset straight line fitting mode is the first straight line fitting mode;
[0195] A second straight line fitting unit, configured to perform straight line fitting on the point sequence by using the least squares method according to the end point of the point sequence to obtain a second straight line when the preset straight line fitting mode is the second straight line fitting mode;
[0196] A third straight line fitting unit, configured to perform straight line fitting on the point sequence by using the least squares method according to the midpoint of the line connecting the starting point and the end point of the point sequence to obtain a third straight line when the preset straight line fitting mode is the third straight line fitting mode;
[0197] A fourth straight line fitting unit, configured to record the midpoints of the connections between any two points in the point sequence to obtain a point set when the preset straight line fitting mode is the fourth straight line fitting mode; for each recorded point in the point set, perform straight line fitting on the point sequence by using the least squares method to obtain multiple candidate straight lines; calculate the sum of the distances from each point in the point sequence to the multiple candidate straight lines respectively, and determine the candidate straight line corresponding to the minimum sum of distances as the fourth straight line;
[0198] A fitting straight line obtaining unit, configured to determine the first straight line, the second straight line, the third straight line, or the fourth straight line as the first fitting straight line.
[0199] Further, the point sequence obtaining module may include:
[0200] A discrete point obtaining unit, configured to obtain N discrete points in a three-dimensional space, where N is a positive integer and N≥3;
[0201] A point sequence obtaining unit, configured to extract any at least three discrete points from the N discrete points to obtain a point sequence formed by the i-th point to the m-th point, where both i and m are positive integers, and i<m≤N;
[0202] Correspondingly, the apparatus may further include:
[0203] A loop execution module, configured to set the value of i to m - 1, set the value of m to m + 1, obtain a new point sequence formed by the i-th point to the m-th point, and repeatedly execute the step of performing straight line fitting on the point sequence by using the least squares method according to a preset straight line fitting mode to obtain a fitting trajectory corresponding to the new point sequence until all the N discrete points are traversed to obtain multiple fitting trajectories;
[0204] A splicing module, configured to splice the multiple fitting trajectories to obtain a final trajectory corresponding to the N discrete points.
[0205] Further, the apparatus may further include:
[0206] A first execution module, configured to calculate the distances between the points in the point sequence and the first fitting straight line respectively to obtain a maximum first distance; compare the maximum first distance with a preset straight line fitting error value; if the maximum first distance is less than the preset straight line fitting error value, determine that the straight line fitting is successful; store the first fitting straight line into a fitting matrix, set the value of m to m + 1, re-obtain a point sequence formed by the i-th point to the m-th point, and return to the step of performing straight line fitting on the point sequence by using the least squares method according to the preset straight line fitting mode to obtain the first fitting straight line until the maximum first distance is greater than or equal to the preset straight line fitting error value; if the maximum first distance is greater than or equal to the preset straight line fitting error value, determine that the straight line fitting fails, and execute the step of performing circular arc fitting on the point sequence by using the least squares method to obtain a fitting circular arc.
[0207] Further, the apparatus may further include:
[0208] A second execution module, configured to calculate the distances between each point in the point sequence and the fitted circular arc respectively to obtain a second maximum distance; compare the second maximum distance with a preset circular arc fitting error value; if the second maximum distance is less than the preset circular arc fitting error value, determine that the circular arc fitting is successful; store the fitted circular arc into the fitting matrix, set the value of m to m + 1, re-obtain the point sequence formed by the i-th point to the m-th point, and return to the step of performing circular arc fitting on the point sequence by using the least square method to obtain the fitted circular arc until the second maximum distance is greater than or equal to the preset circular arc fitting error value; if the second maximum distance is greater than or equal to the preset circular arc fitting error value, determine that the circular arc fitting fails, and execute the step of determining the fitting trajectory corresponding to the point sequence according to the first fitted straight line or the fitted circular arc.
[0209] Further, the trajectory acquisition module may include:
[0210] A first judgment unit, configured to judge whether there is a fitted circular arc stored in the fitting matrix;
[0211] A first result unit, configured to, if there is a fitted circular arc stored in the fitting matrix, determine the most recently stored fitted circular arc in the fitting matrix as the fitting trajectory corresponding to the i-th point to the (m - 1)-th point in the point sequence;
[0212] A second result unit, configured to, if there is no fitted circular arc stored in the fitting matrix, determine the most recently stored fitted straight line in the fitting matrix as the fitting trajectory corresponding to the i-th point to the (m - 1)-th point in the point sequence.
[0213] Further, the device may further include:
[0214] A third execution module, configured to, when the straight line fitting fails, judge whether the number of spatial discrete points in the point sequence is greater than three; if the number of spatial discrete points in the point sequence is greater than three, execute the step of performing circular arc fitting on the point sequence by using the least square method to obtain the fitted circular arc; if the number of spatial discrete points in the point sequence is equal to three, determine the connection line between the first point and the second point in the point sequence as the second fitted straight line; store the second fitted straight line into the fitting matrix, and execute the step of determining the fitting trajectory corresponding to the point sequence according to the first fitted straight line or the fitted circular arc.
[0215] It should be noted that the functions that can be realized by each module in the trajectory fitting device provided in this embodiment and the corresponding achieved technical effects can refer to the descriptions of the specific implementations in the various embodiments of the trajectory fitting method of the present invention. For the sake of simplicity of the specification, they are not described in detail here.
[0216] Embodiment 4
[0217] Based on the same inventive concept, with reference to Figure 2 the schematic diagram of the hardware structure, this embodiment provides a trajectory fitting device, which may include a processor and a memory. A trajectory fitting program is stored in the memory. When the trajectory fitting program is executed by the processor, all or part of the steps of each embodiment of the trajectory fitting method of the present invention are implemented.
[0218] Specifically, the trajectory fitting device refers to a terminal device or a system device capable of realizing communication connection. It may be a terminal device such as an embedded industrial control computer for controlling a machine tool, or a system device such as a control system for controlling a machine tool.
[0219] It can be understood that the trajectory fitting device may further include a communication bus, a user interface, and a network interface. Among them, the communication bus is used to realize the connection and communication between these components; the user interface is used to connect to the client and perform data communication with the client. The user interface may include an output unit, such as a display screen, and an input unit, such as a keyboard; the network interface is used to connect to the background control center and perform data communication with the background control center. The network interface may include an input / output interface, such as a standard wired interface, a wireless interface.
[0220] The memory is used to store various types of data, which may include, for example, instructions of any application program or method in the trajectory fitting device, as well as data related to the application program. The memory can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (abbreviated as SRAM), random access memory (abbreviated as RAM), electrically erasable programmable read-only memory (abbreviated as EEPROM), erasable programmable read-only memory (abbreviated as EPROM), programmable read-only memory (abbreviated as PROM), read-only memory (abbreviated as ROM), magnetic memory, flash memory, a magnetic disk or an optical disc. Optionally, the memory may also be a storage device independent of the processor.
[0221] The processor is used to call the trajectory fitting program stored in the memory and execute the trajectory fitting method as described above. The processor can be an Application Specific Integrated Circuit (ASIC), a Digital Signal Processor (DSP), a Digital Signal Processing Device (DSPD), a Programmable Logic Device (PLD), a Field Programmable Gate Array (FPGA), a controller, a microcontroller, a microprocessor, or other electronic components, and is used to execute all or part of the steps of each embodiment of the trajectory fitting method as described above.
[0222] Embodiment 5
[0223] Based on the same inventive concept, this embodiment provides a computer-readable storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a Read-Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Programmable Read-Only Memory (EPROM), an Electrically Erasable Programmable Read-Only Memory (EEPROM), a magnetic memory, a magnetic disk, an optical disc, a server, etc. A computer program is stored on the storage medium, and the computer program can be executed by one or more processors. When the computer program is executed by the processor, all or part of the steps of each embodiment of the trajectory fitting method of the present invention can be implemented.
[0224] It should be noted that the serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments. The above embodiments are only optional embodiments of the present invention and do not limit the patent scope of the present invention. Any equivalent structural or equivalent process transformation made by using the description and drawings of the present invention under the inventive concept of the present invention, or any direct or indirect application in other related technical fields, is included in the patent protection scope of the present invention.
Claims
1. A trajectory fitting method, characterized in that, the method includes: obtaining a point sequence composed of at least three spatially discrete points; performing linear fitting on the point sequence by using the least squares method according to a preset linear fitting mode to obtain a first fitted line; wherein, the preset linear fitting mode includes any one of the linear fitting methods corresponding to the point set corresponding to the starting point of the point sequence, the ending point of the point sequence, the midpoint of the line connecting the starting point and the ending point of the point sequence, or the midpoint of the line connecting any two points in the point sequence; when the linear fitting fails, performing circular arc fitting on the point sequence by using the least squares method to obtain a fitted circular arc, wherein the linear fitting fails means that the first fitted line does not meet the preset error condition; determining the fitting trajectory corresponding to the point sequence according to the first fitted line or the fitted circular arc.
2. The trajectory fitting method according to claim 1, characterized in that, the step of performing linear fitting on the point sequence by using the least squares method according to a preset linear fitting mode to obtain a first fitted line includes: when the preset linear fitting mode is the first linear fitting mode, performing linear fitting on the point sequence by using the least squares method according to the starting point of the point sequence to obtain a first line; when the preset linear fitting mode is the second linear fitting mode, performing linear fitting on the point sequence by using the least squares method according to the ending point of the point sequence to obtain a second line; when the preset linear fitting mode is the third linear fitting mode, performing linear fitting on the point sequence by using the least squares method according to the midpoint of the line connecting the starting point and the ending point of the point sequence to obtain a third line; when the preset linear fitting mode is the fourth linear fitting mode, recording the midpoint of the line connecting any two points in the point sequence to obtain a point set; for each recorded point in the point set, performing linear fitting on the point sequence by using the least squares method to obtain multiple candidate lines; respectively calculating the sum of the distances from each point in the point sequence to the multiple candidate lines, and determining the candidate line corresponding to the minimum sum of the distances as the fourth line; determining the first line, the second line, the third line or the fourth line as the first fitted line.
3. The trajectory fitting method according to claim 1, characterized in that, the step of obtaining a point sequence composed of at least three spatially discrete points includes: obtaining N discrete points in a three-dimensional space, where N is a positive integer and N≥3; extracting any at least three discrete points from the N discrete points to obtain a point sequence composed of the i-th point to the m-th point, where i and m are both positive integers, and i<m≤N; after the step of determining the fitting trajectory corresponding to the point sequence according to the first fitted line or the fitted circular arc, the method further includes: setting the value of i to m - 1 and the value of m to m + 1 to obtain a new point sequence composed of the i-th point to the m-th point, and repeating the step of performing linear fitting on the point sequence by using the least squares method according to the preset linear fitting mode to obtain the fitting trajectory corresponding to the new point sequence until all the N discrete points are traversed to obtain multiple fitting trajectories; Stitch the multiple fitted trajectories to obtain the final trajectory corresponding to the N discrete points.
4. The trajectory fitting method according to claim 3, wherein, after the step of performing linear fitting on the point sequence by using the least squares method according to the preset linear fitting mode to obtain the first fitted line, the method further includes: Calculating the distances between the points in the point sequence and the first fitted line respectively to obtain the maximum first distance; Comparing the maximum first distance with a preset linear fitting error value; If the maximum first distance is less than the preset linear fitting error value, it is determined that the linear fitting is successful; Storing the first fitted line into the fitting matrix, setting the value of m to m + 1, obtaining a new point sequence formed by the i-th point to the m-th point again, and returning to the step of performing linear fitting on the point sequence by using the least squares method according to the preset linear fitting mode to obtain the first fitted line until the maximum first distance is greater than or equal to the preset linear fitting error value; If the maximum first distance is greater than or equal to the preset linear fitting error value, it is determined that the linear fitting fails, and the step of performing circular arc fitting on the point sequence by using the least squares method to obtain the fitted circular arc is executed.
5. The trajectory fitting method according to claim 4, wherein, after the step of performing circular arc fitting on the point sequence by using the least squares method to obtain the fitted circular arc, the method further includes: Calculating the distances between the points in the point sequence and the fitted circular arc respectively to obtain the maximum second distance; Comparing the maximum second distance with a preset circular arc fitting error value; If the maximum second distance is less than the preset circular arc fitting error value, it is determined that the circular arc fitting is successful; Storing the fitted circular arc into the fitting matrix, setting the value of m to m + 1, obtaining a new point sequence formed by the i-th point to the m-th point again, and returning to the step of performing circular arc fitting on the point sequence by using the least squares method to obtain the fitted circular arc until the maximum second distance is greater than or equal to the preset circular arc fitting error value; If the maximum second distance is greater than or equal to the preset circular arc fitting error value, it is determined that the circular arc fitting fails, and the step of determining the fitted trajectory corresponding to the point sequence according to the first fitted line or the fitted circular arc is executed.
6. The trajectory fitting method according to claim 5, wherein, the step of determining the fitted trajectory corresponding to the point sequence according to the first fitted line or the fitted circular arc includes: Judging whether there is a fitted circular arc stored in the fitting matrix; If there is a fitted circular arc stored in the fitting matrix, determining the most recently stored fitted circular arc in the fitting matrix as the fitted trajectory corresponding to the i-th point to the m - 1-th point in the point sequence; If there is no fitted circular arc stored in the fitting matrix, determining the most recently stored fitted line in the fitting matrix as the fitted trajectory corresponding to the i-th point to the m - 1-th point in the point sequence.
7. The trajectory fitting method according to claim 6, wherein, Before the step of performing circular arc fitting on the point sequence by using the least squares method to obtain the fitted circular arc, the method further includes: When the straight line fitting fails, determine whether the number of spatially discrete points in the point sequence is greater than three; If the number of spatially discrete points in the point sequence is greater than three, perform the step of performing circular arc fitting on the point sequence by using the least squares method to obtain the fitted circular arc; If the number of spatially discrete points in the point sequence is equal to three, determine the line connecting the first point and the second point in the point sequence as the second fitted straight line; Store the second fitted straight line into the fitting matrix, and perform the step of determining the fitting trajectory corresponding to the point sequence according to the first fitted straight line or the fitted circular arc.
8. A trajectory fitting device Characterized in that The device includes: A point sequence acquisition module, configured to acquire a point sequence composed of at least three spatially discrete points; A straight line fitting module, configured to perform straight line fitting on the point sequence by using the least squares method according to a preset straight line fitting mode to obtain a first fitted straight line; wherein, the preset straight line fitting mode includes any one of the straight line fitting methods corresponding to the point set corresponding to the starting point of the point sequence, the ending point of the point sequence, the midpoint of the line connecting the starting point and the ending point of the point sequence, or the midpoint of the line connecting any two points in the point sequence; A circular arc fitting module, configured to perform circular arc fitting on the point sequence by using the least squares method when the straight line fitting fails to obtain a fitted circular arc, wherein the straight line fitting failure means that the first fitted straight line does not meet the preset error condition; A trajectory acquisition module, configured to determine the fitting trajectory corresponding to the point sequence according to the first fitted straight line or the fitted circular arc.
9. A trajectory fitting device Characterized in that The trajectory fitting device includes a processor and a memory, and a trajectory fitting program is stored on the memory. When the trajectory fitting program is executed by the processor, the trajectory fitting method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium Characterized in that A computer program is stored on the storage medium. When the computer program is executed by one or more processors, the trajectory fitting method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Numerical control machining track smoothing method based on B spline curve fitting
CN114545863A
Motion trajectory smooth transition method and device and related equipment
WO2018205276A1