PID and Fuzzy Logic Control of Ball and Beam System Using Particle Swarm Optimization ()
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;
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 (
) 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).
(1)
(2)
(3)
(4)
(5)
If the necessary adjustments are made, the equation of motion is obtained as
(6)
Let’s write the equation in differential equation form.
Table 1. Parameters of the ball and beam system.
(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 (
). 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)
(8)
If withdraw the
term from here, we can obtain the main equation.
(9)
By substituting it in the equation of motion (10), the following equation is obtained.
(10)
We can also write the Lagrange equation of motion for the ball and the beam in this way (11).
(11)
If the beam angle α = 0, the linear approximation of the system becomes (12):
(12)
Then if substitute (9) into (12), we get:
(13)
If the Laplace transform of (13) is taken here,
(14)
(15)
From Table 1, we can obtain the BBS transfer function from (16):
(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:
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 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.
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.