# Comparison Study of the PSO and SBPSO on Universal Robot Trajectory Planning
## 2 Materials and Methods
### Particle Swarm Optimization (PSO)  
The PSO algorithm can be used to solve problems of trajectory planning using a state function value and an Interactive Optimization by Particle Swarms (IPSO) [24; 25]. The position at time (t) is updated through \(\mathrm{x}_{\mathrm{i}}(\mathrm{t})\) and in the future tense (t + 1) will be updated to \(\mathrm{x}_{\mathrm{i}}(\mathrm{t}+1)\) as in Equation (7)  
\[\mathrm{x}_{\mathrm{i}}(\mathrm{t}+1)=\mathrm{x}_{\mathrm{i}}(\mathrm{t})+ \mathrm{v}_{\mathrm{i}}(\mathrm{t}+1) \tag{7}\]  
The velocity of particles is \(\mathrm{v}_{\mathrm{i}}(\mathrm{t})\)[12]. Each particle will have a cognitive component, which will be a relationship of the distance between the optimal solution and the social component, which is the collective's understanding of the particle's existence. For this problem, the PSO was applied globally (Global best PSO), with Equation (8) updating the particle velocity:\[\mathrm{v_{ij}(t+1)=v_{ij}(t)+C_{1}r_{1}(t)\Big{[}y_{ij}(t)-x_{ij}(t)\Big{]}+C_{2}r_{ 2}(t)\big{[}\hat{y_{ij}(t)-x_{ij}(t)\big{]}} \tag{8}\]  
\(\mathrm{v_{ij}(t)}\) is the particle's velocity in a dimension at time t. The acceleration parameters are \(C_{1}\), and \(C_{2}\). The \(y_{ij}\) and \(\hat{y_{ij}}\) which is the best position from the start [12], provide the information of the best particle. A velocity is assigned to each particle in the PSO algorithm. Particles move around the search space at different speeds, which are constantly changed based on their previous actions. Finally, during the search process, particles have a tendency to go via the best research area [12]. The trajectories of the joints of the handler can be optimized using a strategy which divides the robot into several aptitude functions to perform the optimal fit with modified PSO with crossover operator [26]. The simulation results are presented for manipulator trajectory planning of the UR5 using redundant kinematics mounted on a floating space. Several simulations of the PSO algorithm were carried out with capability of changing the number of generations and particles. The best result of the algorithm was for 30 particles and for 2000 iterations that had the best values for the APF, and there was a convergence between the average of all particles and the best particle. For the PSO algorithm, the following were used element values:  
Quantity of particles = 30 particles  
Cognitive and social parameters (learning rates -\(C_{1}\) and \(C_{2}\)) = 2  
Iterations = 2000  
Initial population generation = [\(-\)1, 1];  
Inertia factor (w) = 0.5  
The initial steps of traditional PSO algorithm represent in Algorithm 1. ```
Initialization:
01: initialize the particle cloud
02: repeat Loops 1:
03: for i = 1 to m
04: if (\(\mathrm{v_{ij}}\)) \(<\)/(\(\mathrm{p_{i}}\)) then \(\mathrm{p_{i}=x_{i}}\)
05: if (\(\mathrm{v_{i}}\)) \(<\)/(\(\mathrm{g}\)) then \(\mathrm{g=x_{i}}\)
06: end if
07: end if
08: loop 2:
08: for j = 1 to n
09: \(\mathrm{r_{1}=rand()}\), \(\mathrm{r_{2}=rand()}\)
10: \(\mathrm{v_{ij}=wv_{ij}+c_{1}r_{1}(\mathrm{p_{i}-x_{ij}})+c_{2}r_{2}(\mathrm{ g_{i}-x_{ij}})}\)
11: end to
12: \(\mathrm{x_{i}=x_{i}+v_{i}}\)
13: end to
14: until you meet the stop criteria
```  
**Algorithm 1**The PSO algorithm is presented below  
The PSO algorithm's stopping criterion is the algorithm's generations number. In metaheuristic algorithms, elements representing solutions identified in a particular iteration for a given search space are added to the set E. Additionally, \(\mathrm{e_{ij}}\) is an element that represents a solution \(i\) in iteration \(j\), belonging to set E. The element \(\mathrm{e^{*}_{ij}\ eE}\) represents the fitness value of solution \(i\) which is the best value discovered in iteration \(j\). A search space's probable solutions are denoted by the letter S. So, E is a subset of S. Otherwise, this solution is considered an occasional solution given by Equation (9):  
\[\mathrm{CHANCE=S-E} \tag{9}\]  
\[\mathrm{Chance_{ij}}\]  
is a serendipitous element.