13 minute read
u Neural Network-based approximation of model predictive control applied to a flexible shaft servomechanism
Neural Network-based approximation of model predictive control applied to a flexible shaft servomechanism
Yuanwu He, Yuliang Xiao and Nikhil Bajaj
Department of Mechanical Engineering and Materials Science
Yuliang Xiao Yuliang Xiao is from Beijing, China. His interests in robotics and strong education background motivate him to take further research on Robotics and Computer Vision in graduate.
Yuanwu He Yuanwu He was born and raised in Beijing, China. He is passionate about system controls and robotics, which are also the fields he would like to dive in for his career of engineering.
Nikhil Bajaj, Ph.D. Dr. Bajaj is an Assistant Professor in the Department of Mechanical Engineering and Materials Science. He received his PhD from Purdue University in 2017 and served as a postdoctoral researcher from 2017-2019. His current research interests include nonlinear dynamics, mechatronics, advanced sensors, and advanced manufacturing.
Significance Statement
This work seeks to address the computational burden associated with Model Predictive Control (MPC) algorithms, and specifically demonstrates the improvement of the memory footprint of an explicit MPC via the use of feedforward neural networks for approximation of the controller.
Category: Computational Research
Keyword: model predictive control (MPC), machine
learning, feed-forward neural network, computational cost.
Abstract
In this paper, we seek to address the computational burden associated with Model Predictive Control (MPC) algorithms. MPC algorithms seek an optimal control action over a control horizon that drives a discrete time control system according to the determined reference. It is always used in the process industries in chemical plants, oil refineries, power system balancing models and power electronics. One critical limitation of MPC is the computational complexity, which constrains a system’s ability to find an optimal solution in real-time, resulting in limitations on the classes of systems for which MPC can be used. To address this problem, the major findings are to develop explicit MPC (eMPC) algorithms, which precompute the optimal solutions across the state, reference, and input space, and interpolate between optimal solutions via different methods. In general, however, eMPCs are characterized by trading off computational burden in real-time for memory allocation size [1]. In this work we present the successful use of neural networks to approximate a MPC control algorithm for a particular servomechanism and evaluate their performance and utility.
1. Introduction
Model Predictive Control (MPC) is a popular family of control algorithms in a wide and expanding variety of fields [2]. MPC finds the optimal control action over a control horizon that drives a discrete time control system output to the determined reference while honoring the system constraints. Hence, it is a good tool to handle multi-input multi-output systems that interact with inputs and outputs since designing this system by using traditional controllers like PID is challenging. MPC can help solve constraints because it has predictive capabilities, which computes the trajectories of each state in advance in order to select the best control action according to a cost function. This is why engineers often use MPC to get detailed control of each state during a dynamic process, such as chemical plants, oil refineries, and power balancing systems. The optimization problem iteratively evaluates the expected system response at each step over a prediction horizon. Compared to trajectory planning in the task space or the determination of required control commands in the state space [2], MPC is an advanced technique and can generally provide good performance.
The basic MPC algorithm can be computationally expensive. When the prediction horizon is large, a limitation of this approach is its computational burden since the solutions need to be computed in real-time between control actions. This restricts the applicability of MPC to systems that have large time constants and/or high computational power [1]. Decreasing computational cost is a desirable objective, as it will allow for MPC to be practical in more systems. A common way of addressing this is with an “explicit” MPC (eMPC), which trades off memory for computational complexity. The explicit MPC is a way to manage the computational load by pre-computing the optimal control law u* = m*(x) offline as a function of all feasible states x [3].
The eMPC computes the responses offline, and then fits a sequence of hyper-surfaces to the derived responses, giving an approximation of the performance of the MPC. In this research, an alternative approach is proposed. A direct approximation of the MPC’s computed response may be represented with a combination of states and reference inputs via a feed-forward neural network. This method allows for an intermediate solution between the two, with the potential for smoother fitting of the response function due to the universal function approximation properties of the neural network. It contains a tightly connected set of non-linear neurons which approximate the function of the MPC. The new methodology will be applied to a simulated flexible shaft electromechanical servomechanism, which consists of a DC motor, a gearbox, an elastic shaft, and loads. The goal is to use Neural Network to reduce computational efforts while approximating to the performance of MPC.
2. Method
The governing differential equations representing the position servomechanism system are used to define the state-space representation for the plant model. The system has one control input which is voltage applied to the DC motor. One output gives the measurement of the angle of shaft and the torque is estimated as an unmeasured output. The model constants are substituted into the equations and implemented in a state-space form.
A linear model predictive controller was designed using MATLAB’s MPC Designer [4] tool with the derived state equations. This designs a linear MPC, along with an estimator that can easily be tuned to the desired aggressiveness of the response. Although the focus of this work was on approximating the response of the MPC, the actual performance is also important. The MPC computes the input at time k, uk:
uk = fMPC (x, r, uk-1) (1) [2]
Here, x is the vector of states at time k, r is the angle reference and uk-1 is the vector of manipulated variables at time k-1 to be determined by the controller. fMPC (x, r, uk-1) is the result of the optimization problem solved by the MPC given the states, references, and prior inputs. Data was generated based on this function and used as a training set to feed into the Neural Net Fitting App. The goal of the neural network is to reproduce this function, with the neural network, e.g. fNN (x, r, uk-1) ≈ fMPC (x, r, uk-1) . After creating a neural network model, the results of outputs were derived from implementation in Simulink.
Eventually, the performance of newly designed feed-forward neural network model was evaluated by doing error calculations and data comparison. Typically, MSE and plots comparison are used to evaluate approximation of neural network-based approach. Also, the computation time versus the MPC is improved. The computation time of the MPC can be drastically reduced by approximating the MPC law with a Neural Network controller [2].
For neural network, the number of neurons in hidden layer has some effects on its performance. From Gnana et al., the output errors decrease with being added, where Nh is the number of neurons in the hidden layer [5]. In the book, two equations are introduced to explain the relationship between number of neurons in hidden layer and network performance:
Where N is number of training pairs, d is input dimension, and Cf is first absolute moment of Fourier magnitude distribution of target function. Also, MSE could be used to evaluate the performance of network. Based on the functions above, it is possible to construct a mapping function between Nh and MSE. As a result, there is a relationship between number of hidden neurons and MSE. In the following sections, we show results about the effects of the number of hidden neurons on neural network performance.
3. Data Processing
At first, the training samples are gained from the MPC model by using the MATLAB command “mpcmove”. “mpcmove” evaluates fMPC (x, r, u k-1 ) by providing the required states and parameters. The training data features are x ∈ ℝ4 , r, uk-1 ∈ ℝ for this system. Therefore, it is rational to have six input features, and one output for the neural network. The range of the six input variables used in “mpcmove” is based on the physical constraints of the system so that the precision is maximized. Since changing the value of the interval affects the amount of training data gained from MPC, we chose a suitable value that could produce sufficient training examples while considering constraints on computation time. There were 1932612 training examples produced during the training. 70% of these were used as a training set, and 15% used in testing, and 15% in training algorithm validation. Then, a neural network tool was used to train data gained from MPC. Four network architectures, differing in their number of neurons in the hidden layer, were tested, and each of them has different testing performance in error calculations (i.e. mean square error (MSE), regression (R), etc.). The specific values of error are shown in the Table 1.
MSE
R2 15 Neurons 25 Neurons 30 Neurons 40 Neurons
23.82618 14.71504 8.91072 5.76319
0.999434 0.999650 0.999788 0.999862
Table 1: MSE and Regression for different tests
Next, the Neural Network Fitting App provided a neural network function to implement as a Simulink block, which was used to replace the MPC block. The angle outputs and control effort were saved in the workspace for further data processing.
To determine which number of neurons has better performance, further calculations in relative error against MPC and against reference were implemented by using the data saved in the workspace.
4. Results
Overall, from comparing data generated in Simulink, although there are some differences between machine learning and MPC, the Neural Network could approximate the MPC to a great extent. However, not all four tested numbers of neurons are appropriate for the final design. There was a fluctuating trend in error as the number of neurons was increased.
Figure 1: Error against MPC versus time for different tests
In Figure 1, it shows how relative error against MPC model changes versus time for four tests. Here the interest mainly focuses on vertical comparison, which is the difference of errors between different numbers of neurons, since the goal is to find the most suitable number of neurons in the same condition. It can be seen from the values on vertical axis that tests with 15 neurons and 25 neurons have higher relative error than 30 neurons and 40 neurons, which means the latter two could be chosen for a final implementation. The choice between 30 neurons and 40 neurons was not intuitive since 30 neurons has relatively small error from T = 0 to T = 10, while 40 neurons have relatively small error in the rest of the time. Therefore, the error of angle outputs was calculated.
In Figure 2 (a), it shows the absolute angle outputs error against reference for 15 neurons, 25 neurons, 30 neurons, and 40 neurons. The Figure 2 (b) shows the error of neuron network result against reference. As can be reasonable expected, the 30-neuron network has the least error of the tested architectures, and as a result, the 30-neurons Neural Network block was used in the final Simulink model to test the performance compared with MPC model.
Figure 3: Plot of comparison of MPC and Neural Network in same plant.
In Figure 3, it shows the output from original MPC and the one from the system with implementation of Neural Networks. The horizontal axis refers to the time and vertical axis refers to the output voltage. The orange line is the original output of the MPC model, whereas the blue line is result coming after the 30-neuron Neural Network block. Qualitatively, the result of the Neural Network matches MPC model to a great extent.
5. Discussion
Figure 2 gives a brief illustration on how error changes as the number of neurons increases. Since there are only four different numbers of neurons tested, the overall trend could not be fully explained. 15-neuron and 25-neuron Neural Network have larger error than 30-neuron Neural Network, while 30-neuron has less error than 40-neuron Neural Network. However, changing the number of neurons does affect the voltage output and the relative error between the original MPC model and the one with Neural Network-based approximation. Therefore, to find a suitable number of neurons is a trial-and-error task. If appropriate number of neurons is not selected, model can be overfitting and these lead to wrong results. This means that the Neural Network model gives better result at and near states and conditions associated with training examples, but it may give worse results farther away from
such points. In the research done by M. Yilmaz and E. Arslan [6], the authors document a situation similar to the one explored in this paper, where the appropriate number of neurons used in their research was below 30, and the output of their model was overfitting when the number of neurons is selected larger than 30. The appropriate number of neurons is application dependent and is based on a tradeoff between training complexity, on-line complexity, and achieved error performance. For this application, Neural Network-based approximation towards MPC is feasible since the error between original and tested one is small enough to accept.
In Figure 3, the control effort of MPC (blue line) and machine learning (orange line) are exhibited. We can clearly conclude that the output voltage of MPC system and the system with implementation of Neural Networks are approximately in a same trace, while the latter running much faster than MPC. Due to the limitation of computer memory, higher neuron tests are not implemented, but this does not imply that higher neuron performs worse. The performance is expected to be improved further at a specific number of neurons, but this claim must be tested with more accurate experiments to draw a conclusion.
Furthermore, determining the range and interval of six input variables during data process still has some scope to develop. For example, the range of angle speed may vary between some values which are based on the output of neural network. One could plot the variation of this variable when using neural network to better understand the maximum and minimum value on the plot, and then redefine the range to obtain a good training sample. As for the intervals between training examples in the input space for the neural network, decreasing it means greater numbers of training examples, which could be beneficial for neural network training. In this work, we chose a relatively large interval to perform the proof of concept, but this may have been a suboptimal set of training examples. As a result, in future research, it will be important to study the effect of sampling techniques in the state and input space to the MPC to improve the training data.
6. Conclusion
Above all, the approximation of MPC via Neural Network is feasible, and its performance depends on the range of data set and the number of hidden layers. The Neural Network generates an acceptable result compared to original MPC model while shortening a great amount of computation time. For further MPC applications in industries, neural network-based approximation could decrease real-time cost in the process of dynamic controls.
7. References
[1] S. Paternain, M. Morari and A. Ribeiro, Real-Time Model Predictive Control Based on Prediction-Correction Algorithms, 2019 IEEE 58th Conference on Decision and Control (CDC), Nice, France, 2019, pp. 5285-5291, doi: 10.1109/CDC40024.2019.9029408. [2] J. Nubert, J. Köhler, V. Berenz, F. Allgöwer, S. Trimpe, Safe and Fast Tracking on a Robot Manipulator: Robust MPC and Neural Network Control (v2), 2020. [3] S. Chen et al., Approximating Explicit Model Predictive Control Using Constrained Neural Networks, 2018 Annual American Control Conference (ACC), Milwaukee, WI, 2018, pp. 1520-1527, doi: 10.23919/ACC.2018.8431275. [4] MATLAB and Model Predictive Control Toolbox Release 2020b, The Mathworks, Inc., Natick, Massachusetts, United States. [5] K. Gnana, S. N. Deepa, Review on Methods to Fix Number of Hidden Neurons in Neurons, 2013. [6] M. Yilmaz, E. Arslan, Effect of increasing number of neurons using artificial neural network to estimate geoid heights, January 10, 2011.