Sliding Mode Control of A Servo System in LabVIEW
Sliding Mode Control of A Servo System in LabVIEW
ABSTRACT
The main contribution of this paper is to present the efficiency of LabVIEW in simulating and con-
trolling a servo system with conventional methods (PI and PID control), as well as sliding mode control
(SMC). The control of an actual system with LabVIEW and NI hardware provides an efficient
ORIGINAL RESEARCH implementation platform, using both LabVIEW’s graphical programming and the text-based m-file
PAPER language MathScript RT. Both programming environments and the connection to NI hardware are
relatively easy to use, therefore, ideal for education. The graphical “coding” can help novice users to see
through their algorithms. However, the mathematical background of sliding mode control is difficult
compared to conventional PID control; the SMC implementation for practical uses can be quite simple,
as the presented example demonstrates. The first didactic step is a simulation with the Control Design
and Simulation, as well as MathScript RT Modules. Then a myRIO Student Embedded Device is used to
control a real servo system. LabVIEW code can be compiled to run on computers, (soft) real-time
targets, and FPGAs (hard real-time targets), so students can easily and quickly step up to real industrial
measurement and control problems without the need to learn new programming environments.
KEYWORDS
DC servo motor, PI and PID control, sliding mode control, simulation, real-world system, measurement, LabVIEW,
education
1. INTRODUCTION
Simulating control systems helps students understand control methods better than written
textbook examples. The ability to experiment with the effects of different control strategies on
real-world processes is even more helpful. Conventional PID control is part of the control
engineering curriculum for bachelor-level courses. However, the more robust but mathe-
matically far more challenging sliding mode control is usually introduced later in graduate
studies.
Permanent-magnet brushed DC motors, and servo drives are widespread in industry and
DIY home projects, ranging from low-power versions to vehicle drive systems. Both speed
and position control are possible with a wide range of controllers, with the most common
control method being PI or PID [1, 2]. PI and PID control usually satisfies the most common
requirements. However, when the system has a variable load, rather than nominal ones, using
a PI or PID controller does not result in a fast and stable output voltage response.
Another possible method is sliding mode control (SMC). Because of the switching
p behaviour of sliding mode control, it is commonly used in power electronics [3–5].
Corresponding author.
E-mail: [email protected] SMC is usually referred to as an interesting theory, as the mathematical model itself works
very well on a theoretical level, but implementation can be a significant challenge. In the
literature, some hybrid solutions are reported to overcome this problem [3, 6].
The project aims to implement PI, PID, and SMC control of a DC servo system, both as a
simulation and real-world measurement. This simple system can be used as a teaching tool.
The chosen programming environment is National In- The output of the proportional term is proportional to the
struments (NI) LabVIEW, a graphical programming envi- error signal, the integrating term is proportional to the integral
ronment with excellent hardware connections to real-world of the error signal, and the derivative term is proportional to
processes. LabVIEW programming is similar to drawing the the derivative of the error signal. As the gain of the propor-
algorithm’s block diagram with user interface elements tional member increases, the value of the control signal and
represented as nodes, programming structures such as loops, with it the error increase proportionally. The controller will try
and built-in functions and procedures. The Control Design to respond faster to the error signal, but at the same time, the
and Simulation Module consists of many VIs (Virtual In- overshoot will also increase. With the help of the integrating
struments, the name of LabVIEW subroutines) for control member, not only the rise time but also the steady-state error
theory applications, both in time- and frequency domain. can be reduced. The disadvantage is that it can slow down the
Simulation loops provide a graphical model definition, system and cause oscillations when the sign of the error signal
similar to the one in Simulink, and are used to the timestep changes because it may take some time to follow it. The output
by timestep simulation of various dynamical systems. The of the PI controller is described by Eq. (1).
MathScript RT Module is a text-based m-file programming Z t
environment incorporated into LabVIEW. MathScript can uðtÞ ¼ Kp $eðtÞ þ Ki $ eðτÞdτ (1)
be used as an individual application that functions similarly 0
to MATLAB. MathScript text-based codes can also be used Kp is the gain of the proportional term, e is the error signal
within a graphical LabVIEW program when inserted into a given by the difference between the setpoint (reference
so-called MathScript Node that acts as a VI. signal) and the process variable, Ki is the gain of the inte-
LabVIEW can interface with measurement and auto- grating term, and τ is the integration time.
mation products from various manufacturers, besides de- By adding a derivative term, the controller can predict the
vices from LabVIEW’s developer National Instruments. NI error in advance. It can be used to amplify the control signal
has specific hardware products for students, such as the while keeping the amplitude of the error relatively small. This
myRIO Student Embedded Device that was chosen for the will dampen the system and reduce overshoot while not
measurement and control of the real-world DC servo sys- affecting the steady-state error. The output of a complete PID
tem. The servo system was first simulated in LabVIEW. PI, controller supplemented with a derivative term is described
PID, and SMC control methods were programmed in Lab- by Eq. (2), where Kd is the gain of the derivative term.
VIEW/MathScript, and various experiments were performed Z t
deðtÞ
to evaluate the control strategies. Implementing the simu- uðtÞ ¼ Kp $eðtÞ þ Ki $ eðτÞdτ þ Kd $ (2)
lation and measurement setup is relatively simple; the pro- 0 dt
gramming environment is clear-cut and self-explaining. There are other mathematical representations of the PID-
LabVIEW does not require long to learn; therefore, it is controller’s transfer function; in LabVIEW the transfer
excellent for demonstrational purposes in higher-level edu- function version of Eq. (2) is called Parallel, with the
cation. There are even versions of LEGO robots, e.g. Ro- following parameters:
botics Invention System that shipped with a special 1
LabVIEW version. Further gain by using LabVIEW is that Kc þ þ Td s (3)
Ti s
the developed controller code can be compiled to run not
just on computers but (soft) real-time targets and FPGAs The other two formats are Academic:
(hard real-time targets). That way, students can easily and
1
quickly step up from computer simulation to real industrial Kc 1 þ þ Td s (4)
Ti s
measurement and control problems without the need to
learn new programming environments. and Series:
The presented example of the sliding mode control is far
1
from the complex industrial applications; however, the Kc 1 þ ð1 þ Td sÞ (5)
Ti s
measurement setup provides an excellent possibility to
introduce the basics of this control method with an existing The low-pass filter of the derivative term can be specified
physical system even for bachelor-level students. The DC- with the a parameter, in each representation, when appro-
motor system can further be used to test other control priate:
strategies both with the simulated and the actual process. 1
(6)
aTd s þ 1
2. PI AND PID CONTROLLERS
The PI or PID controller is the most used solution for con- 3. SLIDING MODE CONTROL
trolling the speed of motors. Their operation is based on error
signal compensation. They consist of a total of two or three Sliding mode control was developed in the Soviet Union pri-
parallelly connected terms whose initials give their name. P marily for aerospace and missile applications in the 1970s [7,
stands for proportional, I for integrating, and D for derivative. 8]. The mathematical basis of SMC design can be found in [9].
Table 1. Parameters of motors for the transfer function current value of the test signal, the motor speed, the current,
Parameter Test1 Test2 Test3 and the position is stored in the file after each iteration.
The simulation results obtained with each parameter are
Ra 2 0.6 1 shown in Fig. 3.
La 0.5 0.8 0.2
Kt 0.1 0.2 0.2
Kv 0.1 0.2 0.8 5. SIMULATION RESULTS
J 0.2 0.9 0.4
B 0.02 0.7 0.5
The controller parameters were determined with LabVIEW’s
Control Design and Simulation Module’s built-in tuning
integral of rotational speed and is not included in the blocks for the PI and PID controllers with the use of various
following transfer function): available tuning methods (ZN: Ziegler-Nichols, CC: Cohen-
Kt Coon, CHR: Chien-Hrones-Reswick, IMC: Internal Model
GðsÞ ¼ (13)
ðLs þ RÞðJs þ BÞ þ Kt Kv Control). The details of these tuning methods are available
in the official user manual and help.
Each parameter can be saved or loaded in XML format for
The controller parameters determined by Internal Model
the repeatability of the simulations. The XML file’s path can
Control are used, as this method gave the fastest operation,
be input via the program’s user interface or hard-coded into
according to the simulation results. The parameters of the PI
the program. The parameters can be validated by pressing
and PID controllers are shown in Table 2.
the apply button.
The parameter values of the sliding mode controller are
The model’s correct behaviour can be tested with several
C 5 10, K 5 40 and d 5 0.05.
test functions available in LabVIEW, or the user can create an
own test VI. A function generator has been placed in the
5.1. Step function
program, which can be freely configured in the user interface
to create several general test signals. Configurable parameters The first test for each controller was a step function test in
are duty cycle, period, amplitude, and offset. An Express VI is which the speed setpoint jumped from 0 to 10 rad/s in the
also included in the program to save the simulation data to an first second of the simulation. The speed responses obtained
xlsx spreadsheet file. The current time of the simulation, the for this are summarized in Fig. 4.
5.2. Tracking
In this case, the initial value of the speed reference signal is
10 rad/s, and after the steady-state is reached, it is changed
abruptly to 5 rad/s in the fifth second. The comparison is
shown in Fig. 7. The results again reflect the difference
described in theory as in the previous case of the step Fig. 5. The control signal of different controllers
function. The sliding mode control was spectacularly better
in this study as well, as it was able to follow the change of the 5.3. Speed function
reference signal the fastest and to reach the new steady-state
asymptotically. The tracking results show similar perfor- In the case of the speed function, the result is similar to the
mance to step response results. Sliding mode control per- previous ones; the sliding mode controller performed best,
formed best; the undershoot and settling time of the loop as it was able to follow the signal almost perfectly in the case
with the PID controller were smaller than those of the one of the ideal motor model. The difference between PI and
with the PI controller. PID controllers is as expected from the theory. The response
5.5. Summary
Overall, similar results were obtained for all four test sce-
narios, according to which the sliding mode control produced
much better results at the brushed DC motor speed control.
The theoretical differences between the three different con-
trollers were also well visible in the simulations. By choosing
the appropriate parameters, it was possible to make the
Fig. 6. Error and derivative of the error
sliding mode controller work more efficiently than the PI and
PID controllers while also eliminating the chattering phe-
nomenon, which did not happen in any of the tests. The
summary of control performance indicators are shown in
Table 4 and 5. Smaller number means better control per-
formance. According to the results, the SMO has the best
control performance against PI and PID control laws.
Fig. 11. Part of the real-world DC-motor control LabVIEW Block Diagram
8. SUMMARY
Fig. 15. Comparison of controllers with sinusoidal test signal with
real motor
When comparing the results of the performed experiments,
the sliding mode control worked excellently in the case of the
ideal theoretical model. For all experiments, SMC was able to
7.2. Tracking follow the reference signal extremely well for both abrupt
In tracking the abrupt change of the reference signal. the changes and continuously changing signals. In the case of PI
PID controller performed surprisingly well with the pa- and PID controllers, there was a significant difference in the
rameters of the Internal Model Control method compared to parameters determined by different controller tuning
the other results. methods, although not all test signals gave the best results.
The sliding mode controller performed best, followed by With the real motor, the sliding mode controller no
the PID and then the PI in the last place. Table 9 shows the longer had a clear advantage. Although in cases where there
characteristics of the responses. was an abrupt change in the reference signal value it has
performed much better, in the case of continuously changing
signals such as the speed function or the sine signal it has
7.3. Speed function already lagged behind the other two controllers.
For the speed function test signal. the Ziegler-Nichols pa- Simulation is a very useful tool as students can check
rameters gave the best results for the PI and PID controllers. various controller parameter settings, comparing the results,
After the start. the error is roughly constant with the PI and, therefore, understand the role of the PID-controller’s
and PID controllers. while SMC’s error increases more and parts and their interaction. Experimenting with the tuning of
more with the increase of the input signal. The properties of a simulated control system often provides deeper knowledge
the response signals are shown in Table 10. than the use of controller tuning methods from textbooks
without understanding the underlying principles.
7.4. Sine signal The problems of saturation and integral windup usually
occur in real-world physical systems. There is an educational
In the case of the sinusoidal test signal, a better measure- value of showing these problems with relatively small-scale
ment result was obtained with the Cohen-Coon parameters real-world systems without the risk of serious damage, as
at least, however, this difference may also be due to the well as including the appropriate simulated versions beyond
measurement error mentioned earlier. the idealistic simulated system without considering satura-
tion and integral windup. The detailed discussion of satu-
Table 8. Results of step input tests ration and integral windup is going to be included in the
laboratory experiments’ handouts soon.
Rise time Settling Overshoot Undershoot The whole process of modelling the DC servo system,
Controller (s) time(s) (%) (%)
designing controllers and simulating the closed-loop control
PI 0.0005 0.0017 7.17 – system, and later performing experiments in a real-world
PID 0.0018 4.01 – – system based on the simulation results has a significant
SMC 0.0004 0.0006 – – educational value. Control engineering is considered a rather
Table 9. Results of tracking tests Table 11. Results of sine signal tests
Controller Settling time (s) Undershoot (%) Overshoot (%) Controller Average error (rad/s) Largest error (rad/s)
PI 0.0017 24.30 0.78 PI 16.60 26.66
PID 0.0009 4.40 – PID 11.42 18.47
SMC 0.0001 – – Sliding mode 89.81 149.15
difficult subject all over the world [16, 17]; therefore, it is well Electron., vol. 54, no. 3, pp. 1298–310, 2007. https://www.doi.org/
worth introducing the applications of the theory with exper- 10.1109/TIE.2007.893053.
iments like the one presented above. As the pandemic situa- [7] V. I. Utkin and K. D. Yang, “Methods for construction of
tion enforces distant education worldwide, the value and discontinuity planes in multidimensional variable structure sys-
importance of simulation increases. Students are not allowed tems,” Autom. Remote Control, vol. 39, no. 10, pp. 1466–70, 1979.
to participate in laboratory experiments, so the chance of using [8] K. D. Young, “Controller design for a manipulator using theory of
real-world devices is reduced. Educational devices, such as the variable structure systems,” IEEE Trans. Syst. Man. Cybernetics,
presented NI myRIO, offer the possibility of self-paced ex- vol. 8, no. 2, pp. 101–9, Feb. 1978, https://doi.org/10.1109/TSMC.
periments. especially when students can gain access to them by 1978.4309907.
borrowing or use via the Internet. The expansion of the pre- [9] K. Szell and P. Korondi, “Mathematical basis of sliding mode
sented system to Internet access is currently being investigated. control of an uninterruptible power supply,” Acta Polytech.
Hungarica., vol. 11, no. 3. 2014. https://doi.org/10.12700/aph.11.
03.2014.03.6.
ACKNOWLEDGEMENT [10] P. Korondi and H. Hashimoto, “Sliding mode design for motion
control,” in Applied Electromagnetics and Computational Tech-
This research was funded by TKS2020-NKA-04. Project no. nology II : Proceedings of the 5th Japan-Hungary Joint Seminar on
TKP2020-NKA-04 has been implemented with the support Applied Electromagnetics in Materials and Computational Tech-
provided from the National Research, Development and nology. IOS Press, 2000, pp. 221–32.
Innovation Fund of Hungary, financed under the 2020- [11] V. Utkin and H. Lee, “Chattering problem in sliding mode control
4.1.1-TKP2020 funding scheme. systems,” IFAC Proc. Volumes, vol. 39, no. 5, p. 1, 2006. https://
doi.org/10.3182/20060607-3-IT-3902.00003.
[12] P. Korondi, H. Hashimoto, and V. Utkin, “Discrete sliding mode
control of two mass system,” in 1995 Proceedings of the IEEE
REFERENCES International Symposium on Industrial Electronics, Athens,
Greece, vol. 1, 1995, pp. 338–43, https://doi.org/10.1109/ISIE.
[1] T. Wildi, Electrical Machines. Drives and Power Systems. Upper 1995.497019.
Saddle River. NJ. USA: Pearson Prentice Hall, 2006. [13] P. Korondi, H. Hashimoto, and V. Utkin, “Direct torsion control
[2] G. Sziebig, B. Takarics, and P. Korondi, “Control of an embedded of flexible shaft in an observer-based discrete-time sliding mode,”
system via Internet,” IEEE Trans. Ind. Electron., vol. 57, no. 10, pp. IEEE Trans. Ind. Electron., vol. 45, no. 2, pp. 291–6, April 1998,
3324–33, Oct. 2010, https://doi.org/10.1109/TIE.2010.2041132. https://doi.org/10.1109/41.681228.
[3] K. Al-Hosani, A. Malinin, and V. I. Utkin, “Sliding mode PID [14] H. Maghfiroh, A. Sujono, M. Ahmad, A. Brillianto, and H.
control of buck converters,” in 2009 European Control Conference Chico, “Basic tutorial on sliding mode control in speed control
(ECC), Budapest, 2009, pp. 2740–4, https://doi.org/10.23919/ECC. of DC-motor,” J. Electr. Electron. Inf. Commun. Technol., vol. 2,
2009.7074821. no. 1, pp. 1–4, 2020. https://www.doi.org/10.20961/jeeict.2.1.
[4] P. Korondi and H. Hashimoto, “Park vector based sliding mode 41354.
control of UPS with unbalanced and nonlinear load,” in Variable [15] E. H. Dursu and A. Durdu, “Speed control of a DC motor with
Structure Systems. Sliding Mode and Nonlinear Control, K D. Young variable load using sliding mode control,” Int. J. Comput. Electr.
and U. € uner, Eds., London. UK: Springer, 1999, pp. 193–209.
€ Ozg€ Eng., vol. 8, no. 3, pp. 219–26, 2016. https://www.doi.org/10.
[5] P. Korondi, S. H. Yang, H. Hashimoto, and F. Harashima, “Sliding 17706/IJCEE.2016.8.3.219-226.
mode controller for Parallel resonant dual converters,” J. Circuits. [16] P. Albertos and I. Mareels, Feedback and Control for Everyone.
Syst. Comput., vol. 5, no. 4, pp. 735–46, 1995. https://doi.org/10. Berlin, Heidelberg, Germany: Springer, 2010.
1142/S0218126695000424. [17] K. Zenger, “Control engineering. system theory and mathematics:
[6] R. E. Precup, S. Preitl, and P. Korondi, “Fuzzy controllers with the teacher’s challenge,” Eur. J. Eng. Edu., vol. 32, no. 6, pp. 687–94,
maximum sensitivity for servosystems,” IEEE Trans. Ind. 2007. https://doi.org/10.1080/03043790701520719.
Open Access. This is an open-access article distributed under the terms of the Creative Commons Attribution 4.0 International License (https://creativecommons.org/
licenses/by/4.0/), which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited, a link to the CC
License is provided, and changes – if any – are indicated. (SID_1)