# Trajectory Planning of Robotic Arm Based on Particle Swarm Optimization Algorithm
## 3 Improved Particle Swarm Optimization Algorithm
### Algorithm to Improve  
The PSO algorithm has achieved good results in many different scenarios and practical applications. However, the problem of easily falling into local optima has not been well improved. To address this issue, we introduce a local disturbance term and attempt to use adaptive weights to improve the algorithm. The random disturbance term allows particles to jump out of the current region when they fall into the optimum in the early stage, avoiding the situation of falling into local optima. The adaptive weight coefficient adaptively adjusts the weights by calculating the current particle state. The RTPPSO algorithm modifies the PSO algorithm as follows.  
To prevent particles from getting trapped in local optimal solutions, a random perturbation term is introduced. This technique aids particles in steering clear of local optima and effectively delving into potential global optima. Specifically, the updated particle position is subject to a random perturbation term, which is a vector crafted in alignment with a designated random distribution. This random perturbation term could follow a normal distribution, a uniform distribution, or another pertinent distribution. Consequently, each particle incorporates an element of randomness, thereby enhancing the diversity of the search. Thus, the particle velocity update formula is as follows:  
\[\begin{array}{l}V(t+1)=w\times V(t)+c_{1}\times r_{1}\times(pb-X(t))\\ +c_{2}\times r_{2}\times(gb-X(t))+\alpha\times D\end{array} \tag{14}\]  
where \(\alpha\) is the random disturbance coefficient, which controls the intensity of introduced randomness, and \(D\) is a random number between \(-1\) and \(1\).  
Referring to Equation (16), it generates the updating principle of the inertia weight. In the equation, \(w_{\text{min}}\) and \(w_{\text{max}}\) represent the minimum and maximum values of the custom weights, respectively. \(f(t)\) represents the fitness value of the current particle, while \(f_{\text{min}}\) and \(f_{avg}\) denote the minimum fitness value and average fitness value of the current particle swarm, respectively. The fitness value is calculated by the subsequent objective function value. These values are normalized; thus, they vary between 0 and 1.  
\[w(t)=w_{\text{max}}-(w_{\text{max}}-w_{\text{min}})\times(f(t)-f_{\text{min}}) /\big{(}f_{avg}-f_{\text{min}}\big{)} \tag{15}\]  
Moreover, Equation (14) can be updated and results in Equation (17):  
\[\begin{array}{l}V(t+1)=w(t)\times V(t)+c_{1}\times r_{1}\times(pb-X(t))\\ +c_{2}\times r_{2}\times(gb-X(t))+\alpha\times D\end{array} \tag{16}\]Here, we also introduce adaptive weight changes for the parameters \(c_{1}\) and \(c_{2}\) in the particle velocity calculation formula, as shown in Equation (18). In this equation, \(c_{1}(t)\) and \(c_{2}(t)\) represent newly designed adaptive parameters; \(\alpha\) and \(\beta\) are constants ranging from 0 to 1.  
\[\left\{\begin{array}{l}c_{1}(t)=\alpha((f(t)-f_{\min})/\big{(}f_{\text{avg}}-( f_{\min})))+\beta\\ c_{2}(t)=\alpha(1-(f(t)-f_{\min})/(f_{\text{avg}}-(f_{\min})))+\beta\end{array}\right. \tag{18}\]  
The RTPPSO algorithm has undergone significant changes compared to the traditional PSO algorithm in the formula for updating particle velocities, and its flow chart is shown in Figure 4. All parameters have shifted from their original fixed weights to adaptive weights that can adjust with the changing adaptability of particles. After a series of transformations, the formula for particle velocities now appears as shown in Equation (19).  
\[\begin{array}{l}V(t+1)=w(t)\times V(t)+c_{1}(t)\times r_{1}\times(pb-X(t)) \\ +c_{2}(t)\times r_{2}\times(gb-X(t))+\alpha\times D\end{array} \tag{19}\]