# The Full-Field Path Tracking of Agricultural Machinery Based on PSO-Enhanced Fuzzy Standley Model
## 3 PSO-Enhanced Fuzzy Stanley Model
### Implementation of PSO-Enhanced FSM  
The fitness function of PSO is also named as the objective function. The selection of fitness function has a significant effect on the convergence speed and steady-state accuracy of the PSO-FSM. The integral time absolute error (ITAE) is frequently applied as the performance metric in the automatic control community, which calculates the integral of the product of the time and absolute error value for some predefined time interval [33]. In this paper, the inverse of the sum of ITAE of lateral deviation and heading deviation is used as the fitness function, and the calculation formula is as follows  
\[f=\omega_{1}\Delta t\sum_{j=1}^{N}t_{j}|e(j)|+\omega_{2}\Delta t\sum_{j=1}^{N} t_{j}|\theta_{e}(j)| \tag{8}\]  
\[F=\frac{1}{f} \tag{9}\]  
where \(f\) is the sum of ITAE of lateral deviation and heading deviation, \(\omega_{1}\) and \(\omega_{2}\) are the weights which correspond to ITAE, \(\Delta t\) is the integration interval, and \(e(j)\) and \(\theta_{e}(j)\) correspond to the lateral deviation and heading deviation at time \(j\Delta t\). \(N\) is the number of control periods involved in the calculation of the \(f\) value, and \(F\) is the fitness value employed for PSO-FSM.  
The PSO simulates birds in a flock by designing a massless particle where only the speed and position are adjustable, and the flowchart of PSO is shown in Figure 4. Firstly, each particle searches for the optimal solution individually in the search space, then, its position is recorded as the local optimal position. Secondly, each particle shares its optimal position with other particles in the entire flock to find the temporary global optimal position of the current flock. Finally, each particle in the flock adjusts its attributes continuously according to the optimal position of the individual and the current flock until the global optimal solution is found. The specific procedures are as follows:  
1. Initialize the particle flock. Parameters such as the inertia coefficient \(\omega\) and learning factor \(c_{1}\), \(c_{2}\) are determined according to the operation of agricultural machinery.
2. Calculate the fitness of each particle in the flock and update the optimal position of each particle, then calculate the optimal position of the current flock. Adjust the speed and position of each particle accordingly. The calculation formulas are as follows: \[v_{i}(k+1)=\omega v_{i}(k)+c_{1}\xi(p_{\mathit{ibest}}(k)-x_{i}(k))+c_{2}\eta \Big{(}p_{\mathit{gbest}}(k)-x_{i}(k)\Big{)}\] (10) \[x_{i}(k+1)=x_{i}(k)+v_{i}(k+1)\] (11) where \(v_{i}(k)\) and \(x_{i}(k)\) are the velocity and position of particle \(i\) in the \(k\)-th iteration, \(p_{\mathit{ibest}}\) is the optimal position of particle \(i\), \(p_{\mathit{gbest}}\) is the optimal location of the entire flock and \(\xi\) and \(\eta\) are random numbers between 0 and 1.
3. The particles are continuously updated until the maximum number of iterations is reached or the required convergence accuracy is achieved. Then, the optimal position of the flock is the value of the optimization coefficient \(\alpha\).  
Finally, the input and output block diagram of PSO-FSM can be summarized in Figure 5, where \(e\) represents the lateral deviation, \(\theta_{e}\) represents the heading deviation and \(\delta_{\alpha}\) represents the expected front wheel angle after PSO.  
Figure 4: Flowchart of the PSO algorithm.  
Figure 5: Input and output block diagram of PSO-FSM.