Swarm-Based Design of Proportional Integral and Derivative Controllers Using a Compromise Cost Function: An Arduino Temperature Laboratory Case Study

: Simple and easy to use methods are of great practical demand in the design of Proportional, Integral, and Derivative (PID) controllers. Controller design criteria are to achieve a good set-point tracking and disturbance rejection with minimal actuator variation. Achieving satisfactory trade-offs between these performance criteria is not easily accomplished with classical tuning methods. A particle swarm optimization technique is proposed to design PID controllers. The design method minimizes a compromise cost function based on both the integral absolute error and control signal total variation criteria. The proposed technique is tested on an Arduino-based Temperature Control Laboratory (TCLab) and compared with the Grey Wolf Optimization algorithm. Both TCLab simulation and physical data show that satisfactory trade-offs between the performance and control effort are enabled with the proposed technique.


Introduction
Despite the development of more refined control techniques, the Proportional, Integral, and Derivative (PID) control continues to be ubiquitous for industrial control [1,2]. Given the practical relevance of this type of control, many design methods have been proposed since the pioneering work developed by Ziegler and Nichols [3]. PID tuning rules were developed for specific aspects, such as: Control modes (P, PI, PD, or PID); types of system model characteristics or forms (first order plus time delay, second order plus time delay, non-minimum phase, oscillatory, etc.); PID controller structure (parallel, series, with filters, with two-degrees of freedom, etc.); and anti-windup schemes [4][5][6][7]. The PID control practical relevance also motivates inclusion in most introductory feedback control courses, for example [8].
A commonly used argument against using bio-inspired and nature inspired metaheuristics over classical PID design methods is that these also require the adjustment of parameters prior to the optimization procedure. An advantage of the classical PSO algorithm is fewer adjustable heuristic settings compared with the basic GA. Moreover, PSO is more straightforward to implement than a GA. As the proposed technique aims to be simple to configure, the PSO algorithm is the selected optimization tool used in this study. Moreover, the proposed technique control performance is compared with a more recently introduced metaheuristic: The Grey Wolf Optimization proposed by [18].
There is an increasing pedagogical and research benchmark interest in pocket-sized and portable-based control experiments, as revealed by the following examples in [29][30][31][32][33][34]. Microcontrollers enable a wide range of pocket-size laboratories as common tools both for teaching/learning purposes, as well as for control engineering practitioners testing controller designs. The paradigm is shifting from monolithic laboratory experiments that require significant resources to take-home and modular experiments. The Temperature Control Laboratory (TCLab) proposed by [35][36][37][38] is used to teach PID control to undergraduate engineering students [39,40]. The TCLab is a low-cost Arduino-based lab which is a pocket-sized, plug-and-play kit, meaning that it does not require the user to perform the assembly. This is quite advantageous for computer-based control courses in which the primary goal is to test the identification and control techniques rather than hardware assembly. The TCLab is programmed using different environments, such as: Python, MATLAB ® /SIMULINK ® , and GNU Octave. Moreover, a wide range of open-source supporting materials, including programs, videos, and tutorials are freely available in [24].
The PSO was applied to identify a first order plus time delay model for the TCLab kit in [39,40]. In this paper, the PSO design of PID controllers based on an additive compromise cost function involving the Integral Absolute Error (IAE) and Total Variation (TV) is proposed. This technique is validated both with simulation and practical results obtained with the TCLab. The results obtained with the proposed technique are compared with the ones obtained with the GWO algorithm and classical tuning techniques. The novel contributions of this paper are highlighted in the following points: • New formulation for an additive compromise (or aggregated) cost function involving the Integral Absolute Error (IAE) and Total Variation (TV). Major control design criteria concern optimizing set-point tracking and disturbance rejection, while minimizing the control signal variation. This proposed technique significantly simplifies the PID controller design procedure combining these criteria into a single-objective optimization formulation. • PSO algorithm to design PID controllers that minimize a cost function weighting IAE and TV. A simple PSO algorithm constitutes an excellent design tool for the PID controller, with practical interest for control engineers. The proposed technique is compared with the original GWO algorithm, in a TCLab temperature control case study, providing a similar control performance.

•
Both the simulation and practical validation with TCLab tests, show an effectiveness to design PID controllers by softening the control signal.
The paper remainder is organized as follows: Section 2 introduces the problem statement. In Section 3, the classical particle swarm optimization algorithm is presented. Sections 4 and 5 discuss the TCLab main features and results. Finally, Section 6 provides the conclusions and recommendations for future work.

PID Control Design: Problem Statement
Consider a general block diagram representation of a closed-loop system in Figure 1, assuming the following representation where r is the reference input (set-point), y is the controlled output, e is the error signal, u is the control output, d1 is a load disturbance, d2 is an output disturbance, n is a noise signal, and Gc and Gp are the controller and process transfer functions. The ideal feedback control corresponds to obtaining the controlled output equal to the reference input independent of system disturbances. This ideal control is not possible in practice due to disturbances, measurement noise, actuator saturation, and a wide range of other physical limitations. With these limitations, the controlled output should attempt to follow the reference input (Set-Point Tracking, SPT), while rejecting the system disturbances (Disturbance Rejection, DR). In this work, it is assumed that a dynamic model of the system can be identified. In addition to the SPT and DR criteria, it is also important to consider the control effort in the controller design. A relevant research question is: How can a PID controller be designed to achieve the best possible set-point performance while minimizing the control effort?
There are many time-domain criteria to evaluate a controller performance. These criteria frequently involve set-point step responses with the smallest possible values for first overshoot and rise time. An indirect approach to simultaneously minimize several step response indices is using error-based criteria. The most common are the following: Integral of Square Error (ISE), Integral of Absolute Error (IAE), Integral of Time Weighted Absolute Error (ITAE), and Integral Weighted Square Error (ITSE), represented respectively by the following expressions: with tsim representing the simulation time, which should be large enough so that the system-controlled output reaches the steady-state value. Depending on which of these criteria is adopted in the optimization cost function, different PID controller settings are obtained. Among these criteria the most widely used are the ISE, IAE, and ITAE. Time weighting the absolute error penalizes the error as time increases for ITAE, promoting the elimination of small steady-state errors. IAE independently gives the same relevance to errors over time. For this reason, IAE is adopted in this study. A common criterion to measure the control effort is: with u representing the control signal. The control signal smoothness can be evaluated using a Total Variation (TV) index (6), approximated by (7): with h representing the measurement sampling interval. The TV criterion is adopted in this study to minimize the control signal variation. It is worthwhile to mention at this point, that all actuators have physical limitations, and it is common that the control signal can vary linearly in the interval [umin,umax], with umin and umax representing the minimum and maximum control signal values, respectively. A realistic controller design for practical implementation should consider specific actuator saturation limits. Measurement noise issues are not addressed in this study.
With two performance criteria selected (IAE and TV), a decision regarding how to use these in the optimization algorithm must be made. The two criteria can be considered as two separate functions within a multi-objective (or many-objective) optimization problem and solved using a PSO Pareto-based approach [41]. However, depending on the number of objectives, the computational burden associated with multicriteria optimization can be significant. After a non-dominated Pareto front is achieved, a decision support system should be used to help the operator decide the appropriate trade-offs from the Pareto front. Considering that just two criteria are used (IAE and TV), a simpler approach uses an additive compromise cost function. This cost function is represented by: with α and β representing weighting factors determining the relative importance of each criterion.
An equivalent single parameter β could also be used if the α value is always fixed to a value of one as done in this paper.

Classical Particle Swarm Optimization
The particle swarm optimization algorithm proposed by Kennedy and Eberhart [13] is inspired by the animal swarms social behavior, such as bird flocks and fish schools. The basic notion of the algorithm can be explained using the illustrative example presented in Figure 2.
Particle swarm optimization algorithm: Position, velocity, and personal and global best variables data representation.
A swarm is represented with m particles. Each generic particle, i, has dynamics which are characterized by two d-dimension variables x and v, representing respectively, the particle position in space and the corresponding velocity. The swarm is randomly initialized in the search space unless there is specific information regarding the problem. The specific information can be incorporated in the initialization procedure to improve the convergence rate to an optimal solution. Each PSO iteration, t, updates every particle position to a new position. The update is from the sum of a velocity term according to (8) with the velocity evaluated using (9): where bi represents the best position obtained by particle i until the current iteration, t; g represents the best position from the full swarm (global best) or a specific neighborhood (local best). In this study, information is shared among the entire swarm (fully-connected model). As it can be observed from (9), the new velocity value is evaluated by a sum of three parts. The first part (ω v i (t)) is the inertia and considers the previous velocity value with a factor, ω, called inertia weight. The second part ( c 1 ϕ 1 b i tx i t ) represents the particle cognitive knowledge update. It is the difference between the particle i individual best position, bi, and the particle current position, xi, multiplied by a cognitive constant c1 and a disturbing random value, ϕ1. The third part ( c 2 ϕ 2 g t) − x i t) ) represents the particle social knowledge update: The difference between the swarm global best position, g, and the particle current position, xi, multiplied by a social constant c2 and a disturbing random value, ϕ2. The same relevance is usually given to the cognitive and social knowledge, and thus, c1 and c2 take the same value (e.g., 2 or 1.49445). The two random numbers, ϕ1 and ϕ2, are uniformly generated in the interval [0, 1]. Algorithm 1 is represented by the following pseudo-code: As it can be observed from the PSO pseudo-code, this algorithm is conceptually quite simple. Regarding the PSO algorithm parametrization, there are three adjustable parameters: The swarm size, m, the termination criterion and the inertia weight limits. While these parameters are problem dependent, they can easily be selected for most PID control design cases. The swarm size should be large enough to guarantee a diverse solution representation across the search space. The termination criterion is often a pre-defined number of iterations and is adopted in this study. Regarding the inertia weight, it is commonly accepted that it should assume a higher value at the beginning of the search (e.g., ωi = 0.7) and then gradually decreased over the search evolution until it reaches a minimum value (e.g., ωf = 0.4). This inertia weight variation is to establish an important trade-off between space exploration in an early search stage and gradually transition to a global minimum consensus in a final search stage. The inertia weight is linearly decayed between the maximum and minimum values over the search iterations. However, other approaches can also be used (e.g., see [42]).

Temperature Control Laboratory (TCLab)
The Temperature Control Laboratory (TCLab) is an Arduino-based kit developed by [35]. It comes with the hardware set presented in Figure 3: An Arduino Leonardo; a Printed Circuit Board (PCB) with two transistors acting as heaters, two thermistors to sense the temperature in each transistor casing, an Light Emmiting Diode (LED) to indicate when the system is hot, and a connection socket to power the PCB components (see the white USB adapter shown in Figure 3); and finally, a Universal Serial Bus (USB) cable connects the Arduino to a computer (see the blue cable shown in Figure 3). The TCLab is presented from another perspective in Figure 4. As it can be observed, the transistors (TIP31C) are the control system actuators and operate as temperature heaters (Q1 and Q2). Two TMP36 sensors measure the temperature in each transistor casing (T1 and T2). As it can also be observed from Figure 4, the two transistors are connected to heat sinks acting as heat dissipators. The sensors are glued to the transistor casings using a non-conductive epoxy containing a thermochromic paint. This paint changes color when the temperature rises above 37 °C. The TCLab can be programmed using MATLAB ® /SIMULINK ® , Python and GNU Octave, with a wide range of programs freely available in [22]. This study uses the MATLAB ® /SIMULINK ® connection. More information regarding TCLab can also be found in [35][36][37][38].

Designing PID controllers with the proposed PSO technique involves (a) identifying a First-Order Plus Time Delay (FOPTD) model using an open-loop step response, (b) based on the obtained model in (a)
, another PSO algorithm is used to tune the PID controller. These two steps are illustrated in Figure 5 with the TCLab system.

First-Order Plus Time Delay Model Identification
The first issue that must be addressed is to identify a dynamic model relating temperature measured in transistor 1 (T1) with the actuating heater signal (Q1). A FOPTD model was identified based on an open-loop step response using both the classical two-point and PSO optimization methods as proposed in [39,40]. The following PSO conditions were used in the model identification tests: • A swarm with size m = 40 particles.

•
Each simulation was run for 50 iterations.

PID Controller Tuning
This section presents both simulation and TCLab results regarding the PID controller gains optimized with the PSO algorithm as depicted in the previous sections. The results are compared with the Cohen-Coon (CC) settings [43], as previously introduced in [39,40] and a more recent technique: AMIGO [5], which is well-known to achieve system robustness. For the sake of experiment replication, these two tuning rule methods for PID controllers are presented in Table 1. Table 1. Cohen-Coon [32] and AMIGO [5] proportional, integral, and derivative (PID) tuning rules.

Method
Kp Ti Based on the FOPTD PSO model, PID controllers can be designed using several tuning methods. In [40], results were presented using the Cohen-Coon (CC) settings as these perform well for the TCLab. The results obtained with the CC PID settings Kp = 13.47, Ti = 45.99 s, and Td = 7.00 s are presented in Figure 7. This figure presents the overlapped results between the simulated and TCLab responses. A step input is applied to the system reference input at t = 0 s to define the TCLab transistor 1 set-point temperature at 25 °C and another one at t = 100 s increasing the set-point to 60 °C. A load disturbance with a magnitude of −40% is applied to the controller output at t = 380 s. Both the FOPTD model and the CC PID gains are used in the next section for comparison purposes with the other methods. The PSO optimization simulations were carried out in MATLAB ® /SIMULINK ® . The PSO settings were defined for all the subsequent PID controller tuning simulations as follows: • A swarm with size m = 30 particles.  Note that the conditions used for conducting the PSO optimization PID tuning tests differ from the ones used to perform the FOPTD model identification, particularly in the swarm size and higher iteration number. The PSO convergence rate for the PID optimization was found to be slower than the FOPTD model identification case.
The optimizations consider a step response applied at the reference input at t = 0 s assuming an ambient temperature of 18 °C and a set-point of 60 °C. The simulation time was 600 s, and a load disturbance with amplitude −40% was applied at instant t = 300 s. The optimization test result considering just the minimization of IAE is presented in Figures 9-11. In this case, the gains converged to the following values: Kp = 13.83, Ti = 39.54 s, and Td = 7.14 s. Figure 9 presents the SPT and LDR responses in the top plot and the control signal in the lower plot. As it can be observed, the system tracks well with no overshoot and with an acceptable load disturbance rejection.  Figure 10 shows the best PID gains evolution over 70 iterations. It is possible to observe from Figure 10 that the parameters converged to values are very close to the final ones by iteration 40. Figure 11 presents the evolution obtained with the best swarm cost value, IAE, and the average of the entire swarm particles cost function values. As observed, there is a convergence between the average and the best values in between iterations 40 and 50. These results clearly indicate that 70 iterations are an adequate stopping criterion, in this case.  Notice that this selection was done based on several tests performed on the TCLab. For cases with an additive compromise function, more relevance was given to TV over IAE. Before presenting the TCLab PSO results, a performance comparison with another swarm optimization algorithm, the original Grey Wolf Optimization (GWO) [18], is presented. The GWO was compared with the classical PSO in a benchmark test suit when it was proposed [18]. The GWO swarm size, number of iterations, and PID controller gains interval are the same as the ones used for the PSO. The GWO algorithm uses a heuristic parameter, represented by a [18] responsible for the tradeoff swarm exploration and exploitation. The GWO parameter a is a linearly decreasing vector from amax = 2 to amin = 0 through the evolutionary process. The simulation results are presented in Table 2 for cases I and II. The best controller gains from an 11 run set converged to very similar IAE and TV values. This indicates that with the appropriate settings the classical PSO performs, as well as the classical GWO for this control case study. More information regarding a comparison between PSO, GWO, and GSA for the PID control is reported in [19].
A compilation of the results with the classic tuning rules and PSO optimization is presented in Table 3. The best PSO gains presented in Table 2 are replicated in Table 3 for comparison. Note also that as the TCLab tests were performed in different day periods, the initial starting ambient temperature varies slightly from test to test. To see if this influenced the results analysis, the IAE and TV values considered only the period [95-620 s] (see Table 4). This interval starting point corresponds to 5 s prior to the second step change at t = 100 s where all the temperature steady-state values are approximately equal to 25 °C. The results obtained with the AMIGO PID settings: Kp = 4.69, Ti = 72.94 s, and Td = 9.48 s are presented in Figure 12. As it can be observed, the response presents a pronounced overshoot and worse load rejection disturbance compared with the CC response. The TV value obtained with the AMIGO settings is clearly better than the one obtained with CC (see Tables 3 and 4). The results obtained for PSO with just the ITAE minimization criterion (PSO-I) are presented in Figure 13. As it can be seen from Tables 3 and 4, only minimizing the IAE results in the best possible IAE value and worse TV than with the CC and AMIGO methods.  Observing the values obtained with the four PSO cases, the IAE value increases as expected. With the increase of the TV factor, β in the cost function, the corresponding TV value decreases. Depending on the TV requirements, it is possible to obtain better results for both IAE and TV compared with the CC and AMIGO tuning rules, as expected.   Figure 17 presents the overlap responses obtained with the TCLab regarding the following methods: CC, AMIGO, and PSO-IV. As it can be observed from the tracking response in the top plot, CC gains perform slightly better than the PSO-IV gains and these two are much better than AMIGO. However, regarding the control signals in the bottom plot, the optimized PSO gains result in a less aggressive and less irregular control signal variation than CC and AMIGO. The results also consider an output disturbance applied at instant t = 600 s, as presented in Figure  18. In this case, the disturbance was caused by blowing with a straw near the transistor 1 for 5 s, to decrease the temperature. As it can be observed, the response also tracks well from the output disturbance. Figure 18. TCLab responses using PSO (J = IAE + 60 TV). Output disturbance considered at t ≅ 600 s.

Conclusions
The design of Proportional, Integral, and Derivative controllers (PID) using a technique based on the particle swarm optimization algorithm is presented in this work. Classical PID tuning rules are dependent of the system dynamics and PID controller structure. Moreover, the PID settings in most methods differ according to the specific control design objective (e.g., set-point tracking or load disturbance rejection). The proposed PSO-based PID controller optimization technique holds the following characteristics which are of great practical interest: (a) To be easily implemented in digital industrial computers/microcontrollers; (b) to cope simultaneously with several control design criteria; (c) can be applied to control systems independently of system dynamics; and (d) rely in a reduced number of heuristic parameters, which can be easily adjusted for control purposes.
The merits of the proposed design technique lie within: • The use of an additive compromise cost function involving the minimization of two performance criteria: The Integral Absolute Error (IAE) and the Total Variation (TV). By using a simple compromise cost function, the proposed PID controller design technique simultaneously considers the following major control design criteria: Set-point tracking, load disturbance rejection, and control signal variation.
• By using the proposed cost function, it was shown that it is quite simple to select the PSO heuristic parameters with a special emphasis on the inertia weight decay.

•
The PSO was used to both perform the TCLab system identification as well as PID controller tuning. In both optimization problems, the proposed technique blends quite well with classical design techniques. One of the problems with the use of optimization algorithms in practical problems is to define appropriate decision variable search intervals. The identification of a firstorder plus time delay model with the PSO technique uses the two-point step response method [39,40] to define the model parameter search space. The Cohen-Coon PID controller tuning rules were used to define the controller gain search space.

•
The PSO results for the specific TCLab control case performs as well as a much more recently introduced metaheuristic: The grey wolf optimization.

•
The proposed technique was tested with an Arduino Temperature Control Laboratory (TCLab) and compared with well-established PID tuning methods. Both the simulation as well as physical TCLab results were presented to provide evidence of improved control performance.
The results show a good agreement between the simulation and measured results to validate the dynamic model identified with PSO.

•
The TCLab Arduino kit was introduced as a simple to use portable laboratory to test simulation results obtained with the proposed PSO-based technique. The same device has great potential to test other optimization and artificial intelligence-based techniques.