## 2 Materials and Methods  
### Proposed System  
Given plant dynamics, expected references, and expected disturbances, an optimal neural network-based controller is automatically designed using the proposed system. The optimal neural network-based controller is composed of two parts and is shown in Figure 5 below.  
The first part is the optimal PI controller whose parameters are found using the PSO algorithm. The second part is used for fine-tuning of the system and has a single-layer neural network structure. The input-output relations of the two controllers are as follows:  
\[u_{cpi}=K_{p}*e+K_{i}*\int edt, \tag{7}\]  
where e is the error signal which is the difference between the reference and the output.  
\[u_{cann}=\sum_{i=1}^{t_{post}}w_{1i}*\omega_{i}+\sum_{j=1}^{t_{post}}w_{2j}* \omega_{refj}+\sum_{k=1}^{t_{start}}w_{3k}*\omega_{refk}, \tag{8}\]  
Figure 4: Close-up photo of optical encoder used to measure speed of the motor.  
Note that the system is single-input single-output (SISO), but the subindices of the system output and the reference values above may seem like a multi-output system at first sight. Actually, the subindices i, j, and k in the above equation refer to the timing index of the same single output and reference taken at different times.  
Here, \(\mathbf{t_{\text{past}}}\) and \(\mathbf{t_{\text{future}}}\) are past and future window size in terms of sampling time, \(\mathbf{w}\) are neural network weights, \(\omega\) are plant's output, and \(\omega_{\text{ref}}\) are references.  
Note that this structure is theoretically equivalent to a controller with only the neural network part, but it is observed that using a purely neural network controller leads to a difficult tuning of weights with sometimes unstable results. So, the controller is divided into two parallel parts with the optimal PI controller addressing coarse error signals and the neural network part improving with the fine-tuning of the controller output.  
Neural networks have several advantages over their alternatives and are widely used in various applications. A number of parameters which determine the complexity of the neural network can be adopted very conveniently by just changing the number of neurons. This gives the designer the ability to adopt the complexity of the controller required by the application; hence, the neural controller is chosen in this study. Note that the proposed approach with a neural network controller has many more parameters than the optimal PI controller, so it can be used in more versatile disturbance conditions which are shown in this study.  
It is shown in [31] that the complexity of a neural network is mainly related to the number of neurons but not to the number of layers. So, the simplest topology of single-layer linear neural networks is chosen in this study. The performance of the nonlinear multilayer neural network controller may be investigated in detail in future studies.  
The proposed controller is designed with the following steps:  
1. Choose limits of controller output;
2. Design an optimal PI controller using the PSO algorithm;
3. For fine-tuning, design a neural network controller with the PSO algorithm.