Efficient Planning and Solving Algorithm of 
 S
 -Shape Acceleration and Deceleration


 
 
 S
 
 -shape acceleration and deceleration are the most widely used flexible acceleration and deceleration method in the current CNC system, but its velocity solution equation contains irrational terms, which create a more complicated solution process. When analyzing the solution process of the 
 
 S
 
 -shape acceleration and deceleration directly, using a traditional numerical solution method, the phenomenon of “solving the interval jump” arises, which is the main reason for low efficiency and poor stability of the solution. According to the 
 
 S
 
 -curve profile and solution, the concept of separating the curve profile recognition from the velocity solution was proposed, and a method of quickly identifying the interval of the solution location was introduced. Through the method mentioned above, the complete acceleration and deceleration curve parameters can be obtained through a one-time plan and a one-time solution, and the solution efficiency and stability are guaranteed; solving the Newton problem depends too much on the initial value of Newton velocity, which not only retains the speed advantage of the Newton method but also uses the downhill factor to ensure its convergence. Through the simulation comparison and analysis, the efficiency, stability, and universality of the method are verified.


Introduction
The ability of acceleration and deceleration is an important index in evaluating the performance of CNC systems, which directly affects the processing efficiency and quality of CNC equipment. High-speed and high-quality machining demands higher requirements for the acceleration and deceleration control abilities of CNC systems. The CNC equipment must be able to move from the current position point to the next position point quickly and accurately, while also ensuring the smooth operation of the equipment and avoiding impact, out of step, over the range, or oscillation.
The commonly used acceleration and deceleration algorithms in medium and low-speed equipment include trapezoids [1,2] and exponential acceleration and deceleration algorithms [3,4]. The two algorithms are simple in programming, good in real-time performance, and high in processing efficiency, but they all have the problems of abrupt change and discontinuity of the acceleration curve, which makes them not suitable for high-speed and high-accuracy machining [5].
In high-speed equipment, flexible acceleration and deceleration algorithms are often used, and their acceleration and acceleration function expressions are continuous, to reduce the impact on mechanical components [6]. S-shape acceleration and deceleration algorithm is the most widely used in flexible acc/dec algorithms at present. This method is based on the jerk constraint. The curves of displacement, velocity, and acceleration are composed of cubic, quadratic, and linear functions, respectively, and all of them are continuous without deviation [7,8].
The mathematical programming and solution of the S -shape acc/dec method have attracted considerable attention. The complete S-shaped acc/dec curve is composed of 7 segments, with many parameters. In most cases, the velocity solution equation is nonlinear, which makes its solution complex. Altintas [9] presented a detailed seven segment model of S-shape acc/dec, without elaborating its efficient solution. Barre [10] studied the influence of the acc/dec control in a high-speed machining process and analyzed the control algorithm of the seven-segment S-shape acc/dec. Shi [11] summarized eight possible cases of S-shape acc/dec in the planning, according to the characteristics of the curve segment. Nam [12] used the binary iteration to find the numerical solution, but the calculation amount was uncertain, and the solution efficiency was not ideal. Yang [13] adopted the Newton iteration, but the preconditions and convergence of Newton iteration were not clarified.
Many scholars simplified the S-shaped acc/dec curve in order to reduce the complexity of the solution. Wang and others [14,15] introduced a look-ahead control algorithm based on the S-shaped acc/dec curve with assuming that the velocity curve is symmetrical. In reference [16], the uniform acceleration and deceleration segments were removed, and the model was simplified to 5 segments. Although the above method reduced the complexity of the solution, it limited the dynamic performance of the machine tool. Xia [17] used the S-shape acc/dec based on the reference table to plan the velocity, which reduced the calculation time while limiting the flexibility of S-shape acc/dec.
Presently, the planning of NURBS curve interpolation velocity based on S-shape acc/dec has become a hot research topic, and the solution mainly adopts the matching displacement by changing the velocity step by step [18,19].The main idea of this method is to use the assumed key velocity value to calculate the corresponding displacement, match it with the actual displacement, and then determine the curve profile according to the matching situation. For small line segments, the calculation needs to be repeated more than three times, which reduces the efficiency of the solution.
In order to reduce the complexity in S-shaped acc/dec curve planning and solutions, some scholars introduced the artificial intelligence algorithms such as genetic algorithms [20] and particle swarm optimization algorithms [21]. Although the above artificial intelligence algorithm has strong robustness, it needs to calculate the fitness of each iteration. Compared with the traditional dichotomy and Newton iteration, it has a large amount of calculation and low competitiveness in real-time.
For S-shaped acc/dec curves, the more ideal solution method should have smaller calculation complexity and higher solution accuracy. However, there is no general perfect solution at present.
In this paper, the characteristics of the S-shaped acc/dec curve were analyzed. Focusing on the disadvantages of low efficiency and poor stability of traditional algorithms, a more concise, efficient, and stable general solution was proposed. In this method, the curve profile planning and velocity solution were completely separated. On the basis of proving the continuity of displacement's segmented function about velocity, the interval boundary points were used to analyze the interval of velocity, so as to complete the profile planning quickly. After obtaining the interval of the velocity solution, the modified Newton method was introduced, which can make full use of the Newton method to accelerate up to the convergence speed, and at the same time, the downhill factor guarantees the convergence of the iteration.

Profile Characteristics of S-Shape
Acceleration and Deceleration The name of the S-acceleration and deceleration curves are derived from the fact that the acceleration curve is approximately S-shaped. This type of S-acceleration and deceleration processes includes the S-acceleration process, deceleration process, and the uniform connection between acceleration and deceleration. Acceleration processes includes the accelerated acceleration segment, uniform acceleration segment, and decelerated acceleration; the deceleration process includes the accelerated deceleration segment, uniform deceleration segment, and decelerated deceleration segment. There are 7 sections in total, as shown in Figure 1. The corresponding mathematical expression is as follows: In the follow formula, t i ði = 1, 2,⋯,7Þ is the running time of each segment. Command T 1 = t 1 , T 2 = t 1 + t 2 , and so on, T 7 = t 1 + t 2 + t 3 + t 4 + t 5 + t 6 + t 7 ,.A is the maximum acceleration, J is the maximum jerk, V s is the initial velocity, Ve is the final velocity, and V max is the maximum velocity. According to the characteristics of the S-acceleration and deceleration curve, Acceleration zone Deceleration zone Displacement of the acceleration section: Displacement of the deceleration section: Total displacement: If the actual displacement is S > S T , then there is a uniform velocity segment and running time: Whether there is a uniform acceleration section or a uniform deceleration section in the process of acceleration and deceleration is decided by V s , V e , v, A, and J.

Direct Numerical Solution
3.1. Dichotomy. Dichotomy is the most common method in solving nonlinear equations. Its main process in solving S -shape acceleration and deceleration is shown in Figure 2.
Step 1. input the initial velocity V s , the final velocity V e , maximum acceleration A, maximum jump A, required moving displacement S, and maximum limiting velocity V max .
Step 3. call formulas (7)-(10) to calculate the time of each segment t i and put them into formulas (13)- (16) to calculate the displacement S T .
Step 4. if S T ≤ S, call formula (5) and obtain the running time of each segment and the overall curve profile. The calculation is finished.
If in step 4 S T > S, the binary algorithm will be executed in step 5 to step 8:

Wireless Communications and Mobile Computing
Step 5. take the initial interval ½V a , V b , where V a = max fV s, V e g andV b = V max and set the velocity accuracy V ε .
Step 6. determination of termination conditions: if ðV b − V a Þ ≤ V ε , the calculation will be stopped.

Newton Iteration
For nonlinear equation f ðvÞ = S T − S = 0, V 0 is assumed to be an approximate solution of V * ; f ðvÞ is expanded in the Taylor form at V 0 , and the following formula is obtained: is obtained as the first approximation of V * ; V k is assumed as the current point, andf ðvÞ can be expanded in the Taylor form at V k : Then, 3.2.2. Iteration Process. The first four steps are the same as the first four steps of dichotomy, so it will not be described here. Start with step 5: Step 5. V 0 is taken as the initial value, N is the maximum number of iterations, and Vε is taken as the accuracy requirements.

Start
Input  Wireless Communications and Mobile Computing Figure 3: Schematic diagram of interval jump in the solving process.

Start
Input

Wireless Communications and Mobile Computing
Step Step 7. if jV k+1 -V k j < V ε , the calculation will be stopped.
Step 8. if k = N, stop; otherwise, k = N + 1 and turn to step 6.

Phenomenon of Solving Interval Jump
For the numerical solution, whether dichotomy or the Newton method, the solution interval is selected according to the initial value of the velocity in the first step, and then the displacement expression of this interval will be calculated. The solution obtained is not the final velocity solution, and the solution interval will be selected again according to the velocity value, and the iterative calculation will be carried out repeatedly until the termination condition is met. The process will cause the velocity value to jump at different intervals, and the displacement expression needs to be selected repeatedly, which will affect the solution efficiency, as shown in the following figure: Figure 3 shows the case of V s < V e < V s + ðA 2 /JÞ < V e + ðA 2 /JÞ < V max . The blue dotted line represents the segment point of the interval. From formula (13) to formula (16), it can be seen that the expression of displacement velocity is different in different segments. Taking dichotomy as an example, assuming that the required solution V * is slightly less than V e + ðA 2 /JÞ, the solution obtained after the first iter-  14)) is applicable, and the next iteration is carried out (16) is applicable, and the third iteration is carried out V ′ ′′ = V ′ + V ′ ′/2 ∈ ½V s + ðA 2 /JÞ, V e + ðA 2 /JÞ. In this case, (14) applies again.
This kind of iterative solution jumps between intervals, which causes different displacement expressions to be called back and forth, which leads to the instability of the solution process and affects the solution efficiency. In order to solve this kind of jump problem, the analytic programming method is introduced; that is, the interval of the expected solution is estimated first, and then the solution is calculated.

Solution by Matching with Velocity
Step by Step The main idea of this method is to use the assumed key velocity value to calculate the corresponding displacement, match it with the actual displacement, and then determine the curve profile according to the corresponding situation. Take acceleration segment as example: Step 1. assuming that the velocity can reach the required maximum velocity, the maximum velocity is substituted into Interval 0 Interval 1 Interval 2 Interval 3 V s V s Figure 5: Case 1 with initial velocity less than the final velocity.

Serial number
Wireless Communications and Mobile Computing the displacement formula, and the calculated displacement is compared with the actual displacement. If the calculated displacement is smaller than the actual displacement, then there is a uniform velocity segment: Step 2. if the calculated displacement is larger than the actual displacement, assume that there is just a uniform acceleration segment and substitute the assumed velocity value into the displacement formula and compare the calculated displacement with the actual displacement. If the calculated displacement is smaller than the actual displacement, it means that there is a uniform acceleration segment, then use the displacement formula including the uniform acceleration segment to solve the actual velocity value.
Step 3. if the calculated displacement is larger than the actual displacement, it means that there is no uniform acceleration section. At this time, the displacement formula without uniform acceleration section is used to solve for the actual velocity value.
The specific flow of the algorithm is shown in Figure 4. The advantage of this method is that you can use the assumed velocity to plan first; then, you can solve for the actual velocity and avoid the jump in value ranges, increasing the stability of the solution, but there are also obvious disadvantages: the displacement is calculated and matched step by step with the assumed velocity. For the small line segment, the calculation needs to be repeated more than three times, which reduces the efficiency of the solution.

Interval Identification
To solve the problem of low efficiency of solution by matching with velocity, a new velocity planning method is proposed here.
From formula (5) to formula (10), it can be seen that when the initial velocity, final velocity, and maximum acceleration are given, the value of V directly affects the size and existence of each segment time t i , and the actual s determines whether the actual velocity can reach the maximum allowable value.
When V s < V e , V e ≤ V s + ðA 2 /JÞ, and V e + ðA 2 /JÞ < V max , because of max fV s , V e g ≤ V ≤ V max , interval 0 in Figure 5 is meaningless, and V may exist in the intervals 1-3.
The velocity value interval is divided into six sections and interval 0-5 by five key numerical points. The time expression (8) and formula (10) are suitable in interval 1, and the corresponding displacement expression is formula (16); the time expressions (7) and (10) are suitable in interval 2, and the corresponding displacement expression is formula (14); the time expressions (7) and (9) are suitable in interval 3, and the corresponding displacement expression is formula (15). Then, the piecewise function is obtained: According to the definition of the function continuity, let y = sðvÞ exist in a certain field of point v 0 ; when v → v 0 , if the limit of the function sðvÞ exists and is equal to its function value at point v 0 ,that is lim In the initial conditions, the initial velocity, the final velocity, the maximum acceleration, and the maximum jerk are given. The end values of three intervals are substituted into f i ðvÞ = S Ti ðvÞ − S, respectively. F is and F ie are function values of the endpoints of the i-th interval.
From the properties of the continuity function, F 1e = F 2s , F 2e = F 3s .
In the next step, the function values of f i ðvÞ = S Ti ðvÞ − S at the end points of each group of intervals are multiplied by each other to determine whether the product result is less than zero. There are two situations for the result: (1) If F is * F ie > 0, the S T and S curves do not intersect in this interval, and there is no solution in this interval.
If there is no solution in the three intervals, the velocity is taken as V max, which indicates that the system has a uniform segment, the time is t 4 , and the curve is composed of seven segments. The t i can be obtained by substituting the velocity value into the solutions of formulas (4) and (5) (2) If F is * F ie ≤ 0, it means that the S T curve and S line intersect in this interval, and the equation has a solution, which is the actual value of velocity V that the system can achieve. At this time, substituting V into equation (7)- (10) can calculate the running time of each segment Table 1 is the summary of the curve profile planning of case 1. The first three lines show the three cases of F is * F ie ≤ 0 when i equals 1,2,3, respectively. The fourth line shows that i = 1, 2, 3 cannot meet the situation of F is * F ie ≤ 0.
Formulas (14)- (16) can be solved by the dichotomy and Newton method listed above to get the velocity value. Then, the value is brought into the corresponding time calculation formula to get the running time of each segments.
As shown in Table 2,there are 12 possibilities in the comparison of five key values of the initial velocity V s , the final velocity V s , V s + ðA 2 /JÞ, V e + ðA 2 /JÞ, and V max .
Next, case 2 and case 3 in Table 2 will be discussed, and the interval distribution is shown in Figure 7.
The time expression (8) and equation (10) in interval 1 are suitable, and the displacement expression is the same as equation (17).
The time expression (7) and equation (10) in interval 2 are suitable, and the displacement expression is the same as equation (18). Case 3. Only interval 1 makes sense. The time expression (8) and equation (10) in interval 1 are suitable, and the displacement expression is the same as equation (17). Case 4 and case 5 express the situation when V e > V s + ðA 2 /JÞ, as shown in Figure 8. The time expression (7) formula (10) in interval 1 is applicable, and the displacement expression is the same as formula (14).
Time expression (7) and equation (9) in interval 2 are applicable, and displacement expression is the same as equation (13). The time expression (7) and formula (10) in interval 1 are suitable, and the displacement expression is the same as formula (15).
(1) When Vs = Ve, there are only two cases, case 6 and 7, as shown in Figure 9 Case 6. Interval 1 and 2 make sense. The time expression (8) and equation (10) in interval 1 are suitable, and the displacement expression is the same as equation (17).
The time expression (7) and equation (9) in interval 2 are suitable, and the displacement expression is the same as equation (24).
(2) When Vs > Ve, the possible value range of velocity is from case 8 to case 12. The actual solution process is the same as that of Vs < Ve, and only 1 and 2 need to be interchanged. In consideration of space, it will not be expanded here (3) There are four other possibilities, which are not listed in the bid, as shown in Table 3 (8) and equation (10) in interval 1 are suitable, and the displacement expression is the same as equation (17).
The so-called S-shape means that the shape of acceleration is similar to the S-shape, case 13-case listed in Table 3. There is only acceleration section or deceleration section, and acceleration is similar to half circle. According to the definition of the S-shaped acceleration and deceleration curve, these four cases do not meet the definition, but these four cases do exist in small displacement, especially in the speed sensitive area, so they are listed here. The calculation method is the same as above and will not be described here.

Comparison of Solution Methods
7.1. Match with Velocity VS Interval Identification. The first step when using the velocity method is to assume that the curve has seven complete segments, and that the time and velocity values are substituted into the formula to calculate the displacement. If the calculated displacement is less than the actual displacement, the one with the larger value in V s + A 2 /J and V e + A 2 /J will be substituted into the equation again to calculate the displacement, and the calculated displacement and the actual displacement will be compared again. If the calculated displacement is greater than or equal to the actual displacement, then the actual velocity and running time can be obtained by solving the equation.
If the calculated displacement is smaller than the actual displacement, it is necessary to replace the smaller value of V s + A 2 /J and V e + A 2 /J into the displacement equation again, calculate and compare the displacement for the third time, and then plan out the profile of the curve. Finally, the actual velocity can be obtained by solving the equation.
The specific steps of the interval identification method are as follows: ① input the initial value, compare 5 key speed values, and find the corresponding case No.; ② in the corresponding case No., substitute the value to judge F is * F ie ≤ 0; ③ solve the equation in the interval of F is * F ie ≤ 0 and get the velocity; and ④ replace the speed V with the time calculation formula and get the whole curve profile. Figure 10 shows the comparison of the processes of the two methods. In summation, if the curve has 7 or 6 segments, the calculation steps and calculation amounts of the two Interval 0 Interval 1 Interval 2 Interval 3   Interval 0 Interval 1 Interval 2 Interval 3   Interval 0 Interval 1 Interval 2 Interval 3   Case 2   0 Case 3 Wireless Communications and Mobile Computing methods are basically the same. If the curve has 4 or 5 segments, the calculation steps and calculation amounts of the interval identification method are less and therefore, the efficiency is higher.

Direct Numerical Solution vs Interval Identification.
In order to verify the efficiency of the solution, various methods and algorithms are programmed with matlab2018a, and the displacement is taken as a variable between 0.0001 m and 0.018 m, and the interval between the value points is 0 and 1 mm. Computer configuration: processor Intel (R) core (TM) i5-4200u memory 8 g. The solution time of each algorithm under different displacement conditions is calculated, and the solution efficiency of each method is compared. The number of Newton iteration and dichotomy iteration termination is 10000. The specific parameter settings are shown in Table 4, and the solution efficiency is shown in Figure 11.
It can be seen from Figure 11 that the abscissa of either direct Newton iteration or interval identification+Newton iteration does not start from zero; that is, the red dotted area in the figure which indicates that Newton iteration does not return the velocity solution and directly jumps out of the iteration cycle after reaching the limit of iteration rounds. As mentioned in the previous paper, the convergence of the Newton iteration needs to be further verified. When the displacement value is about 1-3 mm, the number of Newton iterations is also significantly higher than the number after it is stable. When the displacement is more than 4 mm, all algorithms tend to be more stable as displacement increases.
In order to see the solution efficiency of the four methods more clearly and intuitively, the abscissa in Figure 11 is intercepted through 7-12 mm part, resulting in Figure 12.
Regarding solving efficiency, the efficiency of the interval identification method is obviously better than that of the direct iterative method when the solving process of various algorithms is stable. The efficiency of interval identification plus Newton iteration is the highest, and then the efficiency of direct Newton iteration is about one third of that of interval identification plus Newton iteration. The efficiency of dichotomy is obviously lower than that of Newton iteration. The efficiency of direct dichotomy is about one seventh of interval identification plus the Newton iteration. From the point of view of solving stability, the interval identification method is also better than the direct

11
Wireless Communications and Mobile Computing iteration method. As mentioned earlier in the paper, the interval identification avoids the phenomenon of iteration jumping back and forth in different value intervals, thus improving the stability.
To sum up, the interval identification+Newton iteration method is the best both in solving efficiency and solving stability. Figure 11 is the abscissa which is truncated at 0-5 mm and enlarged locally to get Figure 13. It can be seen that the efficiency of all solutions fluctuates within a certain boundary, and the Newton iteration is the obvious. In the figure, the red dot dash appears near two key points, which are S T1 and S T2 in formula (17), corresponding to the interval boundary points in the interval identification method. This shows that the expression change caused by the change of displacement length has an obvious effect on the iteration efficiency. The smaller the displacement, the more timeconsuming the solution.

Interval Identification plus Modified Newton Iteration
In order to prevent the divergence of Newton iteration, a requirement is attached to the iteration process to keep its monotonicity.
In order to meet this requirement, Newton iteration is modified.
Where λð0 < λ ≤ 1Þ is the downhill factor, and formula (18) is obtained after the transformation of the above formula: In the iteration, it starts from λ = 1 and reduces by half until it meets the requirements (16).
After the modified Newton iteration is introduced, the iteration parameters and initial conditions are set according to Table 4. Under the same conditions, the efficiency curve Figure 14 is obtained.
Only Newton iteration can be seen in Figure 14, because the iteration diverges until the number of iterations jumps out of the cycle. The record time of 0.01 seconds in the figure is the time taken to jump out of the cycle. Figure 13 is partially enlarged to obtain Figure 15.
It can be seen from Figure 15 that, when the displacement is large, the solution efficiency of interval identification plus modified Newton method is very close to that of interval identification plus Newton iteration, which retains the characteristics of fast convergence of Newton iteration; when the displacement is small, the downhill factor ensures the convergence of iteration.

Conclusion
(1) When analyzing the process of solving S-shape acceleration and deceleration directly by the traditional numerical solution method, the phenomenon of "solving interval jump" was concerned, which is a main reason for the low efficiency and poor stability of the solution (2) According to the S-curve profile and solution, the concept of separating the curve profile recognition from the velocity solution was introduced, and a plan of quickly identifying the interval of the solution location was put forth. With this method, the com-plete acceleration and deceleration curve parameters can be obtained through one-time planning and one-time solutions, and the solution efficiency and stability are certain (3) The modified Newton method was introduced to solve the problem that the Newton iteration depends too much on the initial value of velocity, which not only retains the speed advantage of the Newton method but also uses the downhill factor to ensure its convergence (4) Finally, through the simulation comparison and analysis, the efficiency and stability of the interval identification and modified Newton method were verified

Data Availability
The data used to support the findings of this study are available from the corresponding author upon request.

Conflicts of Interest
The author(s) declare(s) that they have no conflicts of interest.