PID and Fuzzy Logic Control of Ball and Beam System Using Particle Swarm Optimization

Abstract

In this research, we carried out the modeling of the ball and beam system (BBS) within the MATLAB/Simulink framework by applying both proportional-integral-derivative (PID) and fuzzy logic control strategies to govern the dynamics of this constructed model. The underlying non-linear dynamic equations adjusting the behavior of the BBS system are based on Newton’s second law of motion. The physical installation of the BBS, designed for potential real-time application, comprises a lengthy beam subject to movement through the action of a DC servomotor, with a ball traversing the beam in a reciprocating manner. A distance sensor is strategically placed in front of the beam to determine the exact position of the ball. In this system, an electrical control signal applied to the DC servomotor causes the beam to pivot about its horizontal axis, thereby enabling the ball to move freely along the beam's length. To avoid the risk of losing the ball equilibrium on the beam and to achieve precise system control, a mathematical model was devised and implemented within the MATLAB/Simulink environment. The use of the particle swarm optimization (PSO) algorithm was aimed at tackling the task of refining and optimizing the PID controller specifically designed for the linearized ball and beam control system. The presented system is controlled using both PID and fuzzy logic, and the use of the PSO algorithm enhances the system’s responsiveness efficiency.

Share and Cite:

Alızada, M. and Ozturk, S. (2023) PID and Fuzzy Logic Control of Ball and Beam System Using Particle Swarm Optimization. World Journal of Engineering and Technology, 11, 859-873. doi: 10.4236/wjet.2023.114057.

1. Introduction

Systems generally consist of simple mechanical elements such as dampers, springs, and masses. Newton’s second law is used in the analysis of such mechanical systems. Sliding mode control (SMC) is a non-linear form of control that can be applied to systems with variable structures. SMC has found application in different electromechanical systems because of its insensitivity to system uncertainties and disturbance quantities. PID control is a traditional control form widely used in control applications. It is widely preferred today because of its ease of use and design. When discussing SMC, we are delving into a nonlinear control methodology distinguished by its precision, adaptability, and broad applicability. SMC revolves around the creation of a sliding surface tailored to meet specific design criteria. SMC is known as a two-piece controller design. A pivotal aspect of this approach involves the careful selection of a control law that renders the switching surface an enticing and effective target for the system’s state. In their study [1] , the researchers presented a comprehensive description of the development of a grid-connected photovoltaic system, encompassing the modeling of photovoltaic cells, the design of a DC-DC Ćuk converter, and the implementation of sliding mode control. Additionally, a finely tuned conventional PI controller has been introduced into the system to serve as a benchmark, allowing for an assessment of the prominence and efficacy of SMC. The obtained results show that SMC has advantages such as reference tracking, fast response to changes, and is better than the PI controller in terms of accuracy [2] . Open loop systems are called manual control systems because the output does not affect the input. Although the open-loop structure is simple, economical, and stable, it cannot always be relied upon. Closed-loop systems, often referred to as automatic control systems, offer a suite of benefits encompassing noise mitigation, adaptability to non-linearities, and robustness. Consequently, it is no surprise that closed-loop control systems tend to be the preferred choice in various control applications. The controller design achieves the previously mentioned performance measures with a closed-loop system. The choice of controller type depends on the goals and needs of the system. Typically, PID control involves the adjustment of three parameters; proportional (P), integral (I), and derivative (D). The basic equation of the traditional PID is as follows;

u ( t ) = K p e ( t ) + K i 0 t e ( t ) d t + K d d d t e ( t )

A PID controller is used in many control applications because it provides stability and reliability. It can be accurate based on mathematical models of the controlled process, but PID itself is insufficient to support more complex machines. The authors of another research have addressed the challenge of tracking the BBS trajectory by employing a resilient GPI Controller [3] . Their strategy entailed the application of a generalized proportional integral controller while also undertaking the intricate process of linearizing the system’s inherently nonlinear dynamics. This linearization was based on a tangent linearized system model centered around an equilibrium point, illuminating the creation of control rules based on the intricate relationships between input and output variables. In another study [4] , designing a fuzzy-PID controller to control the BBS stated that the fuzzy-PID controller is better than the traditional PID controller in terms of balancing and error correction. When the literature is analyzed, it is seen that studies are generally conducted using the BBS. One of the most important differences distinguishing this study from other known studies is that the BBS will be implemented using fuzzy and PID controllers, as well as allowing comparison of the results, which differs from similar studies. In this study, an application of a multi-objective PSO algorithm and evolutionary search technique was presented to solve the economic dispatching problem within power systems and consider environmental impacts [5] . Employing a variety of algorithmic techniques, some authors introduced an innovative predictive methodology that focuses on the integration of a neural network and a meta-heuristic algorithm to create a hybrid prediction engine [6] . In another research endeavor by different authors [7] , the focus was on achieving balance control in a BBS. To address this challenge, they introduced a pair of distinct fuzzy sliding-mode controllers (DFSMC) as part of their innovative control strategy. The BBS is preferred by researchers in testing many classical and modern control methods because of its non-linear and non-stable structure [8] . In addition, real control problems, such as ensuring the horizontal balance of aircraft during landing can be modeled with this system. According to the authors’ research, the minimization of environmental pollution using an improved artificial bee colony algorithm was designed. Using the proposed approach, information transactions between bees were performed using Newton’s and gravity laws [9] . The Lyapunov function used in the stability analysis of the system and the control rule used to control the system are determined by a recursive systematic procedure [10] . The researchers introduced an innovative forecasting model that used a hybrid prediction mechanism incorporating an enhanced iteration of empirical mode decomposition, referred to as “sliding window EMD.” This was complemented by the integration of a novel feature selection algorithm and a smart algorithm, which employed a distinct approach [11] . Many literature studies on BBS and position control have been examined. The distinguishing feature of this study is the control of the BBS with the help of the PSO algorithm using PID and fuzzy logic control. In the proposed model, position control of the system was carried out with PID and fuzzy logic controllers by using the PSO algorithm as the controller parameters in the MATLAB/Simulink environment.

2. Material and Methods

Two control methods are used in this system. First, the system model was created in the MATLAB/Simulink environment. PID was used to control the BBS and, the PSO algorithm was added to this control method to avoid the trial and error method. It is thought that the output signal of the system will be more efficient by using the PSO algorithm in PID control. A fuzzy logic control was used as the second method to manage uncertainties without the need for complex mathematical models. A PID controller is employed to manage the nonlinearity within the second-order system, overseeing the ball’s position by adjusting the beam through the motor while decreasing disturbances. The parameters of the PID are tuned using the PID tuning algorithm. The main purpose of using a PID controller in the BBS is to maintain precise control over the position and stability of the ball. A PID controller is used to adjust the control output based on the difference between the desired setpoint (where we want the ball to stay) and the actual measured process variable (the position of the ball). In control systems such as BBS, it is necessary to find the best control parameter gains in a PID controller to achieve the desired system performance. PSO can be used to optimize these parameters by searching for values that minimize a performance criterion, such as thresholding or solution time [12] . BBS systems often exhibit nonlinear behavior due to friction, inertia, and other complex dynamics. The aim of the fuzzy logic controller application was to effectively handle nonlinear systems by using linguistic variables and fuzzy rules to approximate the behavior of the system. This allows for more precise control in situations in which traditional linear controllers might struggle [13] .

Mathematical Model of the Ball and Beam System

The BBS is a mechanical arrangement comprising a ball and beam, where the ball is moved along the length of the beam. This motion is achieved through the action of a DC servomotor that is responsible for displacing the beam. Figure 1 provides a visual representation of the parameters that characterize the BBS. Because of the angle made by the beam with the horizontal plane, the ball rolls while maintaining its contact with the beam. The goal of the system is to control the position of the ball through the angle of the beam.

The equation obtained here gives us the relationship between the motion of the ball ( x b ) and the angle of the beam ( α . The parameters used in the BBS are summarized in Table 1.

The kinetic energy of the system is given in (1), the potential energy is given in (2), and the Lagrange expression is given in (3).

E k = 1 2 m b v b 2 + 1 2 J b ω b 2 = 1 2 ( m b + J b r b 2 ) x ˙ b 2 (1)

E p = m b g h b = m b g x b sin α (2)

d d t ( L q ˙ i ) L q i = Q i (3)

L = E k E p , d d t ( L x ˙ b ) = ( m b + J b r b 2 ) x ¨ b (4)

L x b = m b g sin α , Q = F x , t = k f x ˙ b (5)

If the necessary adjustments are made, the equation of motion is obtained as

( m b + J b r b 2 ) x ¨ b m b g sin α = k f x ˙ b (6)

Let’s write the equation in differential equation form.

Figure 1. Ball and beam system.

Table 1. Parameters of the ball and beam system.

x ¨ b k f r b 2 m b r b 2 + J b x ˙ b = m b g r b 2 m b r b 2 + J b sin α (7)

The purpose of modeling is to determine the physical relationship between the output and input of a system. In this study, the output of the system is the position of the ball ( x b ). The input of the system is the servo gear angle ( φ ), as shown in Figure 1. According to Figure 1, the following relationship can be obtained (8)

sin ( φ ) r M = sin ( α ) L = h (8)

If withdraw the sin ( α ) term from here, we can obtain the main equation.

sin α = r M L sin φ (9)

By substituting it in the equation of motion (10), the following equation is obtained.

x ¨ b k f r b 2 m b r b 2 + J b x ˙ b = m b g r b 2 r M ( m b r b 2 + J b ) L sin φ (10)

We can also write the Lagrange equation of motion for the ball and the beam in this way (11).

( J b r b 2 + m b ) x ¨ b m b g sin α m b x b ( α ˙ ) 2 = 0 (11)

If the beam angle α = 0, the linear approximation of the system becomes (12):

( J b r b 2 + m b ) x ¨ b = m b g α (12)

Then if substitute (9) into (12), we get:

( J b r b 2 + m b ) x ¨ b = m b g r M L φ (13)

If the Laplace transform of (13) is taken here,

( J b r b 2 + m b ) X ( s ) s 2 = m b g r M L φ (14)

X ( s ) φ ( s ) = m b g r M L ( J b r b 2 + m b ) 1 s 2 (15)

From Table 1, we can obtain the BBS transfer function from (16):

X ( s ) φ ( s ) = ( 0.286 ) ( 9.81 ) ( 0.078 ) 0.6 ( 1.76 e 5 0.02 × 0.02 + 0.286 ) 1 s 2 = 1.104 s 2 (16)

3. Design of the Controllers

The PID is the most commonly used controller type in industrial applications. The reason why it is frequently used is that its design is simple and its response time is fast. A PID controller is generally carried out by using the difference in the data obtained using sensors from the reference. As shown in Figure 2, the PID controller constantly calculates the error value. The controller applies a correction that includes proportional, integral, and derivative terms, and this correction aims to minimize the error. Control techniques such as PID and PI are frequently used, while P, I, and PD controllers are rarely used. Using specified controllers instead of PID reduces the price and in some cases increases performance [14] .

As shown in Figure 3, fuzzy logic control design offers a versatile and resilient method for regulating systems, particularly in cases where exact mathematical models are elusive or when confronted with intricate, uncertain, and complex system dynamics. Its applications span a broad spectrum of industries, including but not limited to automotive, robotics, and industrial automation, making it a valuable tool for addressing real-world control challenges. Defuzzification requires the selection of a specific defuzzification technique to obtain the ultimate output. Fuzzy Inference entails merging the conditions specified in each rule to produce fuzzy outputs for each rule. The fuzzification process involves assessing the degree of association between each input value and various fuzzy sets [15] .

3.1. PID Control Model of the Ball and Beam in Simulink

Before creating a PID control model, we created the BBS model of this system, as

Figure 2. Block diagram of the PID controller.

Figure 3. Block diagram of the fuzzy logic controller.

shown in Figure 4. Figure 4 shows, the system parameters used in this modeled system. In Figure 5, we have created the PID control model of the BBS. The beam length has been added to the parameter as 60 cm. We added a step block so that the ball stopped at a 30-cm position, bringing the final value to 0.3. PID coefficients were determined using PSO. The PSO model is shown in Figure 6. Based on the PSO algorithm modeled in Figure 6, there is a swarm and particles that are each individual of the swarm. Each particle adapts its position based on its previous experiences to reach the optimal location within the swarm. Other particles update their movements according to the individual of the swarm with the best position at that moment. This approach speed is a randomly developing situation, and generally, the particles come to a better position in their new movements than in the previous one. This process continues until the goal is reached.

As shown in Figure 7, the PSO algorithm tries a number of possible solutions for a given problem and finds the Pbest values that are closest to the desired result and lead to the solution with the least error. The algorithm evaluates the Pbest values in different herds and determines an overall result known as Gbest. Using this information, the PSO algorithm can be effectively used to find the desired parameters in the simulation.

These coefficients were added to the system and, the output result is shown in Figure 8. These are the PID coefficients obtained using particle swarm optimization:

K p = 8.9926 , K i = 0.01 , K d = 6.0011

Figure 4. Ball and beam system model in Simulink.

Figure 5. PID control model of the ball and beam system.

Figure 6. Ball and beam system using the PSO algorithm model.

3.2. Fuzzy Logic Control Model of the Ball and Beam in Simulink

In the case of errors, the discrete use of fuzzy logic is effective in reducing the overall error [16] . Many researchers are continuously investigating the application of fuzzy logic to improve the operational efficiency of complex machines [17] . As shown in Figure 9, the fuzzy logic controller model was used for BBS. As shown in Figure 10, the fuzzy logic control system considers two primary inputs: the positional error and its derivative. The outcome of this system is the incorporation of a motor.

Figure 7. PSO algorithm pseudo code.

Figure 8. PID-controlled simulation results.

Figure 9. Fuzzy logic control model of the ball and beam system.

Once the fuzzy logic inputs and outputs have been integrated, the subsequent step involves establishing the membership functions for the system. In this particular investigation, a set of seven distinct membership functions was meticulously crafted. Seven membership functions were created, as shown in Table 2. It is worth noting that these membership functions were structured in the form of a triangle-trim type.

Figure 10. Determination of the input and output in fuzzy logic.

Table 2. Variables of membership function.

When we say membership function, we define it as the mapping of points in the input space to a membership degree [18] . Figure 11 shows the error membership function and the derivative error in the range from −50 to 50. This range is chosen based on the entire range of the beam. Two inputs are added and divided into seven membership functions. The system was chosen to reduce distortion in ball control positioning. The control output, i.e., the output function of the controller, is shown in Figure 12 and a range between −80 and 80 is given [19] .

Linguistic variables map input and output through fuzzy mapping rules. Their functions are the same as those of human instinct and decision-making ability. As shown in Figure 13, we obtained the fuzzy logic rule surface plot. A fuzzy surface typically refers to a surface that lacks clarity, sharpness, or well-defined boundaries. It is characterized by a degree of blurriness, imprecision, or uncertainty in its appearance or definition. A fuzzy surface is a concept that deals with the blurriness, imprecision, and uncertainty associated with surfaces or data in various domains, depending on the context in which it is used. Table 3 shows the designed fuzzy rules.

4. Simulation Results

This section discusses the simulation results for PID and fuzzy controllers in the context of setpoint regulation, and tracking performance. The PSO algorithm was used for PID optimization, and many parameters used in this algorithm are shown in Table 4. PSO iteration was used for PID control in this system, and the

Figure 11. Membership function for error and derivative error in fuzzy logic.

Figure 12. Membership function for output in fuzzy logic.

Table 3. Fuzzy rules.

Figure 13. Fuzzy logic rule surface plot.

PID gains obtained from the five best PSO experiments are shown in Table 5. Because of this iteration, the 3rd iteration was considered to be the best result for this system. The results of five PSO renewals in scope are presented as shown in

Table 4. Parameters used in the PSO algorithm.

Table 5. PID gains obtained for the PSO iterations.

Figure 14. The five iteration signal outputs were zoomed in to better see. Signal changes between the 0 - 1.6 seconds, 0.5 - 3 seconds, 1.5 - 3 seconds, and 3 - 5 seconds intervals of the used iterations were examined.

In Figure 15, the results of the 5 iterations used in the PSO algorithm are compared. As seen in the Iteration 1 simulation, the system reaches the desired position within 3.5 - 4 seconds. In the Iteration 2 simulation, the fluctuation is higher than in Iteration 1 and it takes 5 - 5.5 seconds to reach the desired position. Iteration 3 simulation is considered to be the iteration that gives the best results because it requires 2.5 seconds to reach the desired position. When we look at the Iteration 4 simulation, it gives a better result compared to Iterations 1 and 2, but it takes 3 seconds to reach the desired position. In the last iteration, iteration 5, there is some fluctuation at first, but it gives better results than iteration 2 and it takes 3 - 3.5 seconds to reach the desired position.

As seen in Figure 16, the blue signal setpoint value, i.e., the desired position, has been added as 0.3, and the red signal is the simulated system. It takes 7.5 - 8 seconds for the ball to reach the desired position.

5. Conclusion

In this experiment with the BBS system, we conducted iterations using two distinct control methodologies, yielding valuable simulation data. We used the potential of the PSO algorithm to optimize the parameters of the PID controller. Through a comprehensive comparative analysis, we evaluated the efficiency of the PSO algorithm in fine-tuning the PID controller parameters, contrasting it with the classical trial and error method. Our results highlight the effectiveness of the PID tuning method based on the PSO algorithm. Significantly, we observed

Figure 14. Step responses of the PSO iteration results.

Figure 15. Comparison of the PSO algorithm iterations with simulation.

Figure 16. Fuzzy Logic-controlled simulation results.

that the dynamic system control process under the trial and error method consumed more time than the streamlined PSO method. In addition, we ventured into an alternative control strategy aimed at regulating the ball’s position within the BBS. Here, we demonstrated the practical application of fuzzy logic as an integral part of our control strategy. After establishing the fuzzy logic model, the simulation results show that the fuzzy logic controller can stabilize the system efficiently. In addition, the performance of the fuzzy logic control system in the transient period is more advantageous in terms of achieving less overshoot, and the fuzzy logic controller also provides zero steady-state error. The approach presented in this article can be applied to various fields. Furthermore, this study is considered a research area with significant potential for use in industrial applications.

Conflicts of Interest

The authors declare no conflicts of interest regarding the publication of this paper.

References

[1] Farhadi, P., Sedaghat, M., Sharifi, S. and Taheri, B. (2017) Power Point Tracking in Photovoltaic Systems by Sliding Mode Control. 2017 10th International Symposium on Advanced Topics in Electrical Engineering (ATEE), Bucharest, 23-25 March 2017, 781-785.
https://doi.org/10.1109/ATEE.2017.7905097
[2] Ltifi, A., Ghariani, M. and Neji, R. (2014) Performance comparison of PI, SMC and PI-Sliding Mode Controller for EV. 2014 15th International Conference on Sciences and Techniques of Automatic Control and Computer Engineering (STA), Hammamet, 21-23 December 2014, 291-297.
https://doi.org/10.1109/STA.2014.7086731
[3] Ramírez-Neria, M., Sira-Ramírez, H., Garrido-Moctezuma, R. and Luviano-Juarez, A. (2016) Linear Robust Generalized Proportional Integral Control of a Ball and Beam System for Trajectory Tracking Tasks. 2016 American Control Conference (ACC), Boston, MA, 6-8 July 2016, 4719-4724.
https://doi.org/10.1109/ACC.2016.7526099
[4] Wu, Y.Y. and Liu, Y.X. (2015) Fuzzy PID Controller Design and Implement in Ball-Beam System. 2015 34th Chinese Control Conference (CCC), Hangzhou, 28-30 July 2015, 3613-3616.
https://doi.org/10.1109/ChiCC.2015.7260197
[5] Taheri, B., Aghajani, G. and Sedaghat, M. (2017) Economic Dispatch in a Power System Considering Environmental Pollution Using a Multi-Objective Particle Swarm Optimization Algorithm Based on the Pareto Criterion and Fuzzy Logic. International Journal of Energy and Environmental Engineering, 8, 99-107.
https://doi.org/10.1007/s40095-017-0233-9
[6] Abedinia, O., Amjady, N. and Ghadimi, N. (2018) Solar Energy Forecasting Based on Hybrid Neural Network and Improved Metaheuristic Algorithm. Computational Intelligence, 34, 241-260.
https://doi.org/10.1111/coin.12145
[7] Chang, Y.-H., Chang, C.-W., Tao, C.-W., Lin, H.-W. and Taur, J.-S. (2012) Fuzzy Sliding-Mode Control for Ball and Beam System with Fuzzy Ant Colony Optimization. Expert Systems with Applications, 39, 3624-3633.
https://doi.org/10.1016/j.eswa.2011.09.052
[8] Mehedi, I.M., Al-Saggaf, U.M., Mansouri, R. and Bettayeb, M. (2019) Two Degrees of Freedom Fractional Controller Design: Application to the Ball and Beam System. Measurement: Journal of the International Measurement Confederation, 135, 13-22.
https://doi.org/10.1016/j.measurement.2018.11.021
[9] Sharifi, S., et al. (2017) Environmental Economic Dispatch Using Improved Artificial Bee Colony Algorithm. Evolving Systems, 8, 233-242.
https://doi.org/10.1007/s12530-017-9189-5
[10] Sharkawy, A., Othman, M. and Khalil, A. (2011) A Robust Fuzzy Tracking Control Scheme for Robotic Manipulators with Experimental Verification. Intelligent Control and Automation, 2, 100-111.
https://doi.org/10.4236/ica.2011.22012
[11] Mohammadi, M., et al. (2018) Small-Scale Building Load Forecast Based on Hybrid Forecast Engine. Neural Processing Letters, 48, 329-351.
https://doi.org/10.1007/s11063-017-9723-2
[12] Tarique, A. and Gabbar, H. (2013) Particle Swarm Optimization (PSO) Based Turbine Control. Intelligent Control and Automation, 4, 126-137.
https://doi.org/10.4236/ica.2013.42018
[13] Soufi, N., Moghaddam, M., Boroujeni, S. and Vahidifar, A. (2014) A Parameter Varying PD Control for Fuzzy Servo Mechanism. Intelligent Control and Automation, 5, 156-169.
https://doi.org/10.4236/ica.2014.53018
[14] Liu, B., He, B. and Luo, X. (2015) On the Comparisons of PID and GI-PD Control. Engineering, 7, 387-394.
https://doi.org/10.4236/eng.2015.77035
[15] Zhang, Z., Yuan, S., Zhang, J., Ma, C., Xu, J. and Lin, X. (2018) A Knowledge Measure with Parameter of Intuitionistic Fuzzy Sets. Applied Mathematics, 9, 874-889.
https://doi.org/10.4236/am.2018.97060
[16] Isa, A.I., Hamza, M.F., Zimit, A.Y. and Adamu, J.K. (2018) Modelling and Fuzzy Control of Ball and Beam System. 2018 IEEE 7th International Conference on Adaptive Science & Technology (ICAST), Accra, 22-24 August 2018, 1-6.
https://doi.org/10.1109/ICASTECH.2018.8507132
[17] Aziz, N.S.A., Adnan, R. and Tajjudin, M. (2017) Design and Evaluation of Fuzzy PID Controller for Ball and Beam System. 2017 IEEE 8th Control and System Graduate Research Colloquium (ICSGRC), Shah Alam, 4-5 August 2017, 28-32.
https://doi.org/10.1109/ICSGRC.2017.8070562
[18] Schrieber, M.D. and Biglarbegian, M. (2015) Hardware Implementation and Performance Comparison of Interval Type-2 Fuzzy Logic Controllers for Real-Time Applications. Applied Soft Computing, 32, 175-188.
https://doi.org/10.1016/j.asoc.2015.03.022
[19] Chen, C. and Xiao, T. (2011) Probabilistic Fuzzy Control of Mobile Robots for Range Sensor Based Reactive Navigation. Intelligent Control and Automation, 2, 77-85.
https://doi.org/10.4236/ica.2011.22009

Copyright © 2024 by authors and Scientific Research Publishing Inc.

Creative Commons License

This work and the related PDF file are licensed under a Creative Commons Attribution 4.0 International License.