## 2 Improved APF Algorithm
### Resolving Localized Oscillations Caused by U-Shaped Obstacles
If the distance of _dist_ is less than the distance of a grid, then \(p2\) is retained for the cycle of step 2, and vice versa, \(p2\) is removed, and p4 is selected at this time as the intermediate point, and the algorithm cycles through the judgments until the last point is the target point. The necessary points of the paths calculated by Formulas (5) and (6) are taken as the temporary target points of the APF algorithm to provide attraction. Use the final target point and the temporary target point, respectively, to exert gravitational force on the current point. Compare the two ways and calculate the combined potential energy. The comparison graph and the combined potential energy graph are shown in Figure 7.  
It can be observed that the paths planned by the traditional APF algorithm show a greater variation in the resultant force and a poorer match with the global path than the APF using temporary target points. Due to the existence of obstacles near the target point, there is a large difference between the combined potential energy and the zero potential energy point. This will lead to not accurately reaching the target point, so in this paper, the potential energy function of the APF is improved. Based on Equation (2), the improved potential energy function is shown in Equation (7). \[ \begin{split} U_{rep}=\begin{cases}U_{rep}=\frac{1}{2}\times k_{ rep}\times\left(\frac{1}{p(q4_{obs})}-\frac{1}{p0}\right)^{2}\times\left(1-\exp(- \rho\Big{(}q,q_{goal}\Big{)}^{2})\right)\times\rho\Big{(}q,q_{goal}\Big{)}^{ 2}&\rho(q,q_{obs})\leq\rho_{0}\\ 0&\rho(q,q_{obs})>\rho_{0}\end{cases}\\ \end{split}  \tag{7}\]  
Split the original repulsive force \(F_{rep}\) into two repulsive forces, \(F_{rep1}\) and \(F_{rep2}\). \(F_{rep1}\) is still pointing from the obstacle to the current point, and \(F_{rep2}\) is pointing from the current point to the target point. Solve for the negative gradient for \(\rho(q,q_{obs})\) and \(\rho\Big{(}q,q_{goal}\Big{)}\), respectively, as shown in Equations (8)-(10). Figure 7: Path comparison and combined potential energy diagrams. They are: (**a**) MATLAB simulation diagram; and (**b**) Combined potential energy maps using the temporary target point APF. \[F_{rep1}=k_{rep}\times\left(\frac{1}{\rho(q,q_{obs})}-\frac{1}{\rho_{0}}\right)^{2 }\times\left(1-\exp\left(-\rho\left(q,q_{goal}\right)^{2}\right)\right)\times \frac{\rho\left(q,q_{goal}\right)^{2}}{\rho\left(q,q_{obs}\right)^{2}} \tag{8}\]  
\[F_{rep2}=k_{rep}\times\left(\frac{1}{\rho(q,q_{obs})}-\frac{1}{\rho_{0}} \right)^{2}\times\left(2\times\rho\left(q,q_{goal}\right)\times\exp\left(- \rho\left(q,q_{goal}\right)^{2}\right)\times\rho\left(q,q_{goal}\right)^{2}+N\right) \tag{9}\]  
\[N=2\times\rho\left(q,q_{goal}\right)\times\left(1-\exp\left(-\rho\left(q,q_{ goal}\right)^{2}\right)\right) \tag{10}\]  
A distance-dependent target distance factor is introduced into the potential energy function \(\rho\left(q,q_{goal}\right)^{2}\), After performing the square operation on the distance result, it is proportionally magnified to emphasize the influence of distance change on the potential energy value. At the same time in the function introduced Gaussian function, the repulsive potential energy will gradually equal the original potential energy, and the change of the total potential energy field will be smoother. If the current position is near the final arrival point, the value of the Gaussian function tends to 0, which ensures that the final point is the lowest point of the total potential energy of the entire field. The combined potential energy of the APF with the modified repulsion function is compared with that of the APF, and the comparison plot is shown in Figure 8, and the path comparison with the lowest combined potential energy is shown in Figure 9.  
Figure 8: Utotal comparison chart for both algorithms. Figure 9: Path and Utotal comparison chart. They are: (**a**) MATLAB simulation diagram; and (**b**) Combined potential energy maps using the temporary target point APF.