1 Introduction

Overhead cranes are used repeatedly in different industrial applications to transport huge loads in horizontal (moving) and vertical (lifting) directions. It applies to civil construction, metallurgical production, rivers, and seaports. It provides ascent or descent of cargoes and their distance shifting using hoisting and traveling devices [1]. The parts of the overhead crane system consist of the following parts:

  1. 1.

    Trolley (the main part of the crane which contains the driving motor),

  2. 2.

    Girder (the guide for traversing motion),

  3. 3.

    Traveler (the guide for traveling motion),

  4. 4.

    Cable (used in lifting and lowering motion which contains a hook) and

  5. 5.

    Load to be lifted/payload/.

Figure 1 presents the structure of a three-dimensional industrial overhead crane system and its schematic representation [2]. Overhead cranes attain three different motions: Traversing, Traveling, and Hoisting/Lowering. Transporting the loads quickly to the desired position without oscillation or swing is the primary goal of the controlling unit. In transporting loads, the rope length and lifted load mass often change accordingly due to transportation tasks. Due to this, the oscillation was quickly created in the system while lifting the load horizontally. The motion of the trolley, the length of the cable, the load to be lifted, and external interferences such as friction and wind force will affect the swinging motion and positioning performance of the control system for the crane. Therefore, it is necessary to design a controller that can reduce or suppress the uncertainty of the system.

Fig. 1
figure 1

(a) Industrial overhead structure (b) schematic representation of the 3D overhead crane

Optimization tool applied by researchers to non-linear model predictive controller [3], new variable structure control using meta‐heuristics algorithms for frequency regulation [4], Energy Management of Controllable Loads New Supervisor Fuzzy Nonlinear Sliding Mode Control [5] and Predictive Controller for LFC of Nonlinear Multi-area Power System with Energy Storage Devices [6].

Moreover, many researchers tried to overcome the problem by designing different effective and efficient controlling systems. The modeling and control of the swinging effect of the three-dimensional overhead crane using state feedback control in discrete time to obtain high-performance swinging motion at high speed have been studied [7]. A detailed review of the control strategies of cranes (2000–2016) was conducted [8]. In their paper, they have presented the different methods used for controlling the crane. A new anti-swing control scheme has been designed [9], based on the Lyapunov stability theorem, consisting of a feed-forward control and a non-linear PID control with gravity compensation. Partial feedback linearization control, which uses a swing-suppressing element, has been developed and checked experimentally for anti-swing control of overhead cranes [10]. Anti-sway control using PID controller has been investigated [11], and the development and management of Gantry Crane System using the Robust and State feedback controllers [12]. In addition, the study of the feedback control system investigated by researchers [13, 14], and real-time trajectory control of an overhead crane using servo-constraints [15], and the optimal performance control mechanisms by optimizing the control parameters [16].

Furthermore, the effects of external disturbances and time-varying parameters on a flexible system have been studied [17]. The control system was designed based on the adaptive feedback control and predictive unity magnitude shaper system using the NNUMZV-APIDLNN algorithm. Moreover, some researchers present the study of the Fuzzy and LQR-PID controllers for anti-swing control of overhead cranes [18], the Harmony Search radial basis function neural network algorithm for optimal anti-swing motion trajectory [19], the differential evolution (DE) algorithm based fuzzy logic for PID optimal parameters [20], the PSO algorithm for PID-PD parameters optimization [21], and the Riccati discrete-time transfer matrix method of a multibody system (MS-RDTTMM) for control design of overhead motion [22].

Despite the PID controller, some researchers apply the Fuzzy logic controller to overcome the motion of cranes. [23] studied the application of a Fuzzy logic controller (FLC) fewer rules for moving the overhead crane in the desired way by ensuring swing-free payload motion. A two-rule base FLC, one for displacement control, the other for swing control, was designed and implemented. The FLC result shows that the motion of the overhead crane is smooth, and the control result shows no overshoot.

An alternative method for studying the dynamic model and anti-swing motion control of two-dimensional overhead cranes was proposed by [22]. The paper describes an efficient method called the Riccati discrete-time transfer matrix of a multibody system (MS-RDTTMM). Then, positioning and anti-swing control use three separate fuzzy logic controllers. In addition, tuning the initial control parameters uses a Genetic Algorithm. The result shows that the computational efficiency, numerical stability, and control performance are greatly improved.

Shao et al. [24] investigate the non-linear and uncertainty of the dynamic model of the overhead crane with Takagi–Sugeno (T–S) fuzzy modeling and PSO-based robust linear quadratic regulator (LQR). In addition to [25], the comparative analysis of Neural-Network and Fuzzy Auto-Tuning sliding mode controls overhead cranes under payload and cable variations. The proposed control methods are simple, feasible, and robust—finally, a series of numeral simulations for testifying the effectiveness of the methods.

This work aimed to develop a mathematical model using Lagrange’s equation of motion. Then the motion of the overhead crane is controlled using a PID controller and a fuzzy logic controller. The PID controller parameters are optimized using the Bees Algorithm and GA. The paper has four sections: the introduction presets previous works in the area and the objectives of the current work, and then the mathematical modeling and the design of PID control in the method part. The results of optimization, PID controller, and fuzzy logic controller are in the result section, and finally, in the last section, the conclusion is presented.

2 Method

2.1 The mathematical model of overhead crane

The schematic representation of a two-dimensional overhead crane system is shown in Fig. 2, assuming only two-dimensional motions (i.e., vertical and horizontal motions). Here, \({\text{F}}_{{\text{t}}} -\) represents the actuating force acted on the trolley by the motor; \({\text{x}} -\) is the horizontal position of the trolley; \({\text{x}}_{{\text{l}}} {\text{ and y}}_{{\text{l}}} -\) are the horizontal and vertical positions of the load to be lifted, respectively. \({\text{m}}_{{\text{t}}}\) and \({\text{m}}_{{\text{l}}} -\) are the mass of the trolley and the load, respectively;\({\text{l}} -\) is the length of the cable; \({\uptheta } -\) is the swing angle of the load; and \({\text{g}} - { }\) denote the gravitation acceleration.

Fig. 2
figure 2

The schematic representation of a two-dimensional overhead crane system. Where, \({\text{m}}_{{\text{t}}} -\) mass of a trolley, \({\text{m}}_{{\text{l}}} -\) mass of the load to be lifted, \({\text{l}} -\) length of hoisting cable, \({\text{B}}_{{\text{t}}} - { }\) Viscous damping Coefficient of friction of the trolley, \({\text{B}}_{{\text{l}}} -\) Viscous damping coefficient of friction of the lifted load, \({\uptheta } -\) swinging angle, \({\dot{\theta }} -\) angular velocity of the load, \({\text{x}} -\) position of the trolley, \({\dot{\text{x}}} -\) the linear velocity of the trolley, \({\text{ x}}_{{\text{l}}} -\) x- Coordinate position of the lifted load, \({\text{y}}_{{\text{l }}} -\) y-coordinate position of the lifted load, \({\text{F}}_{{\text{t}}} -\) Trolley Control force

Assumptions used in the development of mathematical equations:

  • The motion of the overhead crane is limited to only two-dimensional motion. The third motion is ignored from analysis because the crane can move either traversing or traveling motion at a time.

  • The deflection of the girder beam is not considered in this study and is assumed to be rigid.

  • The mass and deflection of the cable are also assumed to be very small and neglected. Thus, the length of the rope remains constant during the moving process of the trolley.

  • The external effects: friction, wind effects on both trolley and load were considered in this study, as shown in Fig. 2.

  • By assuming the swinging angle as minimal, the approximation of trigonometric functions \({\text{sin}} {{\uptheta }} \approx {\uptheta },{\text{ cos}} {{\uptheta }} \approx 1,{{ \uptheta \dot{\uptheta }}}^{2} \approx 0.\), is applied.

  • The load to be lifted and the trolley is assumed to be a point mass.

Thus, to drive the equation of motion of the given system, let us use the generalized Euler–Lagrange equation:

$$\frac{{\text{d}}}{{{\text{dt}}}}\left( {\frac{{{\text{d}}{\mathcal{L}}}}{{\partial {\dot{\text{q}}}_{{\text{i}}} }}} \right) - \frac{{{\text{d}}{\mathcal{L}}}}{{\partial {\text{q}}_{{\text{i}}} }} = {\text{Q}}_{{\text{i}}} ,\quad {\text{where i}} = 1,{ }2{ }$$
(1)
$${\text{q}}_{1} = {\text{x}},{\text{ q}}_{2} = {\uptheta },{ } {\text{Q}}_{1} = {\text{Q}}_{{\text{x}}} ,{\text{ Q}}_{2} = {\text{Q}}_{{\uptheta }} ,{ } {\mathcal{L}} = {\text{T}} - {\text{U}}$$
(2)
$${\mathcal{L}} - {\text{lagrange}^{\prime}{\text{s\, Parameter}}}$$
$${\text{T}} = \frac{1}{2}{\text{mv}}^{2} - {\text{the kinetic energy}}$$
(3)
$${\text{U}} = {\text{mgh}} + \frac{1}{2}{\text{kx}}^{2} - {\text{the potential energy}}$$
(4)

Thus, the two kinetic energy equations of the 2D overhead crane system are the kinetic energy of the trolley in Eq. 5 and the kinetic energy of the lifted load in Eq. 6.

$${\text{T}}_{1} = \frac{1}{2}{\text{m}}_{{\text{t}}} {\dot{\text{x}}}^{2} { }$$
(5)
$${\text{T}}_{2} = \frac{1}{2}{\text{m}}_{{\text{l}}} {\dot{\text{x}}}_{{\text{l}}}^{2} + \frac{1}{2}{\text{m}}_{{\text{l}}} {\dot{\text{y}}}_{{\text{l}}}^{2}$$
(6)

From the geometry of the given system, the position and the velocity are:

$${\text{x}}_{{\text{l}}} = {\text{x}} + {\text{l}}\sin \uptheta ,\quad {{\dot{\rm x}}}_{{\text{l}}} = {{\dot{\rm x}}} + \dot{\uptheta }{\text{l}}\cos \uptheta$$
(7)
$${\text{y}}_{{\text{l}}} = - {\text{l}}\cos \uptheta ,\quad \dot{y}_{{\text{l}}} = \dot{\uptheta }{\text{l}}\sin \uptheta$$
(8)
$${\text{T}}_{2} = \frac{1}{2}{\text{m}}_{{\text{l}}} {{\dot{\text x}}}_{{\text{l}}}^{2} + \frac{1}{2}{\text{m}}_{{\text{l}}} {{\dot{\text y}}}_{{\text{l}}}^{2} = \frac{1}{2}{\text{m}}_{{\text{l}}} \left( {\left( {{{\dot{\text x}}} + {{\dot{\uptheta }{\text {lcos}}\uptheta }}} \right)^{2} + \left( {{{\dot{\uptheta }{\text {lsin}}\uptheta }}} \right)^{2} } \right)$$
(9)

Moreover, the potential energy of the system is:

$${\text{U}} = - {\text{m}}_{{\text{l}}} {\text{glcos}}{{\uptheta }}$$
(10)

The determination of Lagrange’s Parameter requires the substitution of Eqs. (9, 10) into Eq. (2):

$${\mathcal{L}} = \frac{1}{2}\left( {{\text{m}}_{{\text{t}}} + {\text{m}}_{{\text{l}}} } \right){\dot{\text{x}}}^{2} + {\text{m}}_{{\text{l}}} {{{\rm l}\dot{x}\dot{\uptheta }{\text {cos}}\uptheta }} + \frac{1}{2}{\text{m}}_{{\text{l}}} {\text{l}}^{2} {\dot{\uptheta }}^{2} + {\text{m}}_{{\text{l}}} {\text{glcos}}{{\uptheta }}$$
(11)

The partial derivatives of Lagrange’s Parameters are:

$$\frac{{{\text{d}}{\mathcal{L}}}}{{\partial {{\dot{\text x}}}}} = {{\dot{\text x}}}\left( {{\text{m}}_{{\text{t}}} + {\text{m}}_{{\text{l}}} } \right) + \dot{\uptheta }{\text{m}}_{{\text{l}}} {\text{lcos}}\uptheta {\text{,}}\,\frac{{{\text{d}}{\mathcal{L}}}}{{\partial \dot{\theta }}} = {{\dot{\text x}{\text {m}}}}_{{\text{l}}} {{\text lcos}}\uptheta + \dot{\uptheta }{\text{m}}_{{\text{l}}} {\text{l}}^{2} ,\,\frac{{{\text{d}}{\mathcal{L}}}}{{\partial {\text{x}}}} = 0{{~}}\,{\text{and}}\,\frac{{{\text{d}}{\mathcal{L}}}}{{\partial {{\uptheta }}}} = - {\text{m}}_{{\text{l}}} {{{\rm l}\dot{\text x}}}\dot{\uptheta }{\text{sin}}\uptheta - {\text{m}}_{{\text{l}}} {\text{glsin}}\uptheta$$
(12)

Moreover, let us assume the force applied to the system to be:

$${\text{Q}}_{{\text{x}}} = {\text{F}}_{{\text{t}}} - {\text{B}}_{{\text{t}}} {{\dot{\text x} and {\text {Q}}}}_{{\uptheta }} = - {\text{B}}_{{\text{l}}} {\dot{\uptheta }}$$
(13)

Substituting the above parameters into Euler–Lagrange Eq. (1), gives two equations:

$$\mathop {\text{x}}\limits^{{ \cdot \cdot }} {\text{m}}_{{\text{t}}} + \mathop {\text{x}}\limits^{{ \cdot \cdot }}{\text{m}}_{{\text{l}}} + \mathop {{\uptheta}}\limits^{{ \cdot \cdot }}{\text{m}}_{{\text{l}}} {\text{lcos}}{{\uptheta }} - {\text{m}}_{{\text{l}}} {{\text{l}\dot{\uptheta }}}^{2} {\text{sin}}{{\uptheta }} + {\text{B}}_{{\text{t}}} {\dot{\text{x}}} = {\text{F}}_{{\text{t}}}$$
(14)
$${\text{m}}_{{\text{l}}} \mathop {\text{x}}\limits^{{ \cdot \cdot }} {\text{cos}}{{\uptheta }} + \mathop {{\uptheta}}\limits^{{ \cdot \cdot }}{\text{m}}_{{\text{l}}} {\text{l}}^{2} + {\text{m}}_{{\text{l}}} {\text{glsin}}{{\uptheta }} + {\text{B}}_{{\text{l}}} {\dot{\uptheta }} = 0$$
(15)

The matrix form of the equation of motion is:

$$\left[ {\begin{array}{*{20}l} {{\text{m}}_{{\text{t}}} + {\text{m}}_{{\text{l}}} } & {{\text{m}}_{{\text{l}}} {\text{lcos}}{{\uptheta }}} \\ {{\text{m}}_{{\text{l}}} {\text{lcos}}{{\uptheta }}} & {{\text{m}}_{{\text{l}}} {\text{l}}^{2} } \\ \end{array} } \right]\left\{ {\begin{array}{*{20}l} \mathop {\text{x}}\limits^{{ \cdot \cdot }}\\ \mathop {{\uptheta}}\limits^{{ \cdot \cdot }}\\ \end{array} } \right\} + \left[ {\begin{array}{*{20}l} {{\text{B}}_{{\text{t}}} } & {{\text{m}}_{{\text{l}}} {{{\text l}\dot{\uptheta }{\text{sin}}\uptheta }}} \\ 0 & {{\text{B}}_{{\text{l}}} } \\ \end{array} } \right]\left\{ {\begin{array}{*{20}l} {{\dot{\text{x}}}} \\ {{\dot{\uptheta }}} \\ \end{array} } \right\} + \left[ {\begin{array}{*{20}l} 0 \\ {{\text{m}}_{{\text{l}}} {\text{lsin}}{{\uptheta }}} \\ \end{array} } \right]\left\{ {\text{g}} \right\} = \left\{ {\begin{array}{*{20}l} {{\text{F}}_{{\text{t}}} } \\ 0 \\ \end{array} } \right\}$$
(16)

where,

\({\text{B}}_{{\text{t}}} -\) the damping coefficient due to friction between the trolley and the air.

\({\text{B}}_{{\text{l}}} -\) the damping coefficient due to friction between the lifted load and the air.

For small swing, let us assume the approximation of trigonometric functions \({\text{sin}} {{\uptheta }} \approx {\uptheta },{\text{ cos}} {{\uptheta }} \approx 1,{{ \uptheta \dot{\uptheta }}}^{2} \approx 0.\) Thus, the equation of motion of the system will be:

$$\mathop {\text{x}}\limits^{{ \cdot \cdot }} \left( {{\text{m}}_{{\text{t}}} + {\text{m}}_{{\text{l}}} } \right) + \mathop {{\uptheta}}\limits^{{ \cdot \cdot }} {\text{m}}_{{\text{l}}} {\text{l}} + {\text{B}}_{{\text{t}}} {\dot{\text{x}}} = {\text{F}}_{{\text{t}}}$$
(17)
$${\text{m}}_{{\text{l}}} {\text{l}} \mathop {\text{x}}\limits^{{ \cdot \cdot }} +\mathop {{\uptheta}}\limits^{{ \cdot \cdot }} {\text{m}}_{{\text{l}}} {\text{l}}^{2} + {\text{m}}_{{\text{l}}} {\text{gl}}{{\uptheta }} + {\text{B}}_{{\text{l}}} {\dot{\uptheta }} = 0$$
(18)

To obtain the transfer function of the linearized system of equations analytically, we must first take the Laplace transform of the system equations.

$${\mathcal{L}}\left[ {{\text{x}}\left( {\text{t}} \right)} \right] = {\text{x}}\left( {\text{s}} \right),{ \mathcal{L}}\left[ {{\dot{\text{x}}}\left( {\text{t}} \right)} \right] = {\text{sx}}\left( {\text{s}} \right) - {\text{x}}\left( 0 \right),{ }$$
$${\mathcal{L}}\left[ {\mathop {\text{x}}\limits^{{ \cdot \cdot }} \left( {\text{t}} \right)} \right] = {\text{s}}^{2} {\text{x}}\left( {\text{s}} \right) - {\text{sx}}\left( 0 \right) - {\dot{\text{x}}}\left( 0 \right)$$
(19)
$${\mathcal{L}}\left[ {{\uptheta }\left( {\text{t}} \right)} \right] = {\uptheta }\left( {\text{s}} \right),{\mathcal{L}}\left[ {{\dot{\theta }}\left( {\text{t}} \right)} \right] = {\text{s}}{{\uptheta }}\left( {\text{s}} \right) - {\uptheta }\left( 0 \right),{ }$$
$${\mathcal{L}}\left[ {\mathop {{\uptheta}}\limits^{{ \cdot \cdot }}\left( {\text{t}} \right)} \right] = {\text{s}}^{2} {\uptheta }\left( {\text{s}} \right) - {\text{s}}{{\uptheta }}\left( 0 \right) - {\dot{\theta }}\left( 0 \right)$$
(20)

Assume that all of the initial conditions are zeroes, so these equations represent the location of the crane/trolley is at the left end of the beam. Thus, the Laplace transform of the Eqs. (17) and (18) can be:

$${\text{s}}^{2} {\text{x}}\left( {\text{s}} \right)\left( {{\text{m}}_{{\text{t}}} + {\text{m}}_{{\text{l}}} } \right) + {\text{m}}_{{\text{l}}} {\text{ls}}^{2} {\uptheta }\left( {\text{s}} \right) + {\text{B}}_{{\text{t}}} {\text{sx}}\left( {\text{s}} \right) = {\text{F}}_{{\text{t}}} \left( {\text{s}} \right)$$
(21)
$${\text{s}}^{2} {\text{x}}\left( {\text{s}} \right){\text{m}}_{{\text{l}}} {\text{l}} + {\text{m}}_{{\text{l}}} {\text{l}}^{2} {\text{s}}^{2} {\uptheta }\left( {\text{s}} \right) + {\text{B}}_{{\text{l}}} {\text{s}}{{\uptheta }}\left( {\text{s}} \right) + {\text{m}}_{{\text{l}}} {\text{gl}}{{\uptheta }}\left( {\text{s}} \right) = 0$$
(22)

Rearranging the Eqs. (21) and (22) gives:

$$\frac{{{\text{x}}\left( {\text{s}} \right)}}{{{\text{F}}_{{\text{t}}} \left( {\text{s}} \right)}} = \frac{{({\text{m}}_{{\text{l}}} {\text{l}}^{2} {\text{s}}^{2} + {\text{B}}_{{\text{l}}} {\text{s}} + {\text{m}}_{{\text{l}}} {\text{gl}})}}{{{\text{s}}^{4} \left( {{\text{m}}_{{\text{t}}} {\text{m}}_{{\text{l}}} {\text{l}}^{2} + {\text{m}}_{{\text{l}}}^{2} {\text{l}}^{3} - {\text{m}}_{{\text{l}}}^{2} {\text{l}}^{2} } \right) + {\text{s}}^{3} \left( {{\text{B}}_{{\text{l}}} {\text{m}}_{{\text{t}}} + {\text{B}}_{{\text{l}}} {\text{m}}_{{\text{l}}} + {\text{B}}_{{\text{t}}} {\text{m}}_{{\text{l}}} {\text{l}}^{2} } \right) + {\text{s}}^{2} \left( {{\text{m}}_{{\text{t}}} {\text{m}}_{{\text{l}}} {\text{gl}} + {\text{m}}_{{\text{l}}}^{2} {\text{gl}}} \right) + {\text{s}}\left( {{\text{B}}_{{\text{t}}} {\text{B}}_{{\text{l}}} + {\text{B}}_{{\text{t}}} {\text{m}}_{{\text{l}}} {\text{gl}}} \right)}}$$
(23)
$$\frac{{{\uptheta }\left( {\text{s}} \right)}}{{{\text{F}}_{{\text{t}}} \left( {\text{s}} \right)}} = \frac{{{\text{sm}}_{{\text{l}}} {\text{l}}}}{{ - {\text{m}}_{{\text{t}}} {\text{m}}_{{\text{l}}} {\text{l}}^{2} {\text{s}}^{3} - {\text{s}}^{2} \left( {{\text{B}}_{{\text{l}}} {\text{m}}_{{\text{t}}} + {\text{B}}_{{\text{l}}} {\text{m}}_{{\text{l}}} + {\text{B}}_{{\text{t}}} {\text{m}}_{{\text{l}}} {\text{l}}^{2} } \right) - {\text{s}}\left( {{\text{B}}_{{\text{t}}} {\text{B}}_{{\text{l}}} + {\text{m}}_{{\text{l}}} {\text{m}}_{{\text{t}}} {\text{gl}} + {\text{m}}_{{\text{l}}}^{2} {\text{gl}}} \right) - {\text{B}}_{{\text{t}}} {\text{m}}_{{\text{l}}} {\text{gl}}}}$$
(24)

2.2 Numerical values

The numerical values of the overhead crane parameters should be specified to simulate the transfer function in MATLAB Simulink. Accordingly, the following values are assumed for numerical purposes only.

\({\text{m}}_{{\text{t}}} = 25{\text{ kg}}\), \({\text{m}}_{{\text{l}}} = 15{\text{ kg}}\), \({\text{l}} = 1.5{\text{ m}},{\text{ g}} = 9.81{\text{ m}}/{\text{s}}^{2}\), \({\text{B}}_{{\text{t}}} = 0.25\frac{{{\text{Ns}}}}{{\text{m}}},{\text{ B}}_{{\text{l}}} = 0.1\frac{{{\text{Ns}}}}{{\text{m}}}{\text{ and F}}_{{\text{t}}} \left( {\text{s}} \right) = \frac{1}{{\text{s}}}\).

Substituting these numerical values into transfer functions \(\left( {\frac{{{\text{x}}\left( {\text{s}} \right)}}{{{\text{F}}_{{\text{t}}} \left( {\text{s}} \right)}}{\text{ and}} \frac{{{\uptheta }\left( {\text{s}} \right)}}{{{\text{F}}_{{\text{t}}} \left( {\text{s}} \right)}}} \right)\), gives the following:

$$\frac{{{\text{x}}\left( {\text{s}} \right)}}{{{\text{F}}_{{\text{t}}} \left( {\text{s}} \right)}} = \frac{{33.75{\text{s}}^{2} + 0.1{\text{s}} + 220.7}}{{1096.87{\text{s}}^{4} + 10.94{\text{s}}^{3} + 8829{\text{s}}^{2} + 55.2{\text{s}}}}$$
(25)
$$\frac{{{\uptheta }\left( {\text{s}} \right)}}{{{\text{F}}_{{\text{t}}} \left( {\text{s}} \right)}} = \frac{{22.5{\text{s}}}}{{ - 844{\text{s}}^{3} - 16.2{\text{s}}^{2} - 8829{\text{s}} - 55.2}}$$
(26)

2.3 Design of PID controller

There are several methods for designing PID controller parameters: proportional gain Kp, integral time Ki, and derivative time Kd. One of the simplest methods is known as the Ziegler-Nichols rule [26] for tuning PID controller parameters based on the transient-response characteristics of a given plant. Ziegler-Nichols tuning rules aim at obtaining a 25% maximum overshoot in the step response, as shown in Fig. 3.

Fig. 3
figure 3

PID control of a plant (a), Unit-step response curve showing 25% maximum overshoot (b) [26]

The PID controller tuned by the Ziegler-Nichols method gives:

$${\text{G}}\left( {\text{s}} \right) = {\text{K}}_{{\text{p}}} \left( {1 + \frac{1}{{{\text{K}}_{{\text{i}}} {\text{s}}}} + {\text{K}}_{{\text{d}}} {\text{s}}} \right)$$
(27)
$${\text{G}}\left( {\text{s}} \right) = 0.6{\text{K}}_{{{\text{cr}}}} \left( {1 + \frac{1}{{0.5{\text{P}}_{{{\text{cr}}}} {\text{s}}}} + 0.125{\text{P}}_{{{\text{cr}}}} {\text{s}}} \right)$$
(28)

However, the Ziegler-Nichols rule for tuning PID controller parameters (Table 1), is time-consuming and will provide only the initial parameters (25% maximum overshoot in the step response). Nowadays, different algorithms will optimize the PID parameters with the help of programmable software like MATLAB. In this study, optimization of the PID parameters uses the Bees and GA algorithms. The objective function used to determine the PID parameters is to minimize the transfer function:

$${\text{Obj}}.{\text{ fun}}:\min {\text{G}}\left( {\text{s}} \right) = {\text{K}}_{{\text{p}}} \left( {1 + \frac{1}{{{\text{K}}_{{\text{i}}} {\text{s}}}} + {\text{K}}_{{\text{d}}} {\text{s}}} \right)$$
(29)
Table 1 PID controller parameters for Ziegler-Nichols method

3 Result and discussion

3.1 PID controller result

The position control of the overhead crane, both in a horizontal and angular direction, was done using different methods. First of all, the Ziegler-Nichols approach is applied to find the PID parameters. The MATLAB code produced for the objective function of the overhead crane's horizontal and angular motions was applied to optimize the PID parameters using the Genetic Algorithm and the Bees Algorithm.

Table 2 summarizes the control results obtained with these different methods for controlling the horizontal motion of the overhead crane. Ziegler-Nichols's approach provides initial PID parameters, later modified with other methods. However, optimization techniques are used for the improvement of the result effectively. The rise time and overshoot decreased when GA and the Bees Algorithms. Finally, fine-tuning/manual techniques were applied to obtain a more realistic value, which gives a result nearest to the target value.

Table 2 PID Controller Parameters of horizontal motion for different approaches

3.1.1 Controlling of the linear horizontal motion (x-motion) of overhead crane

Figure 4 shows the schematic diagram of the PID controller in Simulink. The optimized value of the PID parameters was obtained with GA, using the optimization toolbox in MATLAB. The results were Kp = 392.2652, Ki = 189.8355, Kd = 422.6328, and Fig. 5 shows the control result. Similarly, the Bees Algorithm optimized the PID parameters and obtained values as Kp = 348.3816, Ki = 307.3037, Kd = 467.2496. Figure 5 also displays the result obtained with The Bees Algorithm optimized PID controller in Simulink.

Fig. 4
figure 4

Schematic diagram of PID control of overhead crane for different approaches

Fig. 5
figure 5

PID controller result of horizontal motion of overhead crane using different methods at t = 100 s

From the figures obtained from Simulink, a good outcome can result from modifying the PID parameters. Accordingly, by trial and error/fine-tuning, the PID parameters were modified to Kp = 233, Ki = 0.2, Kd = 500. As a result, using fine-tuning, an overshoot of 0.271% and a rise time of 4.449 s were recorded.

For comparison purposes, Fig. 6 presents the control result of four methods. Ziegler-Nichols's approach provides initial PID parameters, the poor result among the tested methods. The results were modified when the PID parameters were optimized using the Bees Algorithm and the Genetic Algorithm. Applying fine-tuning to the GA and the Bees Algorithm parameters result in a better outcome. Therefore, optimizing the PID parameters using the earlier algorithms is advisable to obtain a better control system.

Fig. 6
figure 6

PID controller result of horizontal motion of the overhead crane using different methods at t = 100 s in one diagram

3.1.2 Controlling of the angular/swinging motion (\({\varvec{\theta}}\)-motion) of overhead crane

Similarly, the horizontal motion of the crane, the angular or swinging motion, is controlled with a PID Controller, as shown in Fig. 7. Tuning of PID parameters is obtained with GA using the optimization toolbox in MATLAB. The results were Kp = 5.8757e-05, Ki = 3.2605e-04, Kd = 7.3272e-05. Figure 8 shows the result obtained from the PID controller in Simulink.

Fig. 7
figure 7

Schematic diagram of PID control of overhead crane for swinging motion

Fig. 8
figure 8

PID Controller result for parameters obtained with GA for swinging/angular motion of overhead crane

Figure 8 shows the GA-PID swinging motion control of the overhead crane. The overshoot and the rise time are approximately 0% and 0 s, respectively.

3.2 Application of fuzzy logic controller

Fuzzy logic is an artificial intelligence method that fuzzy membership functions that define some or all input and output parameters. Here, a fuzzy model uses the errors taken from the PID controller used to control the position of the overhead crane.

Chao et al. [27] present the equivalence between fuzzy Proportional-Integral-Derivative (PID) Controllers and Conventional PID Controllers. The paper proposes the transformation of a well-designed conventional PID Controller to an equivalent fuzzy logic controller (FLC) by observing and designing the operating ranges of the input/output of the controller. The result shows that FLC yields more satisfactory system responses efficiently.

Chao et al. [27] states the PID parameters have no relation with the number of membership functions but are strongly correlated to the operating ranges of the control input/output. Accordingly, the linear PID controller parameters can be:

$$K_{P} = \frac{{a_{u} }}{{3a_{e} }},\quad K_{I} = \frac{{a_{u} }}{{3a_{i} }}\,and\quad K_{D} = \frac{{a_{u} }}{{3a_{d} }}$$
(30)

where:

$$\left[ { - a_{e} ,a_{e} } \right] - {\text{the operating range for the error }}e\left( t \right)$$
$$\left[ { - a_{i} ,a_{i} } \right] - {\text{the operating range for the integral error }}\smallint e\left( t \right)dt$$
$$\left[ { - a_{d} ,a_{d} } \right] - {\text{the operating range for the derivative error }}\frac{de\left( t \right)}{{dt}}$$
$$\left[ { - a_{u} ,a_{u} } \right] - {\text{the operating range for the system output}}$$

3.2.1 Input parameters and operating ranges for horizontal motion of crane

To establish the operating ranges of the Fuzzy Membership Functions for error, integral error, and derivative error, we will examine the error signal graph for horizontal motion given in Fig. 9 and the approximate value of \(a_{e}\) assumed as 1.

Fig. 9
figure 9

The error obtained during horizontal position control of the overhead crane

Equation (30) and the PID controller parameters are the main inputs to calculate the operating ranges.

KP = 233.3841, Ki = 94.7797/0.25, Kd = 499.4958

$$\left[ { - a_{e} ,a_{e} } \right] = \left[ { - 1,{ }1} \right]$$
$$\left[ { - a_{i} ,a_{i} } \right] = \left[ { - 934,{ }934} \right]$$
$$\left[ { - a_{d} ,a_{d} } \right] = \left[ { - 0.5,{ }0.5} \right]{ }and\left[ { - a_{u} ,a_{u} } \right] = \left[ { - 700,{ }700} \right]$$

3.2.2 Input parameters and operating ranges for swinging/angular motion of crane

The operating ranges of the fuzzy membership functions for error, integral error, and derivative error may be determined by carefully observing the error signal graph illustrated in Fig. 10. The graph indicates that the approximate value of \(a_{e} { }\) is 5.8708 e-05%, insignificant.

Fig. 10
figure 10

The Error obtained from PID controller for swinging motion of the overhead crane

Accordingly, the operating ranges can be calculated by using the above equation and using the PID controller parameters as:

Kp = 5.8757e-05, Ki = 3.2605e-04, Kd = 7.3272e-05

$$\left[ { - a_{e} ,a_{e} } \right] = \left[ { - 5.8768{\text{e}} - 05,{ }5.8768{\text{e}} - 05} \right]$$
$$\left[ { - a_{i} ,a_{i} } \right] = \left[ { - 1.06{\text{e}} - 05,{ }1.06{\text{e}} - 05} \right]$$
$$\left[ { - a_{d} ,a_{d} } \right] = \left[ { - 4.7{\text{e}} - 05,{ }4.7{\text{e}} - 05} \right]{ }and$$
$$\left[ { - a_{u} ,a_{u} } \right] = \left[ { - 1.034{\text{e}} - 08,{ }1.034{\text{e}} - 08} \right]$$

3.2.3 Fuzzification

Low, Medium, and High are the three fuzzy sets of the input parameters of the horizontal motion and the output variable fuzzified into seven fuzzy sets. In angular motion, the five fuzzy sets of input parameters are Very Low, Low, Medium, High, and Very High, and the output variable is fuzzified into 13 fuzzy sets, as shown in Fig. 11. Therefore, the horizontal motion input parameters have three triangular membership functions and seven triangular-shaped membership functions used for the output. In angular motion, input parameters have five triangular membership functions and 13 triangular-shaped membership functions used for the output.

Fig. 11
figure 11

Fuzzy logic designer (a) and membership function for input (bd) and output variables (e)

Mamdani rule table defines the relationship between input and output parameters in both motions. The fuzzy logic modeling consists of fuzzifying variables, developing rule base and aggregation, and predicting responses by defuzzification. The data from the PID controller form the rules of the fuzzy model.

3.2.4 Fuzzy rules

The organization of the fuzzy rule base is a group of IF–THEN statements for both horizontal and angular motion. Three input variables (error, integral error, and derivative error) divided into a three-membership function (Low, Medium, and High) make 27 fuzzy rules for horizontal motion. Three input variables (error, integral error, and derivative error) divided into a five-membership function (V. Low, Low, Medium, High, and V. High) make 125 fuzzy rules for angular motion. The AND (min) operator combines the antecedent parts of the rules. For the implication method, to correlate the rule consequent with its antecedent, min was used.

The first rule of the FIS of the horizontal motion is Rule 1: IF input1 is Low and input2 is Low, input3 is Low, THEN output1 is mf1. In terms of actual variables, Rule 1 can be: “IF error is Low and integral error is Low and derivative error is Low THEN the total error is Low.” Similarly, the output membership function creates 27 fuzzy rules.

Similarly, the first rule of the FIS for angular motion is “Rule 1: IF input1 is Very Low and input2 is Very Low, and input3 is Very Low, THEN output1 is mf1.” In terms of actual variables, Rule 1 is: “IF error is V. Low and integral error is V. Low and derivative error is V. Low THEN the total error is V. Low.” Similarly, the output membership function generates 125 fuzzy rules.

This study uses the centroid defuzzification method for both motions, which considers the center of an area of the possibility distribution of the inference output.

3.2.5 Fuzzy logic results

Figure 12 shows the result of the fuzzy logic design for horizontal and angular motions. Results show that the fuzzy logic design of both horizontal and angular motions is highly affected by the operating range of the input and output variables. However, the number of membership functions does not affect the design of the Fuzzy Logic system.

Fig. 12
figure 12

Results obtained from fuzzy logic (Surface view for error, integral error, and output)

3.2.6 Fuzzy PID control system for horizontal motion

After designing Fuzzy Logic, the.fis file constructs the Simulink model of the horizontal motion as shown in Fig. 13 and the results in Fig. 14. The results obtained from the Fuzzy modified PID controller are better than conventional PID controller in overshoot, settling time, and raising time. In the FLC modified PID controller of the horizontal motion, the overshoot equals 0.227%, smaller than the conventional PID controller.

Fig. 13
figure 13

Simulink model for both conventional PID controller and FLC for horizontal motion of the crane

Fig. 14
figure 14

Graph of both conventional PID and FLC Results for comparisons

3.2.7 Fuzzy PID control system for angular motion

The fuzzy.fis file constructs the Simulink model of the angular motion as shown in Fig. 15 and the results in Fig. 16. The results obtained from the Fuzzy modified PID controller are better than the conventional PID controller in overshoot, settling time, and raising time for the angular motion. In the Fuzzy Logic modified PID Controller, the overshoot is equal to zero for angular motion.

Fig. 15
figure 15

Simulink Model for both conventional PID controller and FLC for swinging motion of the crane

Fig. 16
figure 16

Graph of both conventional PID and FLC results for comparisons

Table 3 shows the fuzzy logic and the conventional PID controller results for horizontal and swinging motion of overhead cranes. In conclusion, the Fuzzy Logic Controller shows a better performance than the conventional PID controller.

Table 3 The fuzzy logic and conventional PID controller results

4 Conclusion

This paper discusses overhead cranes' mathematical modeling and position control using GA and the Bees Algorithm-optimized PID controller. Moreover, the Fuzzy Logic Controller was applied to control the horizontal and swinging motion of the overhead crane. The mathematical modeling of the overhead cranes uses Lagrange's Approach. The mathematical equations developed were converted into a Transfer Function to apply the control methods. The PID controller parameters were first determined using the recommendation of Ziegler-Nichols Tuning Rules. Ziegler-Nichols Tuning provides initial values that provide poor control results. The use of GA and the Bees Algorithms provides the best PID control parameters. GA performs a 23.26% overshoot, and the Bees Algorithm achieves a 36.5% overshoot, a better result than Ziegler-Nichol's methods (69.36% overshoot). As a result, the controlled position of the horizontal motion has lower overshoot, slower rising time, and settling time. However, the fine-tuning method/trial and error method (0.271% overshoot) gives a better result because it uses the results obtained from optimization techniques. However, the fuzzy logic controller provides a better result (0.227% overshoot for horizontal motion and 0.176% overshoot for angular motion) than the conventional PID methods. Therefore, the Fuzzy Logic Controller shows better performance than the conventional PID controller. The operating range of the input and output variables highly affects the fuzzy logic control system design. However, the number of membership functions does not affect the design of the FLC. The paper was limited to only single values of overhead crane parameters and recommended using different parameters of overhead cranes to obtain a better controller result. Finally, different mechanical systems problems need the application of these algorithms as an optimization.