# Semi-Active Magnetic Levitation System for Education
## 2 Material and Methods
### Control Algorithm  
The proposed PID-like controller is model free and does not depend on the system model. However, Appendix A presents the mathematical model to understand the experiment better. The proposed control law aims to enable the system output \(d\) to track the ideal output \(x_{ref}\) under a semi-active approach. This means that the control is only activated in one direction, opposite to gravitational force, introducing a challenge control design, in contrast with, for instance, [14; 18; 23; 30; 31; 32], where the active approach is employed. Moreover, the maximum voltage is stated at 5 \(V\); however, in the literature, its maximum is \begin{table}
\begin{tabular}{l l r} \hline \hline
**Element** & **Specification** & **Price** \\ \hline Arduino Uno & & 20.07 \\ Hall sensor & A1321 & 0.57 \\ Object & Neodymium disc & 0.10 \\ Capacitator & 10 \(\mu\)F & 0.25 \\ Resistor & 580 \(\Omega\) & 0.10 \\ Diode & 1N5817 & 0.32 \\ Transistor & NTD4858N & 0.70 \\ Solenoid & 15 mH–2.4 \(\Omega\) & 9.13 \\ \hline Total & & 31.24 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Component list and cost calculation in EUR. Figure 5: Hall-effect sensor circuit. The sensor is connected to the analog input of the Arduino Uno through PIN A0. The capacitor \(C=10\,\mu\)F was included in the filter noise. usually 12 V [19]. Considering that the Arduino Uno works with voltage ranging from 0 to +5 V, we must introduce hard saturation to the input:  
\[v=\min(\max(u_{k},0),5). \tag{1}\]  
By recalling that \(x_{k}\) represents the distance, and considering that the control strategy requires the speed of the object, we can use the Euler approximation method to compute the object's speed, for example, \(\delta x_{k}\), as  
\[\delta x_{k}=\frac{x_{k}-x_{k-1}}{h}, \tag{2}\]  
where \(h>0\) denotes the board sampling time. In the equipment, \(h=0.01\) seconds is used. The integral term reads as  
\[I_{k}=al_{k-1}+h(x_{ref}-x_{k}). \tag{3}\]  
Parameter \(a\) must be introduced to stabilize discrete integration. To avoid the drift of the element \(I_{k}\) when the controller becomes saturated (i.e., integrator windup), we impose that  
\[\text{If }I_{k}>T,\quad\text{then }I_{k}=0, \tag{4}\]  
where \(T>0\) represents a threshold value to be chosen. Additionally, we consider \(T<5\), since the Arduino Uno converts the voltage representation of 0-5 V into a PWM signal of 0-255 units (8 bits). First, we recall the classical PID control for the sake of experimental comparisons:  
\[u_{k}^{PID}=-K_{p}(x_{ref}-x_{k})-K_{d}\delta x_{k}-K_{i}I_{k}. \tag{5}\]  
Appendix A presents the mathematical model for the MagLev system, along with the linearized representation, allowing one to select the PID parameters in (5) using, for instance, pole placement. We suggest that the control algorithm to the MagLev is a straightforward adaptation of the well-known anti-windup PID control [33], which, in our case, reads as  
\[u_{k}=-K_{p}(x_{ref}-x_{k})\text{sign}(\delta x_{k})-K_{d}\delta x_{k}-K_{i}I _{k},\quad\text{subject to (\ref{eq:1})}. \tag{6}\]  
The control parameters \(K_{p}\), \(K_{d}\), and \(K_{i}\) are positive constants. To perform the comparison, we use the same parameter values in (5) and (6). It was observed in the laboratory that hysteresis was the main difficulty to achieve the levitation, despite the control method. It is well known that the magnetic flux does not disappear completely, as the electromagnetic core still retains some of its magnetism, even when the current has stopped flowing in the coil [34] (Ch. 1.6). Moving the input signal to the linear region of the hysteretic loop by adding a constant DC current is the simplest method to solve this problem, but with the disadvantage of adding noise, see [35]. Thus, the input voltage must be modified by a constant \(D>0\) in (5) and (6) to diminish the hysteresis produced by the electromagnet [36].