# Optimization Algorithm for 3D Smooth Path of Robotic Arm in Dynamic Obstacle Environments
## 3 Method Description
### Dynamic Path Planning Module
As shown in Figure 8, if \(Q_{\text{near}}\) is located within a protective zone containing multiple obstacles, the repulsive force is strong, making it difficult for the search tree to be guided in a direction that generates an effective path. Therefore, in this scenario, a larger RRT factor \(\alpha\) is needed to make the search tree more likely to leave this area and develop in a more efficient direction, weakening the effect of APF. On the other hand, in areas with fewer obstacles, the APF factor \(\beta\) is larger, so APF can cause the search tree to converge quickly, reducing the randomness of RRT. Therefore, considering both scenarios, the dynamic adjustment process of weights in local path replanning has greater convergence possibilities and shorter path lengths. To determine the weight factors \(\alpha\) and \(\beta\), a search space \(S\) is defined at \(Q_{\text{near}}\). The RRT weight factor \(\alpha\) is determined based on the proportion of the intersection between obstacles and the search space, as shown in Equation (10). \[\alpha\triangleq\frac{S\cap V_{\text{obs}}}{S} \tag{10}\]  
where \(V_{\text{obs}}\) represents the volume of the obstacles. From the above equation, it can be seen that the larger the intersection between the search space and the obstacles surrounding \(Q_{\text{near}}\), the larger the RRT weight factor \(\alpha\) for the robot's obstacle avoidance path replanning. On the other hand, if the intersection between obstacles and the search space is small, APF will more effectively guide the search direction for more efficient obstacle avoidance. The APF weight factor \(\beta\) is defined as the complement of the RRT factor \(\alpha\). Since obstacles are defined as point clouds, the above equation can also be expressed as Equation (11). \[ \begin{cases}\alpha=\frac{n!^{3}}{3\pi R^{3}},\\ \beta=1-\alpha\end{cases}  \tag{11}\]  
where \(n\) is the number of points in the obstacle point cloud within the search space, and \(l\) is the size of a voxel in the point cloud. In the equation, the denominator of \(\alpha\) is the volume of a sphere with radius \(R\), which represents the search space \(S\) mentioned above. The numerator of \(\alpha\) is the product of the number of points \(n\) and the volume of a single point \(l^{3}\) (considered as a voxel). Due to the sufficiently high density of the original point cloud, the numerator of \(\alpha\) represents the volume of the intersection between the obstacles and the search space. Figure 8: Dynamic adjustment of weight factors for node expansion. In summary, the final path is composed of an initially planned static path (offline) and a locally planned path (online). When avoiding dynamic obstacles, the robotic arm must return to the initial static path, and the switching strategy determines whether to follow the new path or the initial path. The distance from the end effector of the robotic arm to the obstacles determines which path the robotic arm will take, as shown in Equation (12) below. Here, Path\({}_{\text{new}}\) and Path\({}_{\text{init}}\) represent the dynamically decided path and the static initial path, respectively. \[ \begin{cases}\text{Path}_{\text{new}},&\|\vec{d}(P_{\text{obs}},P_{\text{tcp}} )\|<r,\\ \text{Path}_{\text{init}},&\|\vec{d}(P_{\text{obs}},P_{\text{tcp}})\|\geq r. \end{cases}  \tag{12}\]  
where \(P_{\text{tcp}}\) represents the position of the end effector, and \(r\) is the radius of the protective zone. If the distance \(\|\vec{d}(P_{\text{obs}},P_{\text{tcp}})\|\) from the end effector to the obstacles is less than the radius of the protective zone (\(r\)), a new local path is planned, and the robotic arm follows this new path to avoid both static and dynamic obstacles. If the distance \(\|\vec{d}(P_{\text{obs}},P_{\text{tcp}})\|\) is greater than the radius (\(r\)), the robotic arm follows the initial static path to avoid static obstacles.