Skip to main content

Bacterial foraging-optimized PID control of a two-wheeled machine with a two-directional handling mechanism


This paper presents the performance of utilizing a bacterial foraging optimization algorithm on a PID control scheme for controlling a five DOF two-wheeled robotic machine with two-directional handling mechanism. The system under investigation provides solutions for industrial robotic applications that require a limited-space working environment. The system nonlinear mathematical model, derived using Lagrangian modeling approach, is simulated in MATLAB/Simulink® environment. Bacterial foraging-optimized PID control with decoupled nature is designed and implemented. Various working scenarios with multiple initial conditions are used to test the robustness and the system performance. Simulation results revealed the effectiveness of the bacterial foraging-optimized PID control method in improving the system performance compared to the PID control scheme.


The interest in two-wheeled machines (TWMs) is incomparably increasing, and various linear and nonlinear methods of identification are employed for developing an accurate model of the inverted pendulum and establishing a proper control strategy for the system. Lee et al. [1] concentrated on designing a one-wheel inverted pendulum system that employs air power for balancing. The pitch angle was controlled by a DC motor, while the roll angle was regulated by air pressure sent out from ducted fans controlled by linear control methods. Chinnadurai and Ranganathan [2] focused on applying the principle of IP by proposing a two-wheel self-supporting robot controlled by an internet-on-a chip (IOC) controller. The main feature associated with this system is the capability to control the robot worldwide using the IOC, not to mention the IR, attitude, and tilt sensors installed on the robot. A novel configuration of wheeled robotic machines (WRM) which is based on the principle of two-wheeled inverted pendulum (IP) with an extended intermediate body (IB) was developed by Goher and Tokhi [3]. For providing multiple lifting levels for a carried payload, the developed machine is equipped with a linear actuator. The previously mentioned WRM was later improved by Almeshal et al. [4]. Increasing the machine’s flexibility and workspace led to a novel five DOFs two-wheeled IP with an extended rod.

Implementation of optimization techniques on IP systems

Determining the optimal control strategy for IP systems has been and still a major concern for significant amount of studies. Diverse modeling techniques and control approaches have been applied for investigating and controlling this highly nonlinear system [5, 8]. Due to their outstanding successful applications in various areas of interest, nature-inspired and bio-inspired optimization algorithms are significantly gaining attention in nowadays research aspects. Within the past decade, there has been a tremendous amount of research studies focusing on developing optimization algorithms. Some of these algorithms include particle swarm optimization (PSO) algorithm [9], spiral dynamics algorithm (SDA) [10], genetic algorithm (GA) [11], and bacterial foraging optimization (BFO) [12].

Bacterial foraging optimization (BFO) algorithm

The survival of species in any natural evolutionary process depends upon their fitness criteria, which relies upon their food searching and motile behavior. The law of evolution supports those species who have better food searching ability and either eliminates or reshapes those with poor search ability. The genes of those species who are stronger get propagated in the evolution chain since they possess ability to reproduce even better species in future generations. So, a clear understanding and modeling of foraging behavior in any of the evolutionary species leads to its application in any nonlinear system optimization algorithm. The foraging strategy of Escherichia Coli bacteria present in human intestine was introduced by Passino [12] and explained by four processes: chemotaxis, swarming, reproduction, and elimination dispersal. The characteristics of movement of bacteria in search of food can be defined in two ways, i.e., swimming and tumbling, together known as chemotaxis. A bacterium is said to be “swimming” if it moves in a predefined direction, and “tumbling” if moving in altogether different direction. In the swarming phase, and for the bacteria to reach the richest food location (i.e., for the algorithm to converge at the solution point), it is desired that the optimum bacterium till a point of time in the search period should try to attract other bacteria so that together they converge at the desired location (solution point) more rapidly. To achieve this, a penalty function based upon the relative distances of each bacterium from the fittest bacterium till that search duration, is added to the original cost function. Finally, when all the bacteria have merged into the solution point, this penalty function becomes zero. The effect of swarming is to make the bacteria congregate into groups and move as concentric patterns with high bacterial density. In regard to the reproduction phase, the original set of bacteria, after getting evolved through several chemotactic stages, reach the reproduction stage. Here, best set of bacteria (chosen out of all the chemotactic stages) get divided into two groups. The healthier half replaces with the other half of bacteria, which gets eliminated, owing to their poorer foraging abilities. This makes the population of bacteria constant in the evolution process. In the evolution process, a sudden unforeseen event can occur, which may drastically alter the smooth process of evolution and cause the elimination of the set of bacteria and/or disperse them to a new environment. Most ironically, instead of disturbing the usual chemotactic growth of the set of bacteria, this unknown event may place a newer set of bacteria nearer to the food location. From a broad perspective, elimination and dispersal are parts of the population-level long-distance motile behavior. In its application to optimization, it helps in reducing the behavior of stagnation (i.e., being trapped in a premature solution point or local optima) often seen in such parallel search algorithms. Table 1 represents the main parameters of BFO algorithm.

Table 1 BFO algorithm parameters [12]

BFO implementation

BFO has been applied in numerous research areas. Supriyono and Tokhi [13] proposed an adaptable chemotactic step size BFO in modeling a single-link flexible manipulator system. Based on an experimental single-link flexible manipulator rig, the input–output data have been collected and employed in establishing three single-input single-output models to characterize the system. As for Kalaam et al. [14], their study considered the implementation of bacterial foraging algorithm for optimizing multiple PI controllers’ design variables in a cascaded structure. Four proportional-integral (PI) controllers were employed for controlling a grid-connected photovoltaic (PV) system. Simulation results revealed that the optimized design values improved the system performance. The performance of utilizing bacterial foraging algorithm (BFO) on an intelligent fuzzy logic controller for a unicycle class of differential drive robot on an irregular rough terrain was investigated by Almeshal et al. [15]. Based on simulation results, the BFO algorithm improved the control method and a satisfactory convergence has been achieved. Nasir et al. [16] focused on improving the performance of BFO by proposing novel adaptive bacteria foraging algorithms based on index of iteration, index of chemotaxis, and fitness value to overcome the oscillations in the convergence graph caused by the constant step size and to speed up the convergence in the case of using small step size. The developed algorithms have been examined with multiple unimodal and multimodal standard benchmark functions. Considering different dimensions and fitness landscapes, simulation results revealed the outperformance of the developed algorithms based on convergence speed and fitness accuracy. On the other hand, Agouri et al. [17] proposed a control strategy for a two-wheeled robot with an extendable IB using quadratic adaptive bacterial foraging algorithm (QABFA). Nasir et al. [18] focused on improving the spiral dynamic algorithm by considering both elimination and dispersal phases of bacterial foraging algorithm. The improved SDA’s performance has been tested and implemented in fuzzy logic dynamic modeling of a twin rotor system. According to simulation results, the improved SDA converged to a far better solution compared to other implemented optimization algorithms. Considerable amount of research studies merged the concept of bacterial foraging algorithm with other algorithms and developed hybrid optimization algorithms [19, 21].

Overview and contribution

This paper presents a bacterial foraging technique for determining the optimal parameters of a PID controller to control the stability of a five degrees-of-freedom (DOF) two-wheeled machine (TWM) developed by Goher [22].

The novel 5-DOF TWM provides payload handling in two mutually perpendicular directions while attached to the IB. Compared to existing TWRMs, this design increases both workspace and flexibility of two-wheeled machines and allows them to be employed in service and industrial robotic applications including objects assembly and material handling. Bacterial foraging algorithm’s potential, as illustrated in the literature, was a source of encouragement to examine the proposed optimization technique on the novel 5 DOF two-wheeled machine’s controller in order to improve the system’s stability performance.

Paper organization

The rest of the paper is organized as follows: “Bacterial foraging optimization (BFO) algorithm” section presents an overview of the BFO algorithm and a rationale about the implementation on various nonlinear dynamic systems, the system description machine is presented in “TWRM system description,” and “System modeling” sections present the previously developed mathematical model using Lagrangian approach. “Control system design” section describes the control system design and the implementation of bacterial foraging optimization technique including various courses of motion and testing of the robustness of the control approach. At last, the main conclusions of the paper are presented in “Conclusions” section.


TWRM system description

Figure 1 illustrates the schematics diagram of the two-wheeled robotic machine (TWRM). The proposed system consists of a chassis with center of gravity at point P 1 and the mass of the linear actuators with center of gravity at point P 2. The coordinates of P 1 and P 2 will change as long as the robot maneuvers away from its initial position along the X axis. The two motors attached to each wheel are in charge of providing the necessary torque, \(\tau_{\text{R}}\) and \(\tau_{\text{L}}\), for controlling the TWRM. For enabling the control strategy to maintain the two-wheeled machine’s position at the upright position continuously, the system is equipped with both accelerometer and gyroscope sensors that provide multiple state variables information at any given time. The system design provides compactness with offering proper rooms for system electronics and accessories. Other targeted features include a lightweight structure without affecting the robot stiffness and a symmetrical mass distribution for the entire robot parts and components at initial position. With respect to the X and Z axes, four types of translations define the system’s DOFs: the attached payload linear displacement in vertical and horizontal directions \(h_{1}\) and \(h_{2}\), respectively, and the angular displacement of the angular rotation of the right and left wheels \(\delta_{\text{R}}\) and \(\delta_{\text{L}}\), respectively. The tilt angle \(\theta\) of the intermediate body around the vertical Z axis is considered as the fifth remaining DOF. Consider a picking up and placing scenario, as an application of the proposed configuration, with the vehicle’s course of motion illustrated in Fig. 2.

Fig. 1
figure 1

System schematic diagrams

Fig. 2
figure 2

TWRM courses of motion

The activation of each of the TWRM actuators against each subtask and the DOFs involved in each process, for the previously mentioned picking and placing scenario, is illustrated in Table 2. Due to the continuous variation in the location of the center of mass (COM) as well as the external disturbances taking place during the picking and/or placing the object task, the system wheels’ motors remain activated during the whole process. Developing a sufficient torque signal from both wheels’ motors is mandatory for maintaining the balancing of the TWRM in the upright vertical position. As for the linear actuators, activating them counts on the selected subtask (i.e., picking, placing, both tasks). As a main part of the control algorithms, switching mechanisms are designed to define the period of engagement of each individual actuator in service.

Table 2 Subtasks against engagement of individual actuators

System modeling

Among the diverse methods of deriving the equations of motion, and due to the fact that it is a powerful approach, Lagrangian modeling approach is employed to model the TWRM. Based on the system schematic diagrams illustrated earlier, the vehicle’s mathematical model is derived by relating the system’s kinematics to the torques/forces applied (details of the model derivation can be found in the work of Goher [22]). The system’s mathematical model is presented as five nonlinear-coupled differential equations as follows:

For the vertical linear link displacement (\(h_{1}\)):

$$\frac{1}{2}m_{2} \left( {2g\cos \theta - 2h_{1} \dot{\theta }^{2} - 4\dot{h}_{2} \dot{\theta } - 2h_{2} \ddot{\theta } + 2\ddot{h}_{1} + (\ddot{\delta }_{\text{R}} + \ddot{\delta }_{\text{L}} )\sin \theta } \right) = F_{1} - \mu_{1} \dot{h}_{1}$$

For the horizontal link displacement (\(h_{2}\)):

$$\frac{1}{2}m_{2} \left( {2g\sin \theta + 2h_{2} \dot{\theta }^{2} - 4\dot{h}_{1} \dot{\theta } - 2h_{1} \ddot{\theta } - 2\ddot{h}_{2} - (\ddot{\delta }_{\text{R}} + \ddot{\delta }_{\text{L}} )\cos \theta } \right) = F_{2} - \mu_{2} \dot{h}_{2}$$

For the angular displacement of the left wheel (\(\delta_{\text{L}}\)):

$$\frac{1}{2}m_{1} \left( {\frac{1}{2}\ddot{\delta }_{\text{R}} + \frac{1}{2}\ddot{\delta }_{\text{L}} - l\dot{\theta }^{2} \sin \theta + l\ddot{\theta }\cos \theta } \right) + \frac{1}{2}m_{2} \left( {\ddot{h}_{1} \sin \theta + 2\dot{h}_{1} \dot{\theta }\cos \theta - h_{1} \dot{\theta }^{2} \sin \theta + h_{1} \ddot{\theta }\cos \theta + \ddot{h}_{2} \cos \theta - 2\dot{h}_{2} \dot{\theta }\sin \theta - h_{2} \dot{\theta }^{2} \cos \theta - h_{2} \ddot{\theta }\sin \theta + \frac{1}{2}\ddot{\delta }_{\text{R}} + \frac{1}{2}\ddot{\delta }_{\text{L}} } \right) + 2m_{\text{w}} \ddot{\delta }_{\text{L}} + 2J_{\text{w}} \frac{{\ddot{\delta }_{\text{L}} }}{{R^{2} }} = \tau_{\text{L}} - \mu_{\text{w}} \left( {\frac{{\dot{\delta }_{\text{L}} }}{{R^{2} }}} \right) - \mu_{\text{c}} \dot{\delta }_{\text{L}}$$

For the angular displacement of the right wheel (\(\delta_{\text{R}}\)):

$$\frac{1}{2}m_{1} \left( {\frac{1}{2}\ddot{\delta }_{\text{R}} + \frac{1}{2}\ddot{\delta }_{\text{L}} - l\dot{\theta }^{2} \sin \theta + l\ddot{\theta }\cos \theta } \right) + \frac{1}{2}m_{2} \left( {\ddot{h}_{1} \sin \theta + 2\dot{h}_{1} \dot{\theta }\cos \theta - h_{1} \dot{\theta }^{2} \sin \theta + h_{1} \ddot{\theta }\cos \theta + \ddot{h}_{2} \cos \theta - 2\dot{h}_{2} \dot{\theta }\sin \theta - h_{2} \dot{\theta }^{2} \cos \theta - h_{2} \ddot{\theta }\sin \theta + \frac{1}{2}\ddot{\delta }_{\text{R}} + \frac{1}{2}\ddot{\delta }_{\text{L}} } \right) + 2m_{\text{w}} \ddot{\delta }_{\text{R}} + 2J_{\text{w}} \frac{{\ddot{\delta }_{\text{R}} }}{{R^{2} }} = \tau_{\text{R}} - \mu_{\text{w}} \left( {\frac{{\dot{\delta }_{\text{R}} }}{{R^{2} }}} \right) - \mu_{\text{c}} \dot{\delta }_{\text{R}}$$

For the tilt angle of the intermediate body (\(\theta\)):

$$2m_{2} \dot{\theta }(\dot{h}_{2} h_{2} + \dot{h}_{1} h_{1} ) + \frac{1}{2}m_{2} (h_{1} \cos \theta - h_{2} \sin \theta )(\ddot{\delta }_{\text{R}} + \ddot{\delta }_{\text{L}} ) + \frac{1}{2}m_{1} l\cos \theta (\ddot{\delta }_{\text{R}} + \ddot{\delta }_{\text{L}} ) - m_{2} g(h_{1} \sin \theta + h_{2} \cos \theta ) + \ddot{\theta }\left( {J_{1} + J_{2} + m_{1} l^{2} + m_{2} h_{2}^{2} + m_{2} h_{1}^{2} } \right) + 2m_{2} h_{1} h_{2} - m_{1} gl\sin \theta = 0$$

Control system design

In the previous section, the TWRM equations of motion have been developed. This section focuses on testing the derived model to obtain its response and to manage to control it by implementing and comparing between different control strategies for the purpose of obtaining a satisfactory response for the system. Examining the behavior of the developed model for the TWRM requires investigating the system’s open-loop response. The derived model is simulated in MATLAB/Simulink® environment by utilizing the simulation parameters shown in Table 3. In a previous study conducted by Goher [22], it was revealed that the system response is unstable nonlinear system. Based on that, a closed-loop system is substantial for stabilizing the TWRM and improving the system’s performance. In this work, five decoupled feedback control loops have been used throughout the work. The developed control strategy, based on loops decoupling, ensures separation of the system dynamics due to the high frequency range (tilt angle) from the dynamics of low frequency range (motion of the intermediate body). The two feedback control loops occupy separate ranges of dynamics, low frequency and high frequency with tilt angle over higher frequency range and motion of intermediate body over lower frequency range, and hence, the decoupling approach is reasonable to use and apply separate control loops.

Table 3 System simulation parameters

The friction at the mating surfaces has been simplified for the chassis–wheel, wheel–ground interaction and in the linear actuator to follow Coulomb frictional model. The values of the coefficients have been selected depending on the type of surfaces. The selected constant values are assumed to be valid under all working conditions of the vehicle and the actuators. This did not take into account variations in speed, path configuration, terrain profile, etc. The constant values have been used to validate the system model. However, modeling interactions between surfaces need to be investigated for various surfaces, various terrain profiles, and various operation conditions of the vehicle.

BFO-optimized PID control design

In this part, bacterial foraging optimization technique is applied on the system in order to optimize the PID controller gains employed in a previous research study [22] by maintaining the system in the upright position and to counteract the disturbances occurring in different motion scenarios.

Optimization algorithm objective functions and constraints

The most critical step in applying optimization techniques is to choose the objective functions that are used to evaluate fitness function. The objective functions can be created using performance indices functions to evaluate the errors of the controlled loops. These performance indices used to optimize the errors of the system are: mean of the squared error (MSE), integral of time multiplied by absolute error (ITAE), integral of absolute magnitude of the error (IAE), integral of the squared error (ISE), and time multiplied by the squared error (ITSE) to minimize the error signals and compare them to find the most suitable one [23]. The TWRM’s bacterial foraging-optimized PID control scheme schematic description is demonstrated in Fig. 3. Figure 4 shows the MATLAB/Simulink model of the PID controller optimized by BFO built to determine the errors using Eqs. (6)–(10). The optimized PID controller is used to minimize the error signals by minimizing the value of the objective functions of performance indices defined as follows:

$${\text{MSE}} = \frac{1}{t}\int\limits_{0}^{\tau } {\left( {e(t)} \right)^{2} } {\text{d}}t,$$
$${\text{ITAE}} = \int\limits_{0}^{\tau } {t\left| {e(t)} \right|} {\text{d}}t,$$
$${\text{IAE}} = \int\limits_{0}^{\tau } {\left| {e(t)} \right|} {\text{d}}t,$$
$${\text{ISE}} = \int\limits_{0}^{\tau } {e(t)^{2} } {\text{d}}t,$$
$${\text{ITSE}} = \int\limits_{0}^{\tau } {te(t)^{2} } {\text{d}}t,$$

where e(t) is the error signal in time domain.

Fig. 3
figure 3

TWRM’s BFO-optimized PID control scheme

Fig. 4
figure 4

Simulink® model of the BFO-optimized PID controller

Results and Discussions

Implementation of BFO-PID algorithm

The behavior of the robotic machine was observed for the tilt angle of the entire vehicle, angular displacements of the two wheels, and linear displacements of the linear actuators using different motion scenarios.

Payload free motion (h 1 = h 2 = 0)

Figure 5a, b demonstrates the simulation results of the system performance and inputs control signals. The system is considered to start initially at \(\theta = - 5^\circ\) and neglecting the effect of both linear actuators, \(h_{1}\) and \(h_{2}\), by setting them to zero during the system stabilization. Table 4 summarizes the performance of the system by determining the overshoot, settling time, rise time, and peak time values of each methods of error determinations. PID controller optimized by MSE gives a value of 46.6% of overshoot which is the biggest value for the overshoot, followed by 34.8% overshoot value for ITSE. The controller optimized by IAE gives the best value with minimum overshoot, 27.9%, where ISE and ITAE give good overshoot percentages for 33.8 and 29.3%, respectively. In summary, it is clear that BFO reduces the percent overshoot, especially if optimized by IAE criterion. As for settling time, it can be seen that the settling time values of BFO vary in the range of 0.78 s for IAE to 1.87 s for BFO optimized by MSE. The best method to optimize the settling time is by using the IAE. From Table 4, the best rise time is given by MSE (0.19 s) and the worst one is ITAE (0.248 s). All other BFO methods produce almost the same value. But because BFO results are not so different, it cannot be concluded that BFO can optimize the rise time. As in rise time values, the peak time values show almost the same values for all methods with small variation between them. All other BFO error methods produce peak time between 0.35 and 0.46 s. The best values are given by BFO optimized by MSE and ISE, 0.35 s. In short, the best optimized PID controller employed is the one optimized by IAE for the low percent overshoot and minimum settling time.

Fig. 5
figure 5

System outputs and inputs (h 1 = h 2 = 0). a System outputs, b system inputs

Table 4 System performance using different performance indices

Payload vertical movement only

In addition, the system stability was examined for each BFO optimization criterion against the vertical linear motion of its center of mass. Considering the following initial conditions: \(\theta = - \;5^\circ\), \(h_{1} = 0.28\,{\text{m}}\) and neglecting the effect of the horizontal linear actuators \(h_{2}\), Fig. 6 demonstrates outputs and inputs simulation of the system in the case where the payload is kept fixed for a period of 12 s from the start of the simulation and then activated to move in a vertical direction along the IB for a distance of 10 cm before settling again at a height of around 38 cm from the chassis of the vehicle. It is clear, since no disturbance occurred in the stabilization condition of the IB, that the control scheme was robust and maintained the system’s stability against the motion of \(h_{1}\). Out of the five methods, the BFO optimized by IAE performed better than the other methods.

Fig. 6
figure 6

System outputs and inputs, payload vertical movement only. a System outputs, b system inputs

Payload horizontal movement only

For completing the picking/placing handling task, the TWRM is allowed to transfer the picked payload in a horizontal direction parallel to the chassis’ axis. Figure 7 illustrates the output response of the system with moving the horizontal linear actuator only and its effects on the performance of the system stability. The carried load is kept stationary at a height of 28 cm. As for the horizontal actuator, it is permitted to orient horizontally for a distance of 7 cm before settling again at a fixed position. The model’s initial conditions are set as follows: \(\theta = 5^\circ\), \(h_{1} = 0.28\,{\text{m}}\), and \(h_{2} = 0\,{\text{m}}\). As can be seen from this scenario’s simulation results, for the MSE and ITAE criterion, the system stability was affected by the activation of the horizontal actuator and the TWRM keeps moving instead of maintaining its position. On the other hand, the remaining methods produce better performance and good robust against the movement of the horizontal actuator.

Fig. 7
figure 7

System outputs and inputs, payload horizontal movement only. a System outputs, b system inputs

Simultaneous vertical and horizontal motion (h 1 and h 2 ≠ 0)

Figure 8a, b demonstrates the system’s output response with moving the two linear actuators simultaneously and their effects on the system’s stability performance. The initial conditions are set to \(\theta = - \;5^\circ\), \(h_{1} = 0.28\,{\text{m}}\), and \(h_{2} = 0\,{\text{m}}\). The system, without any interruptions, remains stable during the operation of initiating the vertical linear actuator. However, once the horizontal actuator starts to extend its rod, for both MSE and ITAE criterions, the system stability was affected and the TWRM wheels keep maneuvering instead of preserving its position. This issue did not appear in the remaining methods’ simulation results and produced good robust and better performance. Another phenomenon has been noticed, while the horizontal actuator activates. The IB tilts to the opposite direction of the horizontal actuator’s extension with a steady inclination angle of around \(7^\circ\) for withstanding the change in the COM’s position.

Fig. 8
figure 8

System outputs and inputs (h 1 and h 2 ≠ 0). a System outputs, b system inputs

Trajectory of a 1-m straight-line motion

The system stability was examined during moving the TWRM in a straight line for 1 m after balancing the robot in the upside position, and the simulation results are shown in Fig. 9. Referring to Fig. 9a, the control scheme, including the five tested criterions, was capable to counter the occurred disturbances caused by the wheels’ motors’ activation at the beginning (8 s) and the end (18 s) of the straight-line motion. As can be observed in Fig. 9b, the maximum control effort spent for maneuvering the system in a 1-m straight-line trajectory, compared to the other criterions, was noted for the ITSE method, around 1.8 N.

Fig. 9
figure 9

System outputs and inputs, 1-m straight-line motion. a System outputs, b system inputs

Control system robustness

Moreover, the system stability was examined against the effect of disturbance forces illustrated in Fig. 10a and the simulation results are shown in Fig. 10b, c. As it is shown that disturbance force affects the system, but the controller reacts against this force to stabilize the system. However, the controller resulted from MSE shows that the displacement of the system is effected with slight change, while the other optimized controllers show better performance.

Fig. 10
figure 10

System outputs and inputs, with disturbance force. a The applied disturbance, b system outputs, c system inputs

Comparison between implementation of PID and BFO-optimized PID

The boundary limits of the controller gain parameters for each loop that were applied in MATLAB/Simulink environment were obtained by trial and error. In this section, the authors carry out a comparison of the system response based on the implementation of two approaches. The control gain parameters employed in each control loop for the control schemes in order to achieve a satisfactory system performance are listed in Table 5.

Table 5 Gain values for different control schemes

For the following cases, payload free movement, payload vertical movement only, payload horizontal movement only, simultaneous horizontal and vertical motion, and 1-m straight-line vehicle motion, Figs. 11, 12, 13, 14, and 15 demonstrate the output results of the simulated TWRM model and the applied control effort. It is clear, from the previous figures, that the optimized controller by BFO provides better performance for the system and minimizes the applied force demanded for the TWRM stabilization process. Observing the payload free movement (h 1 = h 2 = 0) scenario, as an example of how the BFO-optimized PID controller performance is better way than the PID, Table 6 illustrates a system performance comparison between the previously mentioned controllers in terms of overshoots, settling time, peak time, and rise time.

Fig. 11
figure 11

System outputs and inputs, payload free movement (h 1 = h 2 = 0). a System outputs, b system inputs

Fig. 12
figure 12

System outputs and inputs, payload vertical movement only. a System outputs, b system inputs

Fig. 13
figure 13

System outputs and inputs, payload horizontal movement only. a System outputs, b system inputs

Fig. 14
figure 14

System outputs and inputs, simultaneous vertical and horizontal motion (h 1 and h 2 ≠ 0). a System outputs, b system inputs

Fig. 15
figure 15

System outputs and inputs, a 1-m straight-line motion. a System outputs, b system inputs

Table 6 Comparison between the system’s performance using PID and BFO

Starting with system overshoot, the BFO-optimized PID control scheme provides better overshoot value (27.9%), which is much less than the PID-recorded overshoot value by almost 42%. Moving to settling time, it is observable that by implementing the PID control strategy the system takes around 2.3 s to settle, which is greater than the BFO-optimized PID control method’s settling time (0.78 s). Therefore, the BFO-optimized PID control strategy optimizes the settling time. As in peak and rise time values, a slight reduction has been noticed when the BFO-optimized PID control method is implemented on the TWRM model and it can be concluded that the BFO-based method produces both peak and rise time values better than the PID controller.

From the scenarios where the horizontal linear actuator activates, payload horizontal movement only case (Fig. 13) and simultaneous horizontal and vertical motion case (Fig. 14), the issue of the TWRM’s continuous movement that results from the activation of the horizontal actuator has been compensated by the implementation of bacterial foraging algorithm. For the response associated with the PID control scheme, the activation of the horizontal actuator affects the system’s stability and allows the TWRM to move 10 cm away from its original location (\(\delta_{\text{R}}\) = −0.1 m, \(\delta_{ \, }\) = −0.1 m). However, the BFO-optimized PID controller produces a satisfactory performance and robustness against the horizontal linear actuator’s movement. In general, the BFO-optimized PID control method produces much better system performance and optimized behavior than PID control scheme, where the optimum controller values are resultant from the IAE criterion.

Investigating control system robustness

Considering the same disturbance force applied earlier on the system, shown in Fig. 10a, the system’s robustness was examined for the two control methods and the performance of the system is demonstrated in Fig. 16. As can be observed, for both control methods and in few seconds, the system bounced back to its stability region around the vertical axis. However, the PID performance was not sufficient to withstand the effect of disturbance on the TWRM wheels’ displacement (\(\delta_{R}\), \(\delta_{L}\)) and the horizontal linear actuator displacement (h 2). As a matter of fact, the bacterial foraging-optimized PID control method surpassed the PID control scheme in terms of performance, robustness, and instability minimization.

Fig. 16
figure 16

System outputs and inputs with a disturbance. a System outputs, b system inputs

The upper and lower boundaries, shown in Table 5, are associated with the BFO-optimized control scheme with switching mechanism. Those parameters are required by the BFO algorithm in order to calculate the optimal gain values.


A bacterial foraging optimization algorithm for determining the optimal parameters of PID controller employed for controlling the stability of a novel five DOF two-wheeled robotic machine has been presented in this paper. Lagrangian approach has been utilized for deriving the TWRM’s nonlinear mathematical model that has been simulated in MATLAB/Simulink® environment. Furthermore, the stability of the two-wheeled machine was examined against different motion scenarios which include payload free movement, payload vertical movement only, payload horizontal movement only, simultaneous horizontal and vertical motion, and 1-m straight-line vehicle motion. In addition, the system’s stability was examined against disturbance forces to examine the controller robustness. It is clear that the bacterial foraging optimization applied in PID controller improves the system performance compared to the PID method. This was visualized by the reduction in the rise time, settling time, and percent overshoot. Further studies will consider implementing and comparing between various optimization techniques [i.e., particle swarm optimization algorithm, spiral dynamics algorithm, genetic algorithm] for optimizing the 5 DOF TWM’s PID controller gains in order to obtain the optimum control scheme that provides the best system stabilization performance.


  1. Lee J, Shin H, Lee S, Jung S. Mechatronics balancing control of a single-wheel inverted pendulum system using air blowers: evolution of mechatronics capstone design. Mechatronics. 2013;23(8):926–32.

    Article  Google Scholar 

  2. Chinnadurai G, Ranganathan H. IOT controlled two wheel self supporting robot without external sensor. Middle-East J Sci Res (Sens Signal Process Secur). 2015;23:286–90.

    Google Scholar 

  3. Goher KM, Tokhi O. Balance control of a TWRM with a dynamic payload. In: Proceedings of the 11th international conference on climbing and walking robots and the support technologies for mobile machines, Coimbra, Portugal; 2008.

  4. Almeshal A, Goher KM, Tokhi M. Dynamic modelling and stabilization of a new configuration of two-wheeled machines. Robot Auton Syst. 2013;61(5):443–72.

    Article  Google Scholar 

  5. Chan R, Stol K, Halkyard C. Review of modelling and control of two-wheeled robots. Annu Rev Control. 2013;37(1):89–103.

    Article  Google Scholar 

  6. Olivares M, Albertos P. Linear control of the flywheel inverted pendulum. ISA Trans. 2014;53(5):1396–403.

    Article  Google Scholar 

  7. Sun J, Li Z. Development and Implementation of a wheeled inverted pendulum vehicle using adaptive neural control with extreme learning machines. Cogn Comput. 2015;7(6):740–52.

    Article  Google Scholar 

  8. Vinodh Kumar E, Jerome J. Robust LQR controller design for stabilizing and trajectory tracking of inverted pendulum. Proc Eng. 2013;64:169–78.

    Article  Google Scholar 

  9. Kennedy J, Eberhart R. Particle swarm optimization. In: Proceedings of the IEEE international conference on neural networks, vol 4, Perth, WA; 1995, p. 1942–48.

  10. Tamura K, Yasuda K. Primary study of spiral dynamics inspired optimization. IEEJ Trans Electr Electron Eng. 2011;6(S1):98–100.

    Article  Google Scholar 

  11. Goldberg D. Genetic algorithms in search, optimization, and machine learning. Reading: Addison-Wesley; 1989.

    MATH  Google Scholar 

  12. Passino K. Biomimicry of bacterial foraging for distributed optimization and control. Proc IEEE Control Syst Mag 2002;22:52–67.

    Article  Google Scholar 

  13. Supriyono H, Tokhi M. Parametric modelling approach using bacterial foraging algorithms for modelling of flexible manipulator systems. Eng Appl Artif Intell. 2012;25(5):898–916.

    Article  Google Scholar 

  14. Kalaam R, Hasanien HM, Al-Durra A, Al-Wahedi K, Muyeen SM. Optimal design of cascaded control scheme for PV system using BFO algorithm. In: International conference on renewable energy research and applications (ICRERA), Palermo; 2015, p. 907–12.

  15. Almeshal A, Goher K M, Alenezi M, A Almazeed, J Almatawah, Moaz M. BFA optimized intelligent controller for path following unicycle robot over irregular terrains. Int J Curr Eng Technol. 2015;5(2):1199–204.

    Google Scholar 

  16. Nasir A, Tokhi M, Ghani N. Novel adaptive bacterial foraging algorithms for global optimisation with application to modelling of a TRS. Expert Syst Appl. 2015;42(3):1513–30.

    Article  Google Scholar 

  17. Agouri S, Tokhi M, Almeshal A, Goher KM. BFA optimisation of control parameters of a new structure two-wheeled robot on inclined surface. Paper presented at the nature-inspired mobile robotics: proceedings of the 16th international conference on climbing and walking robots and the support technologies for mobile machines, CLAWAR 2013; 2013, p. 189–96.

  18. Nasir A, Tokhi M, Omar M, Ghani N. An improved spiral dynamic algorithm and its application to fuzzy modelling of a twin rotor system. In: 2014 world symposium on computer applications & research (WSCAR); 2014, p. 1–6.

  19. Nasir A, Tokhi M, Ghani N. Novel hybrid bacterial foraging and spiral dynamics algorithms. In: 13th UK workshop on computational intelligence (UKCI), Guildford; 2013, p. 199–205.

  20. Nasir A, Tokhi M. A novel hybrid bacteria-chemotaxis spiral-dynamic algorithm with application to modelling of flexible systems. Eng Appl Artif Intell. 2014;33:31–46.

    Article  Google Scholar 

  21. Almeshal A, Goher K, Nasir A, Tokhi M, Agouri S. Fuzzy logic optimized control of a novel structure two-wheeled robotic vehicle using HSDBC, SDA and BFA: a comparative study. In: 18th international conference on methods and models in automation and robotics (MMAR); 2013, p. 656–61.

  22. Goher KM. A two-wheeled machine with a handling mechanism in two-different directions. Robot Biomim. 2016;3(17):1–22. doi:10.1186/s40638-016-0049-8.

    Google Scholar 

  23. O’Mahony T, Downing CJ, Fatla K. Genetic algorithms for PID parameter optimisation: minimising error criteria. 2000. Accessed 19 Mar 2017.

Download references

Authors’ contributions

KMG initiated the concept of two-wheeled machine with the two-directional handling mechanism. He derived the mathematical model in the linear and nonlinear forms. KMG simulated the system model and designed and implemented the control approach. SOF helped in writing the final format of the paper and analyzing and interpreting the results. Both authors read and approved the final manuscript.


The authors of this paper would like to thank Sultan Qaboos University in Oman for hosting the initial stage of this research.

Competing interests

The authors declare that they have no competing interests.


This research has been funded by Sultan Qaboos University (Oman) and Lincoln University (NZ).

Author information

Authors and Affiliations


Corresponding author

Correspondence to K. M. Goher.

Rights and permissions

Open Access This article is distributed under the terms of the Creative Commons Attribution 4.0 International License (, which permits unrestricted use, distribution, and reproduction in any medium, provided you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license, and indicate if changes were made.

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Goher, K.M., Fadlallah, S.O. Bacterial foraging-optimized PID control of a two-wheeled machine with a two-directional handling mechanism. Robot. Biomim. 4, 1 (2017).

Download citation

  • Received:

  • Accepted:

  • Published:

  • DOI: