# Trajectory Planning of Robotic Arm Based on Particle Swarm Optimization Algorithm
## 3 Improved Particle Swarm Optimization Algorithm
### Model Implementation  
During the actual operation process, the robotic arm transitions from a stationary state to movement and then to a final stop, requiring acceleration, constant speed, and  
Figure 4: RTPPSO algorithm flow chart.  
deceleration stages to ensure smooth operation and reduce vibrations. To achieve this, the velocity profile is composed of acceleration end points \(t_{1}\), constant speed end points \(t_{2}\), and maximum angular velocities \(v_{w}^{\max}\), but where \(t_{1}\) and \(t_{2}\) are both known. Each axis motor has a different velocity profile based on the specific circumstances.  
The angular velocity \(\theta_{1}\) in the first stage is represented in Equation (20), while \(\theta_{2}\) in the third stage is depicted in Equation (21).  
\[\theta_{1}=\frac{t}{t_{1}}2\pi \tag{20}\]  
\[\theta_{2}=\frac{1-t}{1-t_{2}}2\pi \tag{21}\]  
The velocity curve can be categorized into three stages, and the angular velocity of each stage is expressed in Equation (22).  
\[\left\{\begin{array}{l}v_{w}(t)=\frac{v_{w}^{\max}}{2\pi}(\theta_{1}-\sin \theta_{1}),0<t\leq t_{1}\\ v_{w}(t)=\
u_{w}^{\max},t_{1}<t\leq t_{2}\\ v_{w}(t)=\frac{v_{w}^{\max}}{2\pi}(\theta_{2}-\sin\theta_{2}),t_{2}<t\leq 1 \end{array}\right. \tag{22}\]  
If the velocity curve is known, the angular displacement \(\Delta\theta\) can be calculated by integrating. The specific calculation process is shown in Equations (23)-(26). The maximum angular \(v_{w}^{\max}\) velocity can also be calculated from these.  
\[\begin{array}{l}\Delta\theta=\int\limits_{0}^{t_{1}}\frac{v_{w}^{\max}}{2 \pi}(\frac{t}{t_{1}}2\pi-\sin(\frac{t}{t_{1}}2\pi))dt+\int\limits_{t_{1}}^{t_ {2}}v_{w}^{\max}dt\\ +\int\limits_{t_{2}}^{1}\frac{v_{w}^{\max}}{2\pi}(\frac{1-t}{1-t_{2}}2\pi-\sin (\frac{1-t}{1-t_{2}}2\pi))dt\end{array} \tag{23}\]  
\[\Delta\theta=\frac{v_{w}^{\max}\times t_{1}}{2}+v_{w}^{\max}\times(t_{2}-t_{1 })+\frac{v_{w}^{\max}\times(1-t_{2})}{2} \tag{24}\]  
\[\Delta\theta=\frac{v_{w}^{\max}(1+t_{2}-t_{1})}{2} \tag{25}\]  
\[v_{w}^{\max}=\frac{2\times\Delta\theta}{1+t_{2}-t_{1}} \tag{26}\]  
The objective function is a very important index in the trajectory rule, and the optimal trajectory can be obtained only by designing the objective function reasonably. This paper is mainly to reduce the jitter during the operation of the robot arm so that it can run smoothly and ensure the grabbing quality of the robot arm. Therefore, in the design of our objective function, we comprehensively consider the angular acceleration of the X axis, Y axis, Z axis, and rotation axis. The objective formula is as follows:  
\[f=\min\{|A_{\text{X,max}}|,|A_{\text{Y,max}}|,|A_{\text{Z,max}}|,|A_{\text{Q, max}}|\} \tag{27}\]  
where \(A_{\text{X,max}}\), \(A_{Y,\max}\), \(A_{Z,\max}\), and \(A_{\text{Q,max}}\) represent the maximum acceleration of the X axis, Y axis, Z axis, and rotation axis, respectively.  
In the first step, the setup is initialized, and then the acceleration end time and uniform end time for each motor are updated.  
In the second step, the step is to use the interpolation algorithm to fit the velocity curve. Then, Equations (20)-(26) are used to calculate the angular displacement, angular velocity. and maximum angular velocity of the motor.  
In the third step, the step is to run the robot arm according to the designed speed curve.  
In the fourth step, the fitness value is calculated using sensor information based on four reference indices, including the maximum acceleration of the X, Y, and Z axes, along with the rotation axis.  
In the fifth step, the fitness values are calculated, the individual and global optimal values are updated, and the adaptive weight parameters and adaptive acceleration parameters of the particles are updated. Then, it judges whether the set number of iterations is reached, if not, it returns to step 1; If reached, the iteration ends. The output is the current optimal value.