## 6 Implementation of the Dynamic Fuzzy Logic Controller (Dynamic FLC)
### Optimization of the Dynamic PSO Mechanism to Tune the Proposed Metaheuristic FLC  
The tuning process of the proposed metaheuristic FLC utilizing 22 variables is described in Section 6.2. In order to dynamically tune these 22 variables, 22 dimensions are taken into consideration in the hyperspace when designing the proposed dynamic PSO mechanism.  
In a traditional PSO mechanism [107], all candidate solutions or particles are unable to converge to an equilibrium position due to the rapid changes in the amplitude and the frequency of the desired input trajectory (the dynamic behavior) of each wheel. To overcome this problem, in the proposed metaheuristic FLC, the parameters of the dynamic PSO mechanism are tuned in real-time through a separately dedicated TSK-FLC. Through this TSK-FLC, for every iteration or discrete sample, the particle positions (solutions) are re-initialized by optimizing the population size \(nPop\), inertia weights (\(\omega_{max}\) and \(\omega_{min}\)) and acceleration coefficients (\(a_{1}\) and \(a_{2}\)) and the PSO is charged by adding dynamic acceleration \(a_{ij}\) into Equation (19). Finally, this 22-dimensional dynamic PSO mechanism can be expressed as shown in (25) and (26):  
\[x_{ij}(t+1)=x_{ij}(t)+v_{ij}(t+1) \tag{25}\]  
\[v_{ij}(t+1)=\omega v_{ij}(t)+r_{1}a_{1}\Big{(}P_{(Best)_{ij}}(t)-x_{ij}(t) \Big{)}+r_{2}a_{2}\Big{(}G_{(Best)_{ij}}(t)-x_{ij}(t)\Big{)}+a_{ij}(t). \tag{26}\]  
where \(a_{ij}(t)=\frac{1}{K}\left[\frac{\sum\limits_{i=1;\ p=1}^{i=\infty}a_{ip}}{(n Pop)}\right]\), \(K\in\mathbb{R}\), \(nPop\) is the population size, \(j\in\mathbb{Z}^{+}\), \(1\leq j\leq 18,r_{1}a_{1}\Big{(}P_{(Best)_{ij}}(t)-x_{ij}(t)\Big{)}\) is the cognitive component and \(r_{2}a_{2}\Big{(}G_{(Best)_{ij}}(t)-x_{ij}(t)\Big{)}\) is the social component.  
The cognitive component and the social component are taken into consideration for the previous best solution and the global best solution, respectively.  
In this mathematical model, for the proposed dynamic metaheuristic FLC, the inertia weight \(\omega\) is computed according to (27) and continuously optimized through the TSK-FLC as described in Section 7.  
\[\omega=\omega_{max}-\bigg{(}\frac{\omega_{max}-\omega_{min}}{maxIterations} \bigg{)}\times Iteration \tag{27}\]  
Figure 10: The PSO program structure of the metaheuristic fuzzy rule base.  
where \(\omega_{max}\) and \(\omega_{min}\) are the maximum and minimum inertia weights assigned in the TSK-FLC, \"\(maxIterations\)\" is the maximum number of iterations and \"\(Iteration\)\" is the current iteration.  
To optimize the metaheuristic FLC via the dynamic PSO mechanism, an objective function \(f_{ob}\) is utilized as the input to the PSO mechanism, which is a function of the \(E_{k}\) and the \(dE_{k}\), as shown in Figure 2. In this dynamic environment, for rapid convergence and enhancement of the performance of the PSO mechanism, an objective function index \(I_{(f_{ob})}\) is taken into consideration while applying a penalty on each constraint violation. Here, \(I_{(f_{ob})}\) is computed according to (28) and (29):  
\[f_{ob}=RMSE=\sqrt{\frac{1}{N}\sum\limits_{k=1}^{N}(E_{k}(t))^{2}} \tag{28}\]  
\[I_{(f_{ob})}=f_{ob}+\left(\sum\limits_{k=1}^{N}E_{k}\right)\times\text{penalty} \tag{29}\]  
where \(\sqrt{\frac{1}{N}\sum\limits_{k=1}^{N}(E_{k}(t))^{2}}\) is the root mean square error.