Position Control of Magnetic Levitation Ball Based on an Improved Adagrad Algorithm and Deep Neural Network Feedforward Compensation Control

To control the position of the magnetic levitation ball more accurately, this paper proposes a deep neural network feedforward compensation controller based on an improved Adagrad optimization algorithm. ,e control structure of the controller consists of a deep neural network identifier, a deep neural network feedforward compensator, and a PID controller. First, the dynamic inverse model of the magnetic levitation ball is established by the deep neural network identifier which is trained online based on the improved Adagrad algorithm, and the trained network parameters are dynamically copied to the deep neural network feedforward compensator. ,en, the position control of the magnetic levitation ball system is realized by the output of the feedforward compensator and the PID controller. Simulations and experiments illustrate that the accuracy of the deep network feedforward compensation control based on an improved Adagrad algorithm is higher, and its control system shows good dynamic and static performance and robustness to some extent.


Introduction
Magnetic levitation system is widely used in magnetic bearing, magnetic suspension vibration isolator, magnetic suspension train, and many other fields because it is contactless, frictionless, and noiseless, etc. A magnetic levitation ball system is a magnetic levitation system with a single degree of freedom [1]. It is a typical control system to study the phenomenon of magnetic levitation and verify various controllers.
Recently, the controllers of the magnetic levitation ball have received a great deal of attention from a number of researchers, and they have done relevant research and obtained rich research results, such as PID control [2,3], GPI control [4,5], sliding mode control [6,7], and robust control [8][9][10]. e design of the above controllers requires a dynamic model of a magnetic levitation ball system. However, the precise dynamic model of the magnetic levitation ball system is difficult to obtain, so the model-free control method is more suitable for it.
Feedforward control is an effective method for tracking problems, which predicts the external interference in advance and generates appropriate control law according to the prediction and input signals. Feedforward control can eliminate disturbance in time, so it can make the control system have higher control accuracy. It is widely used in various domains of the industry. In [11], the trajectory tracking problem of the cable-driven robot is solved by using feedforward compensation. In [12,13], feedforward control has achieved excellent results in machine tool control. In [14], the hot rolling mill is well controlled by the feedforward controller. But feedforward control is difficult to design because the precise mathematical model of the controlled plant is usually difficult to obtain. e neural network can approximate continuous functions closely, so there has been much research on the use of the neural network for model-free control. By training the neural network online or offline, the performance of the control system can be improved, and finally, a satisfactory control effect can be achieved [15][16][17][18][19][20]. Nowadays, neural network control is promisingly used in magnetic levitation ball system. In [21], electromagnetic parameters are approximated by the neural network. On this basis, a neural network controller is proposed. In [22,23], a magnetic levitation ball model is approximated by RBF neural networks. e model parameters are identified offline by applying the structured nonlinear parameter optimization method. Based on the model, a predictive controller is designed. In [24], a new neural network controller for a magnetic levitation ball system is proposed. e proposed controller comprises a neural network controller and a robust controller. In [25], a dynamic model of control system error and control law is established online by BP neural network. Based on the model, a neural network controller is designed with a PID controller. e controllers identify relevant parameters of the control system by the neural network, and the controller is designed by identified parameters. Although these controllers have achieved good results, the control accuracy can be further improved. e control accuracy of the above methods is affected by the accuracy of the neural network model. erefore, improving the modeling accuracy of the neural network is an effective way to improve the control accuracy of the neural network controller. Generally, the complex neural network can improve the modeling accuracy of the controlled plant. In order to fully train the complex neural network, multiple iterations are needed. However, the computation time generated by multiple iterations is difficult to meet the requirements of real-time control. In order to solve the above problems, this paper proposed a deep neural network feedforward compensation controller based on an improved Adagrad algorithm. First, a dynamic inverse model of the controlled plant is established online by the deep neural network, which is regarded as a model identifier. Meanwhile, the parameters of the identifier are dynamically copied to the feedforward compensator which has the same structure as the identifier. us, the proposed controller in this paper is designed by the deep neural network identifier, feedforward compensator, and PID controller. en, an improved Adagrad optimization algorithm with better convergence accuracy and faster convergence rate is proposed to solve the problem of slow training of the neural network and network parameter delay caused by online training of the neural network controller. e improved Adagrad optimization algorithm was used to train the identifier. Finally, simulation and experiment are conducted to verify the effectiveness of the proposed controller. e main innovations of this article are summarized as follows: (1) An improved Adagrad optimization algorithm is proposed to solve the problems that may occur in the online training of the neural network controller, such as delay, slow training, and control accuracy (2) A deep neural network feedforward compensation controller is proposed by combining the PID controller with a deep neural network. e effect of the proposed controller is proved by simulation and experiment e rest of the paper is organized as follows. Section 2 introduces the magnetic levitation ball control system. Section 3 introduces the feedforward compensation control method of a deep neural network based on an improved Adagrad optimization algorithm. Section 4 verifies the performance of the improved Adagrad optimization algorithm with benchmark function and conducts simulation and experimental research on the control method proposed in this paper. Section 5 is the conclusion.

Magnetic Levitation Ball Position
Control System

Principle of Magnetic Levitation
Ball. e working principle of the magnetic levitation ball control system studied in this paper is shown in Figure 1. In the real-time control, the light transmission area of the slit of the photoelectric position sensor and the illuminance of the silicon photocell change accordingly when the position of the steel ball changes in the vertical direction. e photoelectric position sensor transforms the displacement signal of the ball into a voltage signal that changes in proportion to the level of illumination. en, the voltage signal is input to a computer after signal conditioning and A/D conversion. e controller calculates the control law after comparing the input computer signal with the command position of the maglev ball. After D/A conversion and power amplification, the control law controls the current i in the electromagnet winding, so that the electromagnet generates the corresponding electromagnetic attraction F, and then controls the position of the steel ball.

Modeling of Magnetic Levitation Ball.
In order to build the mathematical model of the magnetic levitation ball, the following assumptions must be made: (1) Magnetic flux leak, edge effect, and reluctance between the ball and the electromagnet are ignored (2) e ball is a homogeneous sphere, and the magnetic force is concentrated towards the center of it (3) ere is a linear relationship between the output current and the input voltage of the power amplifier, and there is no delay Based on the above assumptions, the mathematical model of the magnetic levitation ball system can be established through theoretical derivation. e dynamic equation of the ball is derived from Newton's second law as follows: where m is the mass of the ball, g is the acceleration of gravity, x is the ball position, F(i, x) is the electromagnetic force on the ball, and i is the instantaneous current of the electromagnet winding.
According to Kirchhoff laws and Biot-Savart Law of the magnetic circuit, the electromagnetic force on a ball can be deduced as follows: where K is the constant coefficient related to the magnetic flux of the electromagnet winding. When the ball is in a state of balance, the formula is obtained according to the mechanical balance principle as follows: where x o and i o are the air gap and the current in the coil when the magnetic levitation ball is in equilibrium. Combined with equations (1)-(3), the formula is as follows: Taking the input voltage of the power amplifier (U in ) as input and the output voltage of the photoelectric position sensor (U out ) as output, the transfer function of the magnetic levitation ball control system can be given as follows: where K s is the gain of the photoelectric position sensor and K a is the gain of the voltage-current power amplifier. For the magnetic levitation ball position control experimental platform shown in Figure 1, the relevant parameters in equation (5) are shown in Table 1.
Substitute the physical parameters of the magnetic levitation ball system into equation (5). e system transfer function of the magnetic levitation ball position control system is calculated as follows:

Control Principle.
e feedforward compensation control of a deep neural network is designed for a magnetic levitation ball, and the structure is described in Figure 2. e main design ideas of the controller shown above are as follows: First, the inverse model of the controlled plant is established online by the deep neural network identifier (DNNI), and then the trained parameters are dynamically copied to the deep neural network compensator (DNNC). e data of the training network is the control law and output signal produced in each control period. Second, DNNC and the PID controller are combined, and it can produce control law together. e inverse model of the controlled plant cannot be established accurately by DNNC in the early stage of control, so the PID controller is introduced to ensure the control accuracy in the early stage of control.
e actual control law of the controller proposed in this paper can be designed as follows: where u 0 is the output of the PID controller and u c is the output of DNNC. e output of the PID controller is calculated as follows: where k p , k i , and k d are hyperparameters. Magnetic levitation ball control system is a complex nonlinear control system [26]. It is not accurate to establish the inverse model of the controlled plant only by using the neural network with a single hidden layer. e modeling accuracy of the deep neural network is higher because it has a stronger nonlinear mapping ability than that of a single hidden layer neural network [27,28]. erefore, the identifier and compensator established by a deep neural network can enhance the control accuracy. Figure 2, DNNI and DNNC have the same network structure, both of which are multi-hiddenlayer neural networks. e DNNI is trained online once per control period based on real-time position y and control law u of the control system. en, the trained parameters of the DNNI are dynamically copied to the DNNC. Based on the reference signal r, the compensation control law u c of the current control period is determined by the forward calculation of DNNC. e control law u is calculated by u c and PID controller output u o . e deep neural network used in DNNI and DNNC includes an input layer, multiple hidden layers, and an output layer. e forward calculation and training of the network are as follows.

Forward Calculation.
e whole deep neural network has n + 1 layers, and there is n a weight matrix w 1 ∼ w n in total. e input of the layer k is defined as net k and the output as out k . en, the input calculation process and output calculation process of each layer are as follows: Input layer: by directly inputting the reference signal into the neural network and pass it directly to the next layer, as follows: Hidden layer: the value of the input hidden layer becomes output after being processed by the activation function. In this paper, the Leaky ReLU function is used as the activation function. e input and output of layer k are as follows: where w is the weight matrix between two layers, b is the bias, and δ is the Leaky ReLU function.
Output layer: by implementing linear operations. e output of the deep neural network is as follows: k p e (k) e calculation process of u c is consistent with that of u N .

Training of Deep Neural Network.
In Section 3, we improved the optimization algorithm. e network is trained using the improved Adagrad algorithm in the process of backpropagation. e loss function is as follows: where u is the reference signal, and u N is the output of DNNI. e training objective of the deep neural network is to minimize L. e training process of parameters is as follows: w n error gradient: w n− 1 error gradient: where δ ′ is the derivative of the activation function, w T is the transposition of the weight matrix, and ξ is the intermediate variable. e other symbols are the same as before. w n− 2 error gradient: e above symbols are the same as before. e calculation method of w n− 3 ∼ w 1 error gradient is the same as that of w n− 2 . b n error gradient: e above symbols are the same as before. e error e gradient of all network parameters can be obtained by the above formula. en, the gradient is substituted into the appropriate optimization algorithm to update the network. e dynamic inverse model of the controlled plant is established by an online training network, and the network is trained only once per control period. erefore, it is necessary to select the optimization algorithm with better convergence accuracy and faster convergence rate; otherwise, the network is not fully trained, which will affect the control accuracy.
Using the Adagrad algorithm instead of the gradient descent method to train the neural network can improve the accuracy of network modeling with fewer iterations, which can meet the accuracy requirements of parameter identification in neural network control. is is because the Adagrad algorithm has better convergence accuracy and convergence rate [29,30]. However, Adagrad is still to be improved for instance. e convergence accuracy and convergence rate are far from satisfying and the learning rate is too small in the later stage of training.
In order to fully train the network with fewer iterations to make the established model have higher accuracy, this paper improves Adagrad. e formula of improved Adagrad is as follows: where w t−1 is the parameter before the update, w t is the parameter after the update, η is the learning rate, g t is the gradient value, s t is the sum of the squares of the gradient used in this update, s t−1 is the sum of the squares of the gradient used in the previous update, the initial value of s is 0, and ε is a smoothing term that avoids division by zero (the value is usually le − 8). α and c are hyperparameters, and the value of α is 0.95, which guarantees that the learning rate will not be too low in the later stage of training. e gradient obtained in equations (13)-(18) is substituted into equations (7) and (8) to update the network parameters. In [31], it reveals the similarity between the calculation of the parameter update amount in the process of neural network training and calculation of control law in the process of control by the PID controller. Based on this, we add a gradient differentiation term to Adagrad to build an improved Adagrad algorithm. e function of gradient differentiation is to predict the change trend of neural network parameters in the future and it is similar to the error differentiation in the PID controller. It improves the convergence accuracy and convergence rate of Adagrad by providing predictive compensation amount in the process of weight updating.

Results and Discussion
In this section, the effectiveness of the improved Adagrad optimization algorithm is verified by the benchmark function, and then the effectiveness of the controller proposed is verified by simulation and experiment. Simulation and experiment will compare the control effect of the four controllers. ese four controllers are PID controllers and three controllers proposed in this paper. e three controllers are an Adagrad-based neural network controller (ANNC), an improved Adagrad-based neural network controller (IANNC), and an improved Adagrad-based deep neural network controller (IADNNC), respectively. e three controllers have the same control structure as shown in Figure 2, but the implementation of model identifier and Mathematical Problems in Engineering feedforward compensator is different in these controllers. eir implementation is similar to DNNI and DNNC in Figure 2, but not identical. ey are implemented by different optimization algorithms and different numbers of hidden layers, as shown in Table 2.

Benchmark Function Verification.
e performance of the Adagrad optimization algorithm and the improved Adagrad optimization algorithm is compared by five benchmark functions [32]. e benchmark functions are shown in Table 3. e convergence accuracy of the optimization algorithm is evaluated by the result of iteratively solving the benchmark function. e function iterates from the same initial value. e maximum number of iterations is selected as 5000.
e learning rates of both optimization algorithms are 0.1. e closer the result of either algorithm is to the theoretical minimum value of the reference function result, the better the convergence accuracy of the algorithm is.
e experimental results are shown in Table 4.
e results in Table 4 show that the improved Adagrad algorithm has better convergence accuracy, and its solution results are closer to the theoretical minimum. e convergence rate of the optimization algorithm is evaluated by the number of iterations needed to solve the benchmark function to reach the standard. e standard result of each benchmark function is the one with the larger result in Table 4. e learning rates of both optimization algorithms are 0.1. e fewer the number of iterations required, the faster the convergence rate of the algorithm. e experimental results are shown in Table 5.
e results in Table 5 show that the improved Adagrad algorithm has a faster convergence rate. e standard can be reached faster by solving the benchmark function iteratively with the improved Adagrad algorithm. e results of benchmark function verification show that the improved Adagrad optimization algorithm has better convergence accuracy and faster convergence rate. So, the proposed controller will use the improved Adagrad optimization algorithm to train the network.

Simulation Results.
e following simulation tests the influence of the improved Adagrad optimization algorithm on the control effect. In the simulation, the control period is 3 ms. e parameters of the PID controller are k p � 8, k i � 6, and k d � 0.2. Parameters of the PID controller are the optimal parameters obtained by many experiments. e weight matrix and bias initial value of the neural network are random numbers within (−1, 1). ere are five neurons in each hidden layer. e learning rate is 0.015, and the hyperparameter c of the optimization algorithms in IANNC is 0.98. e activation function is Leaky ReLU. e sinusoidal signal is as in equation (18) which is in radians and one period of the trapezoidal signal is as in equation (19). Time is in seconds.
e simulation results of the magnetic levitation ball follow the sinusoidal reference signal, as shown in Figures 3  and 4, and the trapezoidal reference signal, as shown in Figures 5 and 6. e results show that the IANNC provides better control in simulations. Figures 7 and 8 show the training process of the weight matrix between the hidden layer and the output layer when using IANNC to control the magnetic levitation ball system to track sinusoidal and trapezoidal signals. Each line represents a weight parameter. It can be known from the figure that the weights in the controller will change because the network will be trained once per control period. e training data is the control law and output signal that are generated in each control period. Using the Adagrad algorithm to train the network will produce some problems. e first is the delay problem. is is because we use the data generated in the t n−1 control period to train the network and then use the trained network to predict the control law of the t n control period. In the prediction process, it will be affected by various time-varying factors, so the predicted result will have certain errors. erefore, we add a gradient differential term to Adagrad. According to the change trend of the gradient, we can predict the future parameter value, so the way of calculation will help to reduce the delay error. e second is inadequate network training. Because we train the network only once per control period, it is difficult to train the network fully in one iteration using the Adagrad algorithm. e convergence rate can be improved by increasing the differential of the gradient, which has been proved in Table 5. In order to ensure real-time performance, we can only train the network once per control period in actual control. erefore, the improved Adagrad optimization algorithm is used to speed up the network training, so that the network model established under one training has higher accuracy, which improves the control accuracy. e next simulation tests the influence of the number of hidden layers on the control effect. rough this simulation, the number of hidden layers in the controller is selected. PID controller parameters, neural network parameters, and sinusoidal signal are the same as those in the previous simulation. In the simulation, the feedforward compensation control effect of the neural network with 1, 2, 3, 4, 5, 6, 7, and 8 hidden layers is tested. e control reference signal is a sinusoidal signal. For each kind of neural network, the average absolute value integral of the error over ten times simulation is reported for comparison. e simulation results are shown in Figure 9. According to the analysis of the simulation results in Figure 9, it can be known that increasing the number of hidden layers can improve the control accuracy within limited. For the magnetic levitation ball control system, it is suitable that the neural network in the controller has 5 hidden layers. When the hidden layer is increased to five layers, increasing the number of hidden layers will not only not improve the control accuracy but also increase the calculation time.
e last simulation further tests the influence of the number of hidden layers on the control effect. PID controller parameters, neural network parameters, and reference signals are the same as those in the previous simulation. In the simulation, we test the influence of IANNC and IADNNC (with five hidden layers) on the control accuracy. e simulation results of the magnetic levitation ball follow the sinusoidal reference signal, as shown in Figure 10, and a trapezoidal reference signal, as shown in Figure 11. e results of the two controllers in the comparison figure show that the IADNNC provides the best control in simulations. We can know that the network structure of IADNNC is more complex than that of IANNC, so more data is needed to fully train the network used in IADNNC. In the initial phase, the network of IADNNC is not fully trained by enough data, resulting in a less accurately established network model and a larger error of tracking. Figure 12 shows the experimental platform of magnetic levitation ball position control. In this paper, the data acquisition control card PCI-1711 supported by MATLAB/Simulink is used to realize the realtime collection of magnetic levitation ball position and the output of control law. Based on the MATLAB/RTW software platform, the hardware in the loop experiment verification of the control method proposed in this paper is carried out. e following experiment tests the influence of the improved Adagrad optimization algorithm on the control effect. In the experiment, the control period is 3 ms. e parameters of the PID controller are k p � 1.5, k i � 0.3, and k d � 15. Parameters of the PID controller are the optimal parameters obtained by many experiments. e weight matrix and bias initial value of the neural network are random numbers within (−1, 1). ere are five neurons in each hidden layer. e learning rate is 0.015, and the hyperparameter c of the optimization algorithms in IANNC is 0.98. e activation function is Leaky ReLU. e sinusoidal signal is as in equation (18) which is in radians and one period of the trapezoidal signal is as in equation (19). Time is in seconds. r(t) � 2.18 sin(0.5t + 2.4328) + 10.9,
e experimental results of the magnetic levitation ball follow a sinusoidal reference signal, as shown in Figures 13  and 14, and a trapezoidal reference signal, as shown in Figures 15 and 16. Table 6 shows the error range when three controllers are used to control the magnetic levitation ball.
Based on the above experimental results, it can be concluded that IANNC has a better control effect under the same PID controller parameters. IANNC can make the control system perform with better steady-state accuracy and dynamism.   e next experiment tests the influence of the number of hidden layers on the control effect. PID controller parameters, neural network parameters, and reference signals are the same as those in the previous experiment. In the experiment, using the neural network with too many hidden layers will lead to a longer calculation time of the control quantity than that of the control period. erefore, we test the influence of IANNC and IADNNC (with two hidden layers) on the control accuracy, only to verify whether increasing the number of hidden layers can improve the control accuracy and the change trend of control accuracy is shown in Figure 9. e experimental results of the magnetic levitation ball follow a sinusoidal reference signal, as shown in Figure 17, and a trapezoidal reference signal, as shown in Figure 18. Table 7 shows the error range when two controllers are used to control the magnetic levitation ball.
Based on the above experimental analysis results, it can be concluded that increasing the number of hidden layers of neural network in the controller can improve the control accuracy. In Figure 17, the trend of error change caused by increasing the number of hidden layers is similar to that in Figure 9.       Table 8 proves that the IADNNC produces an obviously smaller RMSE than the other controllers.
In order to test the anti-interference ability of the controller IANNC and IADNNC, the interference is exerted by touching the steel ball with fingers at a random moment in the sinusoidal signal tracking experiment. e anti-interference experiment results of IANNC and IADNNC sinusoidal signal tracking control are shown in Figures 19 and 20. ey prove that the control system can         quickly return to a stable state after being disturbed by the external environment, and the control system has certain robustness.

Conclusion
In this paper, a deep neural network feedforward compensation controller based on the improved Adagrad optimization algorithm is proposed. e improved Adagrad optimization algorithm and deep neural network are used to solve the problems that may occur in the application of the neural network in the control field, such as delay, slow training of the neural network, model accuracy, and control accuracy. By improving the accuracy of the dynamic inverse model of the controlled plant in the neural network controller, the control accuracy can be further improved without changing the controller structure. In the proposed controller, the dynamic inverse model of the controlled plant is established by a deep neural network that is trained by an improved Adagrad optimization algorithm. en, a feedforward compensation controller is obtained by mixing this model with the PID controller. e simulation and experimental results demonstrate that the proposed IADNNC has a good control effect. e proposed controller can also be applied to other nonlinear systems, particularly time-varying systems and systems with uncertainty which are difficult to be obtained by mathematical methods. e application of other deep neural network models in the control field will be a topic for future study.

Data Availability
No data were used to support this study.

Conflicts of Interest
e authors declare that there are no conflicts of interest in this paper.