# Stable Rules Definition for Fuzzy TS Speed Controller Implemented for BLDC Motor
## 2 Description of the Speed Control Algorithm
### Bio-Inspired Optimization of the Fuzzy Speed Controller Using the Chameleon Swarm Algorithm
Every specimen represents a single solution. The size of the population (\(N\)) can be adjusted by the user:  
\[\mathbf{x_{i}^{n}}=[x_{i}^{n,1},x_{i}^{n,2},x_{i}^{n,3},\ldots,x_{i}^{n,d}] \tag{18}\]  
where \(n=1,\ \ 2,\ \ 3,\ \ldots,N\) is the number of specimens in the population; \(i\) is the number of iterations; and \(d\) is the number of searched values. The initial population \(x_{0}^{n}\) is compiled in accordance with the following equation:  
\[x_{0}^{n,d}=l_{b_{d}}+v\times(u_{b_{d}}-l_{b_{d}}) \tag{19}\]  
where \(n\) is the number of specimens; \(d\) is the number of dimensions; \(v\) is a randomly drawn value from the range \([0,1]\); \(l_{b_{d}}\) is the lower bound of the search range; and \(u_{b_{d}}\) is the upper bound of the search range. In subsequent iterations, the value of every specimen is updated by adding the correction factor. The improved solution is given by the following equation:  
\[x_{i+1}^{n,d}=\Delta_{x_{i}^{n,d}}+x_{i}^{n,d} \tag{20}\]  
where \(x_{i+1}^{n,d}\) is the new solution; \(\Delta_{x_{i}^{n,d}}\) is the improvement factor; and \(x_{i}^{n,d}\) is the current solution. The improvement factor is calculated in the first step of the algorithm--corresponding to prospection for prey. The formula for this parameter is given by Equation (21). The selection is carried out during every iteration and is performed by randomly drawing a switch value (s). \[\Delta_{x_{i}^{n,d}}=\left\{ \begin{array}{ll}\mu((u_{b_{d}}-l_{b_{d}})v_{3}+u _{b_{d}})sgn(v_{4}-0.5)&s<P_{p}\\ \sigma(g_{i}^{n,d}-G_{i}^{d})v_{1}+\tau(G_{i}^{d}-x_{i}^{n,d})v_{2}&s\geqslant P _{p}\end{array} \right. \tag{21}\]  
where \(s\) is the randomly generated switch value; \(u_{b_{d}}\) and \(l_{b_{d}}\) are the upper and lower boundaries of the search range, respectively; \(\tau\) and \(\sigma\) are the customizable CSA parameters; \(sgn()\) is the sign function; \(v_{1},v_{2},v_{3},v_{4}\) are the random numbers drawn in every iteration from the range \([0,1]\); \(g_{i}^{n,d}\) is the best solution obtained so far by the exact \(n^{\prime}h\) specimen; \(G_{i}^{d}\) is the global best solution so far; and \(\mu\) is the consistently decreasing step factor. Then, the eye rotation stage is computed, and thus the transformation of the improvement vector is obtained in the form of rotation matrices--for the given problem, along the axes of the 2D coordinate system, as in (22) and (23). \[rot_{x}=\left[ \begin{array}{ccc}1&0&0\\ 0&\cos\phi&-\sin\phi\\ 0&\sin\phi&\cos\phi\end{array} \right] \tag{22}\]  
\[rot_{y}=\left[ \begin{array}{ccc}\cos\Phi&0&\sin\Phi\\ 0&1&0\\ -\sin\Phi&0&\cos\phi\end{array} \right] \tag{23}\]  
In the final step, the hunting process is reproduced--the new solution is approached along the previously calculated vector with the rate corresponding to the chameleon tongue acceleration model given by the equation  
\[a=2590\times(1-e^{-log(i)}) \tag{24}\]  
where \(i\) is the number of iterations. The final solution for every specimen is given by (25):  
\[x_{i+1}^{n,d}=x_{i}^{n,d}+\frac{(p_{i}^{n,d})^{2}-(p_{i-1}^{n,d})^{2}}{2a} \tag{25}\]where \(p_{i}^{n,d}\) and \(p_{i-1}^{n,d}\) are the speeds of the tongue in the two proceeding iterations. The new solutions are evaluated by the cost function. If an improvement is obtained, the global best solution is updated. The optimization process is finished if the maximum number of iterations (\(I_{max}\)) is reached or no improvement in five subsequent iterations is obtained.