Open access peer-reviewed chapter

Auto-Tuning PID Controller Based on Genetic Algorithm

Written By

Rodrigo de Figueiredo, Bruno Toso and Jean Schmith

Submitted: 26 December 2022 Reviewed: 23 January 2023 Published: 21 February 2023

DOI: 10.5772/intechopen.110143

From the Edited Volume

Disturbance Rejection Control

Edited by Mohammad Shamsuzzoha and G. Lloyds Raja

Chapter metrics overview

126 Chapter Downloads

View Full Metrics

Abstract

The PID controller is widely used in industry and its tuning is always a concern for the plant stabilization. Several methods for auto-tuning the PID have been proposed over the years, however, the relay method is the most used even though this method may determine nonideal PID gains and cause some physical stress on the plant. Here is presented a proposal for an auto-tuning PID controller based on a genetic algorithm. Genetic algorithm is a well-known method that imitates the natural selection process in order to obtain approximate solutions to optimization problems. Here, the method is presented in underdamped plants with the hypothesis that any plant can be approximated to a second-order function. From the unit step response of the system, the maximum overshoot and peak time were used in the GA evolution to obtain optimal PID parameters. The system was tested with a set of parameters and compared to MATLAB PID tuner function. Using the rising time and the settling time of unit step response from the closed loop system as validation parameters, the GA presented better results than the MATLAB tuner for most cases.

Keywords

  • auto-tuning PID
  • genetic algorithm
  • artificial intelligence
  • PID controller
  • underdamped second order plants

1. Introduction

The PID (Proportional–Integral–Derivative) controller is widely used in industry for process control and robotics. The auto-tuning is an important feature embedded in some commercial PID controllers. This feature is responsible for tuning the PID controller by using the plant’s unit step response and changing the Kp, Ki e Kd gains in order to obtain the plant stability [1, 2, 3]. The performance characteristics of a control system are often specified in terms of the transient response to unit step input. The transient response of a stable physical system frequently presents damped oscillations before achieving its steady state. The specification of the transient-response characteristics of a control system to unit step input is given by the determination of the Td delay time, Tr rise time, Tp peak time, Mp maximum overshoot, and Ts settling time.

Figure 1 presents a typical unit step response from a second-order system with the parameters indication. The Td represents the time from zero until the amplitude of the response reaches 0.5, the Tr is the time to the response to reach the amplitude of 1.0, and the Tp is the time to the response to reach the maximum overshoot Mp. At last, but not the least, the Ts is the time to the response to achieve the steady state condition. It is noteworthy that Ts depends on the chosen allowable oscillation tolerance in a steady-state condition. Although the parameters were presented for an under-dumped example, they are applicable to critically damped and over damped, as well. Therefore, the same procedure may be applied to any second-order plant [4, 5].

Figure 1.

Unit step response of a second-order plant with the parameters Td, Tr, Tp, Ts, and Mp indication.

The PID controllers are tuned by the Kp proportional, Ki integral, and Kd derivative gains and are directly responsible for the system stability. A well-tuned PID controller works to decrease the oscillation in the system. The stability of the system may impact directly the productivity of a manufacturing process or the precision of a robot, for example. Thus, the tuning and auto-tuning methods are important, as evidenced by works [2, 6].

There are well-established auto-tuning algorithms that implement the relay and Ziegler-Nichols methods [7]. The Ziegler-Nichols method requires the parameters from the system in an oscillatory fashion to obtain the critic Ku gain and the oscillation period Tu to compute the PID gains. However, this procedure may cause some stress on the plant. To avoid that issue, the relay method is an alternative to the parameter extraction procedure. This method is based on restricting the controller’s output in order to create controlled oscillation on the plant. The procedure yields the same two parameters obtained from the previously mentioned method and used to obtain the PID gains. It consists of replacing the controller with a relay, which operates with a hysteresis and limited output. Although the relay method may be less stressful to the system, oscillatory behavior is still needed for a certain amount of time, which may be impractical for certain plants [8].

Another approach is the usage of artificial intelligence [9]. Applications using Fuzzy Logic [10] for PID tuning are based on a predetermined expert system, which uses a rule table for each of the controller parameters. By using this set of rules, it was possible to reach a satisfactory result. Other works using fuzzy [11, 12, 13] and flower pollination algorithms [14] presented good results for obtaining the PID parameters. The point here is that auto-tuning of PID controllers using artificial intelligence is a possibility.

The artificial neural network (ANN) has the disadvantage in the need of a large quantity of data from the plant. Whereas, the use of genetic algorithm (GA) uses only the unit step response parameters. The GA is able to produce better results than Ziegler-Nichols in terms of performance [15, 16]. Therefore, this work proposes the usage of GA for tuning the values of Kp, Ki, and Kd gains from the unit step parameters Mp and Ts. The novelty here is the usage of a single-unit step response to the closed system for the PID tuning.

This method allows the tuning of the PID controller with minimal physical plant stress. The method allows the parameter computation from any physical plant of unknown mathematical model since the idea is the approximation to a second-order function.

Advertisement

2. Methodology

The proposed system uses the extraction of temporal parameters from the plant unit step response. The method uses the extracted temporal data to apply it to a transfer function. This transfer function (second-order mathematical model) was used by the GA to validate the parameters Kp, Ki, and Kd and its result is compared with an ideal one, which is a function with a stable response in the set point, low overshoot, and low ripple. Figure 2 presents the block diagram for the proposed system.

Figure 2.

Block diagram of the proposed method.

A unit step signal is applied to the plant. Next, from the unit step response of the plant is possible to obtain the peak time Tp and maximum overshoot . For the GA design, the maximum ripple tolerance in steady state condition assumed for Ts determination was 0.5%. This 0.5% ripple is, on purpose, a restricted value in relation to the values assumed in control plants for regulatory response [17, 18, 19]. Further, the damping factor ξ and the undamped natural frequency ωn are computed by Eqs. (1) and (2), respectively.

ξ=logMPπ21+logMPπ2E1
ωn=πTP.1ξ2E2

Hence, the idea is to approximate any plant to a second-order system. By the ωn and ξ computation it is possible to determine the Laplace transformation of an approximate second-order transfer function as presented in Eq. (3), where s denotes the Laplace variable.

Hs=ωn2s2+2ξωns+ωn2E3

The PID controller is determined by Eq. (4).

GS=Kp+Kis+KdsE4

The feedback model of the system yields Eq. (5).

YsXs=GsH1+GsHE5

At this point, the control structure is established. Now the question is how to determine the parameters to improve the Gs to produce a stable system. Again, the unit step signal is applied to the closed system. From the feedback model, the inverse Laplace transform was computed to obtain the unit step response of the controlled system. The error was computed by Eq. (6), where y is the desired output and a0 is the output of the controlled system. The brackets denote the discrete form of the signal.

ξ=i=0nyia0i2E6

The ideal desired output yt is computed by Eq. (7), in order to obtain a response approximated to a Heaviside function stable in the set point with low overshoot and low ripple.

yt=1e100.TP.tE7

This error was used to improve the GA algorithm that computes new values for Kp, Ki, and Kd to achieve a stable output to the system. With this system evaluating the plant has minimal physical stress. The PID tuning was given by the GA evolution.

The genetic algorithm is a method to seek approximate solutions to optimization problems. The main idea is to look for better solutions from a population of abstract solution representations. The evolution starts with a random population to form the generation, in each generation, each solution is evaluated, some are selected, some are discarded, and some are recombined or mutated to form the next generation. The next generation is used in the next interaction of the algorithm.

In the presented method, the parameters to be tuned in the PID are the Kp proportional, Ki integrative, and Kd derivative gains. Therefore, the GA genome is created with the PID gains as its chromosomes. The chromosomes are the elements that evolve through the GA process. The GA genome is formed by the parameters Kp, Ki, and Kd, as floating-point chromosomes. There was the possibility of establishing limits in variation of values of each chromosome of the genome, however, this practice limits the evolutionary capacity of the GA. Here it was decided not to create this limit and to work only on the hyperparameters of the GA. In this way, there is an evolutionary freedom of the parameters Kp, Ki, and Kd, not limiting the exploration.

The GA optimal hyperparameters were defined after testing. In these tests, the hyperparameters were varied individually over a well-known plant (a classic underdamped system of second order). We used some different plants to realize these tests and validate the system. Their step response was generated using MATLAB and fed into the system in order to analyze different overshoot levels. With these tests, the optimum hyperparameters were a population with 100 individuals (genomes), 50 generations (50 times that the GA has the opportunity to evolve), and a mutation chance of 6% (a random factor responsible to avoid locals optimum).

Advertisement

3. Discussion and results

In order to check the effectiveness of the proposed method for PID tuning, we compared the tuning capability with the pidtune function from MATLAB, which is a well-known tool for mathematics and very robust for control analysis. Our method was developed in MATLAB, as well, for a fair comparison.

Table 1 presents the results for the MATLAB pintune and the proposed GA method for a second-order plant with different values of ξ and ωn. The chosen values for ξ were 0.1, 0.3, 0.6, and 0.9. For each ξ, the frequencies of 2 and 10 rad/s were used as ωn. A steady-state error for all numerical experiments was not observed. The performance of each system was compared in terms of rising time Tr and settling time Ts.

ξωn (rad/s)MATLABGAMATLABGAMATLABGAMATLABGAMATLABGA
KPKPKIKIKDKDtr (ms)tr (ms)ts (ms)ts (ms)
0.1224.2024.44511.10098.86513.10039.78241.014.461.024.2
101.051.0000.5467.6910.5071.00070.025.011200.0230.0
0.3224.2059.65611.10099.49413.10039.94243.015.068.024.0
103.163.5054.9000.3620.5090.33267.064.01980.029600.0
0.6231.6099.08319.00099.75213.10047.50144.012.076.021.0
106.311.00019.40013.8330.5141.00048.0571.0631.02420.0
0.9247.3099.81642.60099.97413.10080.82044.07.075.013.0
109.479.85842.90099.3100.5251.00045.031.087.0215.0

Table 1.

Performance comparison between the results obtained by MATLAB pidtune and the proposed genetic algorithm. In bold are highlighted the better results for each parameter.

Observing the Tr and Ts, in the most cases the proposed GA method reached better results than the MATLAB function. Considering the rising time Tr, the only situation that the MATLAB function presented a better result than GA was with ξ = 0, 6 and ωn = 10 rad/s. In the case of Ts, the MATLAB achieved better results only in three situations, with ξ = 0.3, 0.6, and 0.9, in cases with ωn = 10 rad/s. One might note that the situations that the GA did not achieve better results than the MATLAB function were with ωn = 10 rad/s. This behavior may be explained by the chosen yt function and the higher oscillatory aspect of the plant unit step response, which yields a higher error and, therefore, an additional difficulty to the GA correction of the Kp, Ki, and Kd gains.

Figure 3 presents the unit step response of the second order plant and the closed loop with the MATLAB function and the GA method with ξ = 0.1 and ωn = 2 and 10 rad/s. One might note that we tacitly changed the scale of the graphics in order to present the most interesting behavior on each one. Note the better performance of the GA method against the MATLAB function. For the MATLAB function, ξ = 0.1 and ωn = 2 rad/s, it was observed a maximum overshoot of 2%, for the other closed-loop systems with MATLAB function computations there was no overshoot.

Figure 3.

Unit step response for ξ = 0.1 and (a) = 2 rad/s and (b) ωn = 10 rad/s.

Figure 4 presents the results for ξ = 0.3 and ωn = 2 and 10 rad/s. Note the worst results of GA for ωn = 10 rad/s, as discussed before, taking a long period to achieve the stability. On the other hand, for ωn = 2 rad/s, the GA method presented better results.

Figure 4.

Unit step response for ξ = 0.3 and (a) = 2 rad/s and (b) ωn = 10 rad/s.

Figure 5 presented the results for ξ = 0.6 and ωn = 2 and 10 rad/s. For ωn = 2 rad/s, the GA method achieved better results and for ωn = 10 rad/s the MATLAB function performed better. For ωn = 10 rad/s the GA method presented an overshoot of 8%.

Figure 5.

Unit step response for ξ = 0.6 and (a) = 2 rad/s and (b) ωn = 10 rad/s.

Finally, Figure 6 presents the results for ξ = 0.9 and ωn = 2 and 10 rad/s. Note, again, that for ωn = 2 rad/s, the GA method presented better results than the MATLAB function, although, for ωn = 10 rad/s, the MATLAB function presented better results. For ωn = 10 rad/s, the GA presented an overshoot of 2%. For the other commented closed-loop systems with GA computation, there were no overshoots.

Figure 6.

Unit step response for ξ = 0.9 and (a) = 2 rad/s and (b) ωn = 10 rad/s.

It was possible to observe that both techniques eliminated the overshoot and searched for the smallest rising time Tr, which are good features for a tuning system. As aforementioned, the GA method presented better results for the most cases and the cases that the MATLAB pidtune function presented better results were with higher oscillations of the plant unit step response, in which, with a better choice of yt may mitigate this issue. The MATLAB function uses all available knowledge about control systems in order to provide optimal PID parameters, in addition to rising time Tr, settling time Ts, and overshoot Mp, it also uses stability and disturbance robustness. The GA proposed method uses only the error computation to compare the obtained response of the chromosome with an ideal unit step response. Therefore, the MATLAB function requires prior knowledge to configure the pidtune and the idea of the method proposed in this article is to depend as little as possible on the user’s knowledge and avoid the stress of the plant.

Hence, the proposed method was developed to obtain the better performance in terms of Tr, Ts, and Mp. The disturbance robustness and other important features were not considered. The GA method presented good results in most cases, and it is possible to reach better results by adjusting the yt function in order to consider more characteristics of the plant.

Advertisement

4. Conclusion

The presented work proposed a method for auto-tuning PID controllers using genetic algorithm. The method was applied to different parameters of a second order plant and compared to the MATLAB pidtune function. The GA method presented better results than MATLAB function for the most cases. The cases in that GA had a poor result were with high oscillations in unit step response of the plant. The explanation may the choice of the simple error function, thus a more sophisticated and complete error determination shall be studied. Although the advantage of the proposed GA method is that any prior knowledge of control system is not necessary to avoid complex analysis of high-order mathematical models.

Advertisement

Acknowledgments

The authors are grateful for the technical and financial support of UniRV (Rio Verde University), which made the publication of this book chapter possible. They also thank IntechOpen for the opportunity to share their studies and knowledge with other researchers.

Advertisement

Conflict of interest

The authors declare no conflict of interest.

References

  1. 1. Blondin MJ, Sanchis Sáez J, Pardalos PM. Control Engineering from Classical to Intelligent Control Theory—An Overview. In: Blondin M, Pardalos P, Sanchis Sáez J, editors. Computational Intelligence and Optimization Methods for Control Engineering. Springer Optimization and Its Applications. Vol. 150. Cham: Springer; 2019. DOI: 10.1007/978-3-030-25446-9_1
  2. 2. Borase RP, Maghade D, Sondkar S, Pawar S. A review of pid control, tuning methods and applications. International Journal of Dynamics and Control. 2021;9(2):818-827
  3. 3. Lloyds Raja G, Ali A. New pi-pd controller design strategy for industrial unstable and integrating processes with dead time and inverse response. Journal of Control, Automation and Electrical Systems. 2021;32(2):266-280
  4. 4. Castellanos-C’ardenas D, Castrill’on F, V’asquez RE, Smith C. Pid tuning method based on imc for inverse-response second-order plus dead time processes. PRO. 2020;8(9):1183
  5. 5. Nguyen NH, Nguyen PD. Overshoot and settling time assignment with pid for first-order and second-order systems. IET Control Theory & Applications. 2018;12(17):2407-2416
  6. 6. Somefun OA, Akingbade K, Dahunsi F. The dilemma of pid tuning. Annual Reviews in Control. 2021;52:65-74
  7. 7. Patel VV. Ziegler-Nichols tuning method. Resonance. 2020;25(10):1385-1397
  8. 8. Aisuwarya R, Hidayati Y. Implementation of Ziegler-Nichols PID Tuning Method on Stabilizing Temperature of Hot-water Dispenser. In: 2019 16th International Conference on Quality in Research (QIR): International Symposium on Electrical and Computer Engineering, Padang, Indonesia. 2019. pp. 1-5. DOI: 10.1109/QIR.2019.8898259
  9. 9. Ekinci S, Hekimoğlu B, Kaya S. Tuning of PID Controller for AVR System Using Salp Swarm Algorithm. In: 2018 International Conference on Artificial Intelligence and Data Processing (IDAP), Malatya, Turkey. 2018. pp. 1-6. DOI: 10.1109/IDAP.2018.8620809
  10. 10. Senthil Kumar S, Anitha G. A novel self-tuning fuzzy logic-based PID controllers for two-axis gimbal stabilization in a missile seeker. International Journal of Aerospace Engineering. 2021:1-12
  11. 11. Anand A, Aryan P, Kumari N, Raja GL. Type-2 fuzzy-based branched controller tuned using arithmetic optimizer for load frequency control. Energy Sources, Part A: Recovery, Utilization, and Environmental Effects. 2022;44(2):4575-4596
  12. 12. El-Samahy AA, Shamseldin MA. Brushless dc motor tracking control using self-tuning fuzzy pid control and model reference adaptive control. Ain Shams Engineering Journal. 2018;9(3):341-352
  13. 13. Somwanshi D, Bundele M, Kumar G, Parashar G. Comparison of fuzzy-pid and pid controller for speed control of dc motor using labview. Procedia Computer Science. 2019;152:252-260
  14. 14. Potnuru D, Mary KA, Babu CS. Experimental implementation of flower pollination algorithm for speed controller of a bldc motor. Ain Shams Engineering Journal. 2019;10(2):287-295
  15. 15. Bari S, Zehra Hamdani SS, Khan HU, Rehman Mu, Khan H. Artificial Neural Network Based Self-Tuned PID Controller for Flight Control of Quadcopter. In: 2019 International Conference on Engineering and Emerging Technologies (ICEET), Lahore, Pakistan. 2019. pp. 1-5. DOI: 10.1109/CEET1.2019.8711864
  16. 16. Rodr’ıguez-Abreo O, Rodr’ıguez-Res’endiz J, Fuentes-Silva C, Hern’andez-Alvarado R, Falc’on MDCPT. Self-tuning neural network pid with dynamic response control. IEEE Access. 2021;9:65206-65215
  17. 17. Kumar D, Aryan P, Raja GL. Design of a novel fractionalorder internal model controller-based smith predictor for integrating processes with large dead-time. Asia-Pacific Journal of Chemical Engineering. 2022;17(1):e2724
  18. 18. Kumari S, Aryan P, Raja GL. Design and simulation of a novel foimc-pd/p double-loop control structure for cstrs and bioreactors. International Journal of Chemical Reactor Engineering. 2021;19(12):1287-1303
  19. 19. Mukherjee D, Raja G, Kundu P. Optimal fractional order imcbased series cascade control strategy with dead-time compensator for unstable processes. Journal of Control, Automation and Electrical Systems. 2021;32(1):30-41

Written By

Rodrigo de Figueiredo, Bruno Toso and Jean Schmith

Submitted: 26 December 2022 Reviewed: 23 January 2023 Published: 21 February 2023