## 2 Introduction
### DC Motor Control
\[V_{a}=R_{a}*i_{a}+L_{a}*\frac{di_{a}}{dt}+e_{b}, \tag{1}\]  
\[e_{b}=K_{\omega}*\ \omega, \tag{2}\]  
\[T_{m}=K_{m}*i_{a} \tag{3}\]  
\[T_{m}=J*\frac{d\omega}{dt}+b*\omega+T_{l}, \tag{4}\]  
where \(\mathrm{V_{a}}\) is armature voltage, \(\mathrm{i_{a}}\) is armature current, \(\mathrm{R_{a}}\) is armature resistance, \(\mathrm{L_{a}}\) is armature inductance, \(\mathrm{e_{b}}\) is back-emf voltage, \(\mathrm{K_{\omega}}\) is back-emf constant, \(\mathrm{K_{m}}\) is motor torque constant, \(\mathrm{\omega}\) is rotor angular speed, \(\mathrm{T_{m}}\) is motor torque, \(\mathrm{J}\) is rotor inertia, \(\mathrm{b}\) is viscous friction constant, and \(\mathrm{T_{l}}\) is load torque. If we organize these four equations into proper order and make the necessary replacements, we have a second-order system from armature voltage input to rotor angular speed output, which is given in the following equation below. \[\frac{\Omega(s)}{V_{a}(s)}=\frac{K_{m}}{L_{a}Js^{2}+(R_{a}J+bL_{a})s+(K_{m}K_ {b}+R_{a}b)} \tag{5}\]  
Note that the brushed DC motor with second-order dynamics is inherently linear with linear differential equations in its mathematical model. Plants with linear dynamics can be controlled with classical controllers using analytical design techniques explained in control theory textbooks, but these analytical analysis and design techniques assume ideal conditions with little or no external disturbance. Making an additional assumption that \(\mathrm{L_{a}}<<\mathrm{R_{a}}\), that is, armature inductance is much less than armature resistance, which is valid for most practical motors, we have a first-order system from voltage input to angular speed output, which can be represented by the following transfer function:  
\[H(s)=\frac{1}{c_{1}*s+c_{0}}, \tag{6}\]  
which has only two parameters: constant coefficient \(\mathrm{c_{1}}\) and constant coefficient \(\mathrm{c_{0}}\). Figure 2: Block diagram of a DC motor system. Note that, even if the armature inductance \(\mathrm{L_{a}}\) is not ignored, the system has second-order dynamics with a very small highest-order coefficient, which practically resembles the dynamics of a first-order system. So, ignoring the small highest-order coefficient does not affect the performance results of the full system. A real DC motor's parameters are estimated using parameter estimation experiments and the following parameters are found using the PSO algorithm, details of which are provided in Section 2.3 below:  
\[\mathrm{c_{1}}=0.00253256,\,\mathrm{c_{0}}=0.09365946\]  
The real DC motor's parameters are used to simulate the system more realistically in the simulation experiments. This leads to more helpful simulation results, which give insight into the performance of real systems to be implemented in the future. The parameters of the optimal PI controller are also determined using the PSO algorithm and are found as follows:  
\[\mathrm{K_{p}}=1.5,\,\mathrm{K_{i}}=4980.0\]  
Note that the standard PSO algorithm is used to find the optimal parameters of the PI controller with a two-dimensional parameter space, which results in relatively stable findings. Even after 100 epochs, the algorithm converges to optimal values. The real DC motor setup used to estimate the parameters of real DC motor is shown in Figure 3 below. Note that a real DC motor system mainly consists of three parts. The DC motor itself, the optical encoder to measure the speed of the motor, and the gear reduction mechanism to increase the output torque. Optical encoder subsystems consist of a rotating disc with holes on it, an infrared (IR) transmitter, and an IR receiver. In Figure 4 below is shown a close-up photo of the optical encoder used in this study. The IR transmitter sends continuous IR light to the IR receiver. In between the IR transmitter and the IR receiver, there is a rotating disc with a known number of holes on it. The rotating disc is connected to the shaft of the DC motor, so it rotates at the same speed as the motor.