## 5 Improve Obstacle Avoidance Path Planning for RRT
### Improvements to RRT  
The APF algorithm is a good obstacle avoidance algorithm widely used in obstacle avoidance paths. By assuming that there are attractive and repulsive forces between the target point and obstacles in the workspace, the moving object is subjected to the combined force of the two and continuously moves towards the target point. This algorithm guides the moving object to move towards the target point while avoiding collision with obstacles during the movement. The movement direction of the APF path planning algorithm is shown in Figure 9.  
The RRT algorithm and the APF algorithm were combined to enhance the search towards the picking point. Integrating the gravitational field of the APF algorithm into the RRT algorithm, the target point had a gravitational field guiding the nodes of the random tree to deviate towards the target point, which reduced unnecessary redundant nodes and shortened computation time, thus accelerating the convergence speed. The specific algorithm process was as follows:  
1. Set \(q_{start}\) as the starting point of exploration, \(q_{goal}\) as the final destination point, where both \(q_{start}\) and \(q_{goal}\) are points in the workspace \(C_{free}\);
2. Set \(q_{start}\) as the starting point  
Set \(q_{start}\) as the root node of random tree \(L\);
3. Sampling points \(q_{rand}\) are obtained by random sampling in the working interval \(C_{free}\) for each iteration;
4. Search for the node closest to \(q_{rand}\) in the random tree \(L\), denote it as \(q_{near}\);
5. Starting from \(q_{near}\), generate a new node \(p_{1}\) with a specific step size in the direction from \(q_{near}\) to \(q_{rand}\), and generate a new node \(p_{2}\) under the gravitational field of the target point \(q_{goal}\) with a certain step size from \(q_{near}\), where both new nodes \(p_{1}\) and \(p_{2}\) are in the working space \(C_{free}\);
6. Generate a new node \(q_{new}\) in the direction of the diagonals formed by the parallelogram from \(q_{near}\) to \(p_{1}\) and from \(q_{rand}\) to \(p_{2}\); then, denote the path from node \(q_{rand}\) to the new node \(q_{new}\) as \(Ei\);
7. Judge whether \(Ei\) meets the obstacle avoidance conditions within the working area \(C_{free}\). If it does, set \(q_{new}\) as the new \(q_{rand}\) node; if not, return to step (3) to re-find a randomly sampled point \(q_{rand}\);
8. If the obstacle avoidance conditions are met, repeat steps (3) to step (7) in the next iteration cycle until node \(q_{goal}\) is reached, and \(q_{start}\) to \(q_{goal}\) paths are output. The improved RRT algorithm flowchart is shown in Figure 10, and the pseudocode can be found in Supplementary S2. The comparison chart of RRT before and after improvement is shown in Figure 11.  
Figure 10: Improved RRT algorithm flowchart.  
In hybrid algorithms, the guiding role of artificial potential fields is mainly reflected in three key aspects:  
1. In the node sampling stage, although the basic characteristics of random sampling are still maintained, the continuous guidance of the gravitational field makes the sampling points naturally biased towards the direction of the target point, significantly improving the target directionality.
2. During the tree expansion process, whenever a new node is generated, APF calculates the attraction and repulsion in real-time based on the current environment. Attraction pulls the node towards the target point, while repulsion pushes the node away from obstacles. The balance of these forces allows the new node to automatically avoid obstacles while maintaining the expansion direction.
3. At the level of overall path optimization, the continuous effect of APF enables the tree structure grown to naturally form smooth detours in areas with dense obstacles, while maintaining the characteristic of approaching the target in a straight line in open areas. This not only avoids the redundant exploration that may occur in traditional RRT but also makes the final path both safe and optimal through dynamic adjustment of the force field.