## 4 Improved Algorithms
### Improved Hybrid Algorithm of the APF and RRT
#### 4.4.2 Improved Hybrid Algorithm Implementation  
According to the principle of the improved APF and RRT hybrid algorithm, the specific implementation steps are described as follows. Step 1: Initialize the parameters, and define the obstacle environment, starting point, target point, step length, and target sampling rate. Step 2: Determine the distance between the current node and the obstacle. If the distance between the current node and the nearest obstacle is greater than twice the step length, execute Step 3. If the distance between the current node and the nearest obstacle is less than twice the step length, execute Step 4. Step 3: Use the I-APF method to search and move forward under the combined force of the target and obstacle. (1) Calculate the gravitational and repulsive forces. (2) Determine whether the gravitational and repulsive forces experienced by the current node are equal and opposite. If they are equal, the object falls into a local minimum, the heuristic method based on the number of adjacent obstacles is used to escape from the local minimum so that the algorithm escapes from the local minimum, and the end effector of the robotic arm is guided to continue to move. If they are not equal, proceed to Step (3). (3) If the distance between the current node and the target point is less than the step length or if the distance between the nearest node and the nearest obstacle is less than twice the step length, then the I-APF method search process is ended, the path node obtained by the APF method is added to the Pathpath, and the Pathpath and the latest node q(new) are returned. Otherwise, jump to Step (1). Step 4: If the distance between the current node and the nearest obstacle is less than twice the step length, the I-RRT algorithm is used to search for the path. (1) Initialize the tree, set the initial node and target point, and define the step size, target sampling rate, and segmentation rate. (2) Start the iteration and sample the state space. When the random probability is less than the target sampling rate, the sampling point selects the target point. If it is greater than the target sampling rate, random sampling points in the space are selected. (3) Select the nearest neighbor node according to the triangle nearest neighbor node selection method and calculate the distance dist\({}_{1}\) between this node and the nearest obstacle. (4) Determine whether the distance dist\({}_{1}\) is greater than the step length. If so, the step length \(F_{1}(n)\) is used for expansion. If not, generate a virtual new node according to the step length \(F_{1}(n)\) and calculate the distance dist\({}_{2}\) between the virtual new node and the nearest obstacle. (5) If dist\({}_{2}<\) dist\({}_{1}\), the new node has a tendency to move towards obstacles. Remove the virtual new node and use step \(F_{2}(n)\) to expand. If dist\({}_{2}>\) dist\({}_{1}\), the new node has a tendency to move away from obstacles; remove the virtual new node and use the step size \(F_{3}(n)\) to expand. (6) Determine whether the new node collides with obstacles; if there is a collision, skip to Step (2). Re-sample random points; if there is no collision, add the new node to the tree and assign the parent node of the new node to the nearest node (q\({}_{\text{nearest}}\)). (7) When the distance between the new node and the target point is less than the step length or the distance between the nearest node and the nearest obstacle is greater than twice the step length, end the iterative process; otherwise, skip to Step (2). (8) Use the collision detection method of the path to perform the process of removing redundant nodes on the generated path to obtain the processed path. (9) Add the processed path node to the Pathpath and return the Pathpath and the latest node q(new). Step 5: Determine whether the distance between the new node and the target point is less than the step length.