Sie sind auf Seite 1von 6

PI tuning based on Bacterial Foraging Algorithm

for flow control.

1st Rios Hernández Ronald 2nd Apráez Bastidas Alejandra 3rd Rodriguez Calderon Jaime
Ingeniero en automatización E. de ingenierı́a en automatización E. de ingenierı́a en automatización
Universidad de la Salle Universidad de la Salle Universidad de la Salle
Bogotá, Colombia Bogotá, Colombia Bogotá, Colombia

4th Tumialán Borja José Antonio

Docente ingenierı́a en automatización
Universidad de la Salle
Bogotá, Colombia

Abstract—In the industrial field, the need has arisen to use constants obtained, improving conditions such as overshoot
more efficient and robust controllers using artificial intelligence and establishment time [2].
techniques that optimize the operation of processes within the
industry. In this way, the need arises to use adaptive controllers
such as the BFOA and implement it in real systems in which In the literature, the BFOA algorithm was implemented
its functionality can be analyzed. This article presents the with the aim of designing an adaptive PID controller for
implementation and analysis in a functional prototype fully a third-order system, which was compared to a genetic
instrumented with industrial sensors. The working methodology algorithm and a fuzzy neural network to analyze the
has been documented since the acquisition of physical variables constants obtained by each of them. It was observed that
through OPC client-server communication; the excitation timing
of the input variable (speed inverter) and obtaining the evolution the performance index of the algorithms corresponds to 0.26
of the flow over time; experimental data used the relative for the neural network, 0.23 for the genetic algorithm and
least squares identification methodology to obtain the transfer 0.017 for BFOA, which showed a better result for the latter;
function. Subsequently, the BFOA algorithm was implemented to showing that this algorithm can be used in different control
adjust the constants of a PI controller (Kp and Ki ) and analyze systems by varying the initialization parameters [3].
the response through simulation using Matlab software, in which
satisfactory results were observed based on the disturbance
response analysis and as an end the controller and BFOA A PID controller was also designed using the Bacterial
algorithm a PLC-S7-1500 controller was implemented in an Foraging algorithm for a stable system (RLC circuit) and
SCL language , validation of the functionality was performed an unstable system (inverted pendulum). The results showed
with the functional prototype changing the flow consignments at that the algorithm significantly improves absolute error
certain times, observing a behavior according to the simulations
performed with a minimum overstep of approximately 5 % and (2,5087e-04), establishment time (5,9554e-04s) and overshoot
an establishment time of 20s. (0.0 0061) for the RLC system and an absolute error (0.0856),
Index Terms—Bacterial foraging, OPC, AI, adaptive control, set-up time (0.8102s) and overshoot (0.0270) for the inverted
optimization, SCL, identification, experimental validation. pendulum [2].

I. I NTRODUCTION The combination of the algorithm of Bacterial Foraging

Currently there are errors in the operation of industrial together with the algorithm of Particle Swarm Optimization
processes which can be corrected with the use of optimization (PSO) was implemented for tuning a PID controller; this in
techniques that improve or adjust the parameters. Faced order to use the advantages that each provides and get better
with this need, the optimization methods were developed optimization values. Through the combination of techniques,
bioinspirados, which are based on nature’s response to the it was observed that overshoot was lower compared to other
problems and processes that arise in their environment [1]. techniques, and that the cost function was lower, compared
In industrial applications the PID controller is the most with the function obtained by individually analyzed strategies;
widely used and implemented; Controller parameters are in the case of the PSO algorithm the value corresponded
usually adjusted using conventional methods, which can to 15,3445, for the BF algorithm it was 7,7158 and the
provide gains that are not always adapted for the process in combined technique corresponded to 7,3021 for one of the
question, as in the case of unstable systems with delay time. plants evaluated [4].
The incorporation of bioinspired algorithms can modify the

978-1-7281-9496-7/20/31.00 ©2020 IEEE

By combining the same algorithms, the system temperature In this work the algorithm Bacterial Foraging was used
control of a heat exchanger was performed using a PID to find the constants Kp and Ki of a PI controller, which
controller. To tune in the controller conventional methods was taken to an experimental prototype of a process plant
such as Ziegler-Nichols were first used, and then the combined to perform flow control. This plant consists of an industrial
algorithm was applied. It was shown that the establishment process based on closed-circuit hydraulic pumping and
time was 254.08s for Ziegler-Nichols and 200s for the with functions of flow control, fluid heating and cooling,
BFO-PSO algorithm; a higher percentage of overshoot in ZN instrumentation for point-level, continuous level, hydraulic
(33.07) was also observed while the BFO-PSO algorithm did flow, pressure and temperature measurements [7].
not show up overshoot. [5].
The plant has sensors and a programmable logic controller
The BFOA algorithm, proposed by Passino, uses the (PLC) S7-1500 from Siemens. The plant is detailed in Figure
processes developed by the bacterium E. Coli in its 2.
environment, since bacteria tend to look for their nutrients in
a way that maximizes the energy obtained per unit of time,
but also each bacterium communicates with the others in its
environment by sending signals. Together, bacteria try to find
their food and avoid harmful phenomena, generating a type of
intelligent behavior, whose movement patterns are generated
by the presence of attractive and repellent chemicals [6].

An E. Coli bacteria can move in two different ways: it can

swim (over a period of time), or it can tumble. Movement
is achieved through a series of relatively rigid flagella that
allow the bacteria to move depending on the direction in
which they move. That is, if its flagella rotate clockwise, the
bacteria performs a rotational movement, while if its flagella
rotate counterclockwise, the bacteria swim. This movement
is detailed in Figure 1.

Fig. 2 Process Plant P&ID Diagram. [8]


Fig. 1 Swim,tumble, E. Coli movements. [6]

Client-server OPC communication was developed to obtain
the flow over time, the mathematical model based on relative
The BFOA algorithm mimics the four main mechanisms
least squares identification, the development and implementa-
in a population of bacteria: chemotaxis, swarm, reproduction
tion of the BFOA algorithm and its subsequent analysis.
and elimination. The purpose is to find the minimum of the
cost function J(θ), which represents the effects of attraction
and repulsion of substances in the medium depending on the
position in which the bacteria is located. When the bacteria is A. OPC communication
in a neutral environment (i.e., no harmful substances or food
are found), swimming and rotational movements alternate; Through OPC and KepServer the acquisition of data from
this allows the bacteria to move in a random direction to the value of the flow sensor was configured, allowing reading
continue searching for nutrients. When the bacteria finds and writing of the variables, injecting a white noise into the
a nutrient, the distance and time spent in each movement pump setpoint to perform the identification of the dynamic
change according to the need to approach that nutrient. That system. As shown in figure 3 a white noise oscillating at
is, the bacteria tends to always look for the best nutrient random with pump setpoint values between 12000 and 32000
gradient in its space, so constant movement is required. was established, with a white noise change frequency of 0.05
Considering the regressor matrix and the output of the
dynamic system, there is the optimal a and b where the
gradient of θ is taken into account relative to the cost function,
so that the error between the extinction measurements and
the estimation error is as close to 0. This identification
methodology is one of the best compared to others, taking
into account the most appropriate mathematical model; in the
event that the error is high it is most advisable to propose a
model more approximate to the system dynamics, a matrix
containing the coefficients of the mathematical model was
designed, taking into account that the number of coefficients
(α, β) depends on the order of the proposed model.

−1 T
θ = φT φ

φ Y (3)

The cost function required to solve the optimization problem

is defined in the equation 4, which is dependent on both θ and
Fig. 3 White noise injected into the process plant for flow identifi- φ, taking into account the element to be minimized.
B. Mathematical model based on identification 1 X
J(θ) = (y(k) − yb(k, θ))2 (4)
The least squares identification methodology was used to N
obtain the experimental prototype transfer function specifically
the physical flow variable, the procedure is performed by
exciting the input response u(k) to the system and model,
comparing the output of the system and calculating the mean
quadratic error as presented in the figure 4.

Fig. 4 Minimum square identification architecture.

As initial parameters of the methodology a first-order model

was proposed without delay corresponding to the plant, as Fig. 5 Response of the flow system to a white noise input.
presented in the equation 1.

β1 z −1 With the values obtained from the system identification

F = (1) process (figure 5), the transfer function was obtained in the
1 − α1 z −1
discrete domain as seen in the equation 5.
The regressor matrix that contains the input (drive setpoint)
and system output values over time (flow), which is repre- 0.0024642
sented in the way Gp = (5)
z − 0.9896
 T 
ϕ (0) The pseudocode of algorithm 1. corresponds to the identifi-
 ϕT (1) 
cation implemented to find the transfer function of the flow
φ= .  (2)
 
 ..  system from the plant model and the proposed model taking
ϕT (n) into account the experimental data.
Algorithm 1 Relative least squares For the BFOA algorithm, the following initial parameters
Input: White noise change frequency of 0.05 Hz were set as presented in the table I.
Output: Speed =(Flow response over time
for i = 2, ..Data − 1 do Table I BFOA algorithm initialization parameters.
Data input (white noise) and output (Flow) in variables, the BFOA parameters
regressor matrix is created Variable Value Description
Xmin = SpeedM in, U min = InputM in p 2 Search space dimension
end for S 8 Number of bacteria
3: θ = inv(φT ∗ φ) ∗ φT ∗ Y Nc 10 Number of chemotactic steps
α = θ(1, 1) Ns 4 Swimming length
β = θ(2, 1) Nre 4 Number of reproduction steps
6: for J = Data : 1 : T otalData do Ned 2 Number of elimination events
6: Cost Function: Yk (j) = −α ∗ Speed(j − 1) + β ∗ Ped 0.25 Probability of elimination
inputSpeed(j − 1); n
end for=0
For the cost function, the integral square error (ISE) and
the system overstep value (alpha) were used, assigning each
C. Development and implementation of the BFOA algorithm of them a weight whose sum is equal to one; for the process
in simulation plant it was decided to prioritize the integral square error
(Beta). The following is the pseudocode implemented for this
The dimension of the search space is determined by the function.
constants that are required to be found from the controller.
Because a PI control is performed, the search space is equal
to 2, to find the constants Kp and Ki . The implemented Algorithm 3 Cost function
pseudocode is: 0: R ∞ of the function J(i, j, k, l)
Assign Kp and Ki the values
0: Calculate ISE: ISE = 0 [e(t)]2 dt
Algorithm 2 Bacterial Foraging 0: Calculate overshoot by: sysos = max(yout) − 1
0: Assign weights to parameters alpha = 0.3, beta = 0.7
Input: Initial parameters BFOA (p, S, Nc, Ns, Nre, Ned, Ped ) 0: Calculate the cost function F = e × beta + sysos × alpha
Output: Control constants : Kp, Ki return values Cost function =0
0: Elimination loop l = l + 1
0: Reproduction loop k = k + 1
0: Chemotactic loop j = j + 1 In the figure 6, bacteria are observed in an initial state, with
for i = 1, 2, ... do constants thrown by a poor controller therefore the control
Calculate the cost function J(i, j, k, l) within the process is not the most suitable for the operation of
Assign to Jlast J(i, j, k, l) the system; using these constants as a starting point proceeds
Tumble: generate random tumble vector ∆(i)
Displacement: calculate θi (j + 1, k, l) to the implementation of the BFOA optimization algorithm. At
Calculate the cost function J(i, j + 1, k, l) the end of the iterations of the algorithm, the bacteria gather
Swimming: This process is done while m< Ns at a common point, in which there is the greatest amount of
2: while m < Ns do nutrients, that is, where the best and optimal constants of the
2: Start counter m = 0 controller are located, the location of the bacteria on the x-
2: Calculate θi (j + 1, k, l)
2: Calculate the cost function J(i, j + 1, k, l) axis corresponds to the proportional constant Kp and on the
end while axis and the integral constant Ki . These values correspond to
Continue with bacteria i + 1 Kp = 52.5444 and Ki = 6.9468.
4: end for
if j < N c then
Calculate the health of the bacteria i by:
X c +1
Jhealth = J(i, j, k, l) (6)

Bacteria with the highest value of Jh ealth dies and the lowest
is divided into two
6: end if
if k < N re then
Continued reproduction of bacteria
8: end if
for i=1,2,....,S do
Elimination and dispersal of bacteria
10: end for
if l < N ed then
Return to step 1 Fig. 6 Initial location of bacteria in the search space (above). Final
12: end if=0 location of bacteria around nutrients (below).
The flow control’s response to a set point input of 200 L/h
is presented in figure 7. By implementing the closed loop PI
controller, a stable system is obtained, with a low overshoot
percentage and a set time of less than 20s.

Fig. 9 BFOA block.

The block that calculates the cost function is presented in

the figure 10

Fig. 7 Flow control response.

In addition to the above characteristics, it was observed

that the system has a good response to disturbances, because
the movement of bacteria brings the system to controllable
maximum and minimum values, ensuring the response of the
controller at different reference values as presented in figure
Fig. 10 Cost function block.

Since the Tia Portal software does not have the same
functions as the Matlab software, it took a more structured
programming to obtain the expected result, where libraries
specific to the TIA Portal software were used, such as the
library LGFRandomReal that allows random numbers to be
generated to indicate the initial positions of the constants. All
codes corresponding to the algorithm of Bacterial Foraging
were implemented in a cyclic interrupt block (OB30) with a
time of 0.1s. When the algorithm is executed on the PLC,
the bacteria move around the space to find the optimal values
of the constants Kp and Ki in the PI controller; this is done
Fig. 8 Response of flow control to system disturbances. by the block FB Bacterial.

The validation of the operation of the algorithm, was

III. E XPERIMENTAL RESULTS . performed on a PLC controller S7 1500 in a real process
within the process plant of the figure 2 for the flow control
of the system, where initially the percentage of overshoot is
After testing the Matlab software, BFOA was deployed considerably high; after implementing the BFOA algorithm
to the TIA Portal software using the SCL language. Figure a system was obtained with a low overshoot percentage and
9 presents the block where the BFOA algorithm code was shorter stabilization time, as presented in the figure 11.
software allows to constantly monitor the plant’s response;
this means that before changes or disturbances, the algorithm
can re-evaluate the controller constants.

Some of the main disadvantages of the algorithm are that

BFOA assumes that there is no variation in the concentration
of nutrients caused by the absorption that bacteria perform
for their feeding, as this implies that the cost function J
Fig. 11 System behavior with constants found in the BFOA algorithm. varies when nutrients have already been consumed in one
position. In addition, bacteria are known to have exponential
A comparison was made between different controller growth, however, to reduce computational cost, the algorithm
design methodologies, such as polynomial design, cascading uses a fixed population, the size of which is not altered by
control and the implemented BFOA algorithm. The result is the simultaneous effects of reproduction and elimination, even
presented below. though there are different generations and nutrients.
Table II Comparison of control methodologies implemented in the
process plant.
[1] I. R. Medina, “Revisión de los algoritmos bioinspira-
dos.,” 2014.
Control methodologies implemented [2] N. Das and A. Sengupta., “A comparison between adap-
Methodology Overshoot Establishment Time
Cascading 0% 30s tive pid controller and pid controller with derivative
Polynomial 25% 25s path filter based on bacterial foraging optimization al-
BFOA 5% 20s gorithm.,” 2018.
[3] G. Wu, “Application of adaptive pid controller based on
It was observed in table II the control performed by BFOA, bacterial foraging optimization algorithm,” 2013.
has a response with low overshoot and low establishment [4] W. Korani, H. T. Dorrah, and H. Emara, “Bacterial
time, this due to the quadratic error used in the cost function foraging oriented by particle swarm optimization strategy
(ISE), which allows this error to be as close to 0, having this for pid tuning,” Computational Intelligence in Robotics
compared to the cascading control for which the control of and Automation, 2010.
the process pressure was first taken into account as an internal [5] S. Gupta and R. Gupta, “Controller parameter opti-
control loop , once this internal control was found the new mization using hybrid bfoa-pso algorithm.,” IEEE In-
system transfer function to find the control of the external ternational Conference on Power Electronics. Intelligent
loop which is evident in the flow control, for which the Control and Energy Systems., 2016.
overshoot is almost 0% and its establishment time is much [6] S. Das, A. Biswas, S. Dasgupta, and A. Abraham,
longer than the control performed by BFOA and polynomial Bacterial Foraging Optimization Algorithm: Theoretical
design. Compared to polynomial design control has a fast Foundations, Analysis, and Applications. Springer, 2009,
response but with greater overshoot, because this control pp. 23–55.
is performed under established design parameters which [7] Anitco., “Manual de operación y mantenimiento unidad
does not necessarily indicate that they are the best operating de entrenamiento en automatización.,” 2016.
parameters for the system. [8] M. A. R. Mahecha., “Implementación sistema de super-
visión y control para los módulos de procesos.,” 2019.
After the iterations of the algorithm in which it found
the most optimal positions, new constants Kp and Ki are
generated taking into account the needs expressed in the
cost function, this algorithm implemented in the SCL block
constantly throws the constants improvements to the controller
where it is evidenced as an adaptive controller which in each
iteration evaluates the previous constants and whether they
are better, being better and more optimal are sent to the
PLC controller and therefore the system improves its output
response with each of the iterations that pass to the best
constants as presented in the figure 11.
Among the main advantages of this algorithm is that this
can be used online or offline depending on the computational
cost available. Implementing this code in the TIA Portal