1 Introduction

Currently, control systems are a very important element in a mechatronic process since they allow to maintain the conditions desired or required by the user. Nowadays, there are different types of control systems that are used in different types of processes [1, 2]. However, for the selection of a suitable control system, it is necessary to consider different characteristics and/or parameters such as: performance, efficiency, precision, computational load, required software or hardware, mathematical models and, most importantly, if there are large uncertainties in the process. Conventional controls are based on a rigorous mathematical model of the system. In a PID, the way to optimize the control action is to adjust variables and tune coefficients, but it is complicated due to random changes, both internal and external disturbances of the system. An alternative is to use intelligent control systems, which are a control technique that uses the knowledge of a human being in a particular control domain and attempts to imitate human intelligence to learn and make decisions to solve problems, [3]. Artificial neural networks, fuzzy logic control, generic algorithms, expert systems, and hybrid systems are the main types of intelligent control.

Also, there are other structures that combine two intelligent control systems, for example, neuro-fuzzy control, direct adaptive control, indirect adaptive control, artificial neural network and a genetic algorithm, among others. In this case, NFC and IAC were used, which use fuzzy logic control (FLC) and artificial neural networks (ANN). The FLC does not require the mathematical model of the system, experimental tests can be used to define the control strategy and linguistic values to define the characteristics of the process and the control action. ANNs do not require the mathematical model of the system, only a data set of input and output variables is used to learn the dynamics and control of the process [4, 5]. Today, an FLC is used in a wide variety of applications, for example, monitoring carbon dioxide, carbon monoxide and ambient air levels in a ventilation system [6], peak-point tracking control power a photovoltaic panel [7], optimal point tracking control power of a photovoltaic panel [7], humidity and water level control of a hydroponic system [8], regulation of intravenous administration of anti-cancer drugs [9], trajectory tracking control of a robot or manipulator [10], tracking of the maximum power point of a wind turbine [11], among others. ANNs have been used to predict the thermal conductivity of multi-walled carbon nanotubes (water nanofluid) [12], detect possible production line failures to identify and apply maintenance activities [13], predict cases and deaths caused by COVID-19 [14], analysis of environmental pollution in the European Union due to the mining industry [15], predicting diabetes in a person [16], among others. In this work, a comparative analysis of three types of controls is carried out, these are: NFC, IAC and a PID, applied to an inverted pendulum (InvPen) system. The InvPen is used, because its movement is unstable in any direction and at any time. This property provides the characteristics necessary to analyze and validate a control system. Comparing the control action of the three controllers will show the efficiency of each one. To do this, the prototype of an InvPen and the design of programming algorithms are carried out to implement an NFC and an IAC under an Arduino UNO platform. For the analysis of the performance of the NFC and the IAC, Fuzzy Logic Toolbox™ and Neural Network Toolbox™ are used, as well as experimental tests of the InvPen to analyze its functionality and behavior. The structure of this work is as follows, section two describes the characteristics of the system, the NFC and the IAC. The third section shows the implementation of the prototype. Section four shows the simulation results. Section five shows the experimental results. The sixth section conclusions are given.

2 Description of the system

Figure 1a shows the diagram of the InvPen which is mounted on a cart (InvPenCart). The movement of the InvPenCart causes instability in the InvPen, which depending on the direction of the cart causes it to fall clockwise or counterclockwise. To maintain the balance of the InvPen at 90° to the horizontal, three types of controls are used: a PID, an NFC and an IAC, and determine the response of each of them. To measure the angular position of the InvPen, a potentiometer is used as a sensor, a stepper motor is used to adjust its angular position, and a DC motor is used to move the InvPenCart. To measure the position of the InvPen, (1) is used, which is a relationship between the output voltage (0 to 5 V) of the potentiometer and the angular position (− 150° to 150°) of the InvPen, as shown in Fig. 1b). To determine the direction of movement of the InvPen, the angular movement in degrees of the potentiometer was divided into two parts. If the result of (1) gives positive degrees, the movement of the InvPen is clockwise, in the other case, the movement of the InvPen is counterclockwise. Table 1 shows the InvPen parameters used for the prototype. Figure 2 shows the prototype of the InvPen designed. To control the movement and direction of the InvPenCart, a pulley-belt-pulley transmission system is used, which has a transmission ratio of 5:1. The potentiometer, stepper motor, and the InvPen are connected by a pulley-belt-pulley transmission system with a transmission ratio of 1:1.

$${\text{PosInvPen}}=\left(\frac{\left(\left({\text{VPot}}\right)*\left(300^\circ \right)\right)}{5{\text{Vdc}}}\right)-150^\circ$$
(1)

where VPot is the output voltage of the potentiometer, 5Vdc is the potentiometer supply voltage, and 300° is the operating range of the InvPen.

Fig. 1
figure 1

Configuration of a InvPen and b potentiometer

Table 1 Technical characteristics of the InvPen
Fig. 2
figure 2

Design of the InvPen

The mathematical model of the InvPen, where the friccion (b) is not considered, is given by:

$$\left({\text{I}}+{{\text{mL}}}^{2}\right)\frac{{{\text{d}}}^{2}\uptheta }{{{\text{dt}}}^{2}}-\mathrm{mgL\theta }={\text{mL}}\frac{{{\text{d}}}^{2}{\text{x}}}{{{\text{dt}}}^{2}}$$
(2)
$$\left({\text{M}}+{\text{m}}\right)\frac{{{\text{d}}}^{2}{\text{x}}}{{{\text{dt}}}^{2}}+{\text{b}}\frac{{\text{dx}}}{{\text{dt}}}-{\text{mL}}\frac{{{\text{d}}}^{2}\uptheta }{{{\text{dt}}}^{2}}={\text{u}}$$
(3)

Taking the Laplace transforms of (2, 3),

$$\left({\text{I}}+{{\text{mL}}}^{2}\right){{\text{s}}}^{2}\uptheta \left({\text{s}}\right)-\mathrm{mgL\theta }({\text{s}})={{\text{mLs}}}^{2}{\text{X}}({\text{s}})$$
(4)
$$\left({\text{M}}+{\text{m}}\right){{\text{s}}}^{2}{\text{X}}({\text{s}})+{\text{bX}}({\text{s}})-{{\text{mLs}}}^{2}\uptheta ({\text{s}})={\text{U}}\left({\text{s}}\right)$$
(5)

Then, the transfer function is, [17, 18]:

$${\text{q}}=\left({\text{M}}+{\text{m}}\right)\left({\text{I}}+{{\text{mL}}}^{2}\right)-{\left({\text{mL}}\right)}^{2}$$
(6)
$$\frac{\uptheta ({\text{s}})}{{\text{U}}({\text{s}})}=\frac{\frac{{\text{mL}}}{{\text{q}}} {{\text{s}}}^{2}}{{{\text{s}}}^{4} - \frac{{\text{mgL}}\left({\text{M}}+{\text{m}}\right)}{{\text{q}}} {{\text{s}}}^{2}}$$
(7)

And the solution of the mathematical model is:

$$\uptheta \left({\text{t}}\right)=\frac{2000\sqrt{395}\sqrt{9483}{\text{sinh}}\left(\frac{\sqrt{395}\sqrt{9483}}{395}{\text{t}}\right)}{6742413}$$
(8)

2.1 Proportional integral derivative control (PID)

Figure 3 shows the block diagram of the PID for the InvPen. The input signal is the error (\({\text{E}}\left({\text{s}}\right)\)), which is the difference between the desired position (\({\uptheta }_{{\text{des}}}\left({\text{s}}\right)\)) and the current position (\({\uptheta }_{{\text{O}}}\left({\text{s}}\right)\)). The output signal is the control signal (\({\text{U}}\left({\text{s}}\right)\)). The PID depends on the gain parameters: proportional \({{\text{K}}}_{{\text{p}}}\), integral \({{\text{K}}}_{{\text{i}}}\) and derivative \({{\text{K}}}_{{\text{d}}}\). To determine these gains, a programming algorithm was performed to implement the computational optimization method [19]. The values obtained were: 7.4, 114 and 439 for \({{\text{K}}}_{{\text{p}}}\), \({{\text{K}}}_{{\text{i}}}\) and \({{\text{K}}}_{{\text{d}}}\), respectively. Figure 4 shows the control of the InvPen using the PID. The programming algorithm to implement the computational optimization method is shown below.

Fig. 3
figure 3

Block diagram of the InvPen and the PID.

Fig. 4
figure 4

Block diagram implemented in Simulink

figure a

2.2 Indirect adaptive control (IAC)

To tune a system, IAC uses an ANN to model the operation of the system and an ANN to generate the control signal (\({\text{u}}\left({\text{k}}\right)\)). IAC generates the signal \({\text{u}}\left({\text{k}}\right)\), which makes the system output as similar as possible to the desired signal (\({\uptheta }_{{\text{des}}}\left({\text{k}}\right)\)). Figure 5 shows the IAC structure used to control the InvPen. The training of the ANN-M is performed using the identification error (\({{\text{e}}}_{{\text{id}}}\left({\text{k}}\right)\)), which is the difference between the system response (\({\uptheta }_{{\text{real}}}\left({\text{k}}\right)\)) and the output of the ANN-M (\({\uptheta }_{{\text{ANN}}}\left({\text{k}}\right)\)). For training the ANN-C, it is done using the tracking error (\({{\text{e}}}_{{\text{tr}}}\left({\text{k}}\right)\)), which is the difference between \({\uptheta }_{{\text{real}}}\left({\text{k}}\right)\) and \({\uptheta }_{{\text{des}}}\left({\text{k}}\right)\). First, the training of the ANN-M is carried out and subsequently, the training of the ANN-C [20]. ANN-M and ANN-C have an input layer with one input, an intermediate layer with 20 neurons, an output layer with one neuron, and sigmoid activation functions. Figure 6 shows the structure of ANNs. The backpropagation algorithm is the most used method to train an ANN [21, 22]. The first stage of the method is to obtain the response of the ANN based on the value of the input variables. The second stage of the method is to update the synaptic weights (\({{\text{W}}}_{{\text{ji}}}^{\left(1\right)}\) and \({{\text{W}}}_{{\text{ji}}}^{\left(1\right)}\)), for which the error must be propagated backward through the layers (L) of the ANN.The input of an artificial neuron is determined by.

$${{\text{I}}}_{{\text{j}}}^{\left({\text{L}}\right)}= {\sum }_{{\text{i}}=0}^{{{\text{j}}}_{1}}\left({{\text{W}}}_{{\text{ji}}}^{\left({\text{L}}\right)}*{{\text{x}}}_{{\text{i}}}\right)$$
(9)

The output of an artificial neuron is determined by.

$${{\text{O}}}_{{\text{j}}}^{({\text{L}})}={\text{g}}\left({{\text{I}}}_{{\text{j}}}^{\left({\text{L}}\right)}\right)$$
(10)

To apply the backpropagation algorithm to the ANN-M, the Squared Error (SE), which is the difference between \({\uptheta }_{{\text{real}}}({\text{k}})\) and \({\uptheta }_{{\text{ANN}}}({\text{k}})\), must be determined by

$${\text{E}}\left({\text{k}}\right)=\frac{1}{2}{\left({\uptheta }_{{\text{real}}}\left({\text{k}}\right)-{\uptheta }_{{\text{ANN}}}\left({\text{k}}\right)\right)}^{2}$$
(11)

Applying the descending gradient to (XX) with respect to the synaptic weights (\({{\text{Wm}}}_{{\text{ji}}}^{\left(2\right)}\) and \({{\text{Wm}}}_{{\text{ji}}}^{\left(1\right)}\)), we obtain:

$${{\text{A}}}_{1}=\left({\uptheta }_{{\text{real}}}\left({\text{k}}\right)-{\uptheta }_{{\text{ANN}}}\left({\text{k}}\right)\right)*{{\text{g}}}^{\mathrm{^{\prime}}}\left({\uptheta }_{{\text{ANN}}}\left({\text{k}}\right)\right)$$
(12)
$${{\text{Wm}}}_{{\text{ji}}}^{\left(2\right)}\left({\text{k}}+1\right)={{\text{Wm}}}_{{\text{ji}}}^{\left(2\right)}\left({\text{k}}\right)+\upeta *{{\text{A}}}_{1}*{{\text{O}}}_{{\text{j}}}^{\left(1\right)}$$
(13)
$${{\text{A}}}_{2}=\sum_{{\text{j}}=1}^{{{\text{j}}}_{2}}\left({{\text{A}}}_{1}*{{\text{Wm}}}_{{\text{ji}}}^{\left(2\right)}\right)*{{\text{g}}}^{\mathrm{^{\prime}}}\left({{\text{O}}}_{{\text{j}}}^{\left(2\right)}\right)$$
(14)
$${{\text{Wm}}}_{{\text{ji}}}^{\left(1\right)}\left({\text{k}}+1\right)={{\text{Wm}}}_{{\text{ji}}}^{\left(1\right)}\left({\text{k}}\right)+\upeta *{{\text{A}}}_{2}*{\text{u}}\left({\text{k}}\right)$$
(15)

To apply the backpropagation algorithm to the ANN-C, the SE, which is the difference between \({\uptheta }_{{\text{real}}}({\text{k}})\) and the \({\uptheta }_{{\text{des}}}\left({\text{k}}\right)\), must be determined by

$${\text{E}}\left({\text{k}}\right)=\frac{1}{2}{\left({\uptheta }_{{\text{real}}}\left({\text{k}}\right)-{\uptheta }_{{\text{des}}}\left({\text{k}}\right)\right)}^{2}$$
(16)

Applying the descending gradient to (XX) with respect to the synaptic weights (\({{\text{Wc}}}_{{\text{ji}}}^{\left(2\right)}\) and \({{\text{Wc}}}_{{\text{ji}}}^{\left(1\right)}\)), we obtain:

$${{\text{A}}}_{3}=\sum_{{\text{j}}=1}^{{{\text{j}}}_{3}}\left({{\text{A}}}_{2}*{{\text{Wm}}}_{{\text{ji}}}^{\left(1\right)}\right)*{{\text{g}}}^{\mathrm{^{\prime}}}\left({{\text{O}}}_{{\text{j}}}^{\left(2\right)}\right)$$
(17)
$${{\text{Wc}}}_{{\text{ji}}}^{\left(2\right)}\left({\text{k}}+1\right)={{\text{Wc}}}_{{\text{ji}}}^{\left(2\right)}\left({\text{k}}\right)+\upeta *{{\text{A}}}_{3}*{{\text{O}}}_{{\text{j}}}^{\left(1\right)}$$
(18)
$${{\text{A}}}_{4}=\sum_{{\text{j}}=1}^{{{\text{j}}}_{2}}\left({{\text{A}}}_{3}*{{\text{Wc}}}_{{\text{ji}}}^{\left(2\right)}\right)*{{\text{g}}}^{\mathrm{^{\prime}}}\left({{\text{O}}}_{{\text{j}}}^{\left(1\right)}\right)$$
(19)
$${{\text{Wc}}}_{{\text{ji}}}^{\left(1\right)}\left({\text{k}}+1\right)={{\text{Wc}}}_{{\text{ji}}}^{\left(1\right)}\left({\text{k}}\right)+\upeta *{{\text{A}}}_{4}*{\uptheta }_{{\text{des}}}\left({\text{k}}\right)$$
(20)

The analysis of the performance of the indirect adaptive control was carried out by

Fig. 5
figure 5

Block diagram of indirect adaptive control

Fig. 6
figure 6

Structure of a ANN-C and b ANN-M

$${\text{MSE}}=\frac{1}{{\text{P}}}\sum_{{\text{k}}=1}^{{\text{P}}}\left({\text{E}}\left({\text{k}}\right)\right)\mathrm{ P}:\mathrm{number of samples}$$
(21)

Then, to analyze the performance of the IAC, a programming algorithm was designed on the Arduino UNO board, using only basic operations (addition, subtraction, multiplication, division and exponential). The experimental results were as follows: processing time of 4.29 ms, 48% memory, training time of 5.35 h. The programming algorithm to implement the ANN is shown below.

figure b

2.3 Neuro-fuzzy control (NFC)

An NFC is carried out through the union of an FLC and an ANN. The ANN training algorithm is used to tune the parameters of the fuzzy sets and the coefficients of the FLC polynomials. The configuration that was used in this work is known as the Adaptive Network-Based Fuzzy Inference System (ANFIS). For this, backpropagation algorithm and a Takagi–Sugeno type fuzzy control were used. \({\uptheta }_{{\text{des}}}({\text{k}})\) and a delay of the \({\uptheta }_{{\text{des}}}({\text{k}})\) signal were used as input variables, and \({\text{u}}\left({\text{k}}\right)\) as the output variable. Five triangular fuzzy sets were defined for \({\uptheta }_{{\text{des}}}\left({\text{k}}\right)\) labeled as \({{\text{A}}}_{1}\), \({{\text{A}}}_{2}\), \({{\text{A}}}_{3}\), \({{\text{A}}}_{4}\) and \({{\text{A}}}_{5}\). For \({\text{d}}\left({\uptheta }_{{\text{des}}}\left({\text{k}}\right)\right)/{\text{dt}}\), also five fuzzy sets labeled \({{\text{B}}}_{1}\), \({{\text{B}}}_{2}\), \({{\text{B}}}_{3}\), \({{\text{B}}}_{4}\) and \({{\text{B}}}_{5}\). Twenty-five rules (R) were used, and the polynomials of the consequent are of first order \({\text{y}}={{\text{p}}}_{0}+{{\text{p}}}_{1}{{\text{x}}}_{1}+{{\text{p}}}_{2}{{\text{x}}}_{2}\) [23,24,25]. Figure 7 shows the NFC structure used to control the InvPen, Fig. 8 shows the fuzzy sets of the input variables and Fig. 9 shows the structure of ANFIS.Layer 1 performs fuzzification of the input variables, this is done by.

Fig. 7
figure 7

Block diagram of neural-fuzzy control

Fig. 8
figure 8

Fuzzy sets of a \({\uptheta }_{{\text{des}}}\left({\text{k}}\right)\), and b \({\uptheta }_{{\text{des}}}\left({\text{k}}-1\right)\). (\({{\text{x}}}_{1}\) and \({{\text{x}}}_{2}\) represents \({\uptheta }_{{\text{des}}}\left({\text{k}}\right)\) and \({\uptheta }_{{\text{des}}}\left({\text{k}}-1\right)\), respectively.)

Fig. 9
figure 9

ANFIS structure (\({{\text{x}}}_{1}\) and \({{\text{x}}}_{2}\) represents \({\uptheta }_{{\text{des}}}\left({\text{k}}\right)\) and \({\uptheta }_{{\text{des}}}\left({\text{k}}-1\right)\), respectively.)

$${\upmu }_{{\text{C}}}\left({{\text{x}}}_{{\text{n}}}\right)=\left\{\begin{array}{c}0\mathrm{ si x}<\mathrm{a }\\ \begin{array}{c}\frac{{\text{x}}-{\text{a}}}{{\text{b}}-{\text{c}}}\mathrm{ si a}<{\text{x}}<{\text{b}}\\ \frac{{\text{c}}-{\text{x}}}{{\text{c}}-{\text{b}}}\mathrm{ si b}<{\text{x}}<{\text{c}}\\ 0\mathrm{ si x}>{\text{c}}\end{array}\end{array}\right.$$
(22)

Layer 2 determines the intensity of the rules (r), this is done by.

$${{\text{w}}}_{{\text{r}}}=\left({\upmu }_{{\text{A}}}\left({{\text{x}}}_{1}\right)\right)*\left({\upmu }_{{\text{B}}}\left({{\text{x}}}_{2}\right)\right)$$
(23)

Layer 3 determines the intensity of a fuzzy rule with respect to the intensity of all fuzzy rules, this is done by.

$$\overline{{{\text{w}} }_{{\text{r}}}}=\frac{{{\text{w}}}_{{\text{r}}}}{{{\text{w}}}_{1}+{{\text{w}}}_{2}+\dots +{{\text{w}}}_{{\text{R}}}}$$
(24)

Layer 4 determines the consequent of the rules, this is done by.

$${{\text{y}}}_{{\text{r}}}=\overline{{{\text{w}} }_{{\text{r}}}}*\left({{\text{p}}}_{0}+{{\text{p}}}_{1}*{{\text{x}}}_{1}+{{\text{p}}}_{2}*{{\text{x}}}_{2}\right)$$
(25)

Layer 5 determines the global output or response of the ANFIS, this is done by.

$${\text{Z}}={\sum }_{{\text{r}}=1}^{{\text{R}}}\left({\overline{{{\text{w}} }_{{\text{r}}}}*{\text{y}}}_{{\text{r}}}\right)$$
(26)

To apply the backpropagation algorithm to the ANFIS, the SE, which is the difference between \({\text{d}}({\text{k}})\) and \({\text{u}}({\text{k}})\), must be determined by

$${\text{E}}\left({\text{k}}\right)=\frac{1}{2}{\left({\text{d}}\left({\text{k}}\right)-{\text{u}}\left({\text{k}}\right)\right)}^{2}$$
(27)

Applying the descending gradient to (27) with respect to the coefficients of the polynomials (\({{\text{p}}}_{0}\), \({{\text{p}}}_{1}\), \({{\text{p}}}_{2}\)), and the parameters of a fuzzy set (a, b, and c), we obtain:

$${{\text{p}}}_{0}\left({\text{k}}+1\right)={{\text{p}}}_{0}\left({\text{n}}\right)-\upeta \left(\overline{{{\text{w}} }_{{\text{r}}}}\right)$$
(28)
$${{\text{p}}}_{1}\left({\text{k}}+1\right)={{\text{p}}}_{1}\left({\text{k}}\right)-\upeta \left({\text{d}}\left({\text{k}}\right)\right)*\left(\overline{{{\text{w}} }_{{\text{r}}}}\right)$$
(29)
$${{\text{p}}}_{2}\left({\text{k}}+1\right)={{\text{p}}}_{3}\left({\text{k}}\right)-\upeta \left({\uptheta }_{{\text{des}}}\left({\text{k}}\right)\right)\left({\text{d}}{\uptheta }_{{\text{des}}}\left({\text{k}}\right)/{\text{dt}}\right)\left(\overline{{{\text{w}} }_{{\text{r}}}}\right)$$
(30)
$${{\text{W}}}_{{\text{T}}}=\sum_{{\text{r}}=1}^{{\text{R}}}\left({{\text{w}}}_{{\text{r}}}\right)$$
(31)
$${\text{a}}\left({\text{k}}+1\right)={\text{a}}\left({\text{k}}\right)-\upeta \left({{\text{y}}}_{{\text{r}}}\right)\left(\frac{{{\text{W}}}_{{\text{T}}}-{{\text{w}}}_{{\text{r}}}}{{{\text{W}}}_{{\text{T}}}^{2}}\right)\left({\upmu }_{{\text{C}}}\left({{\text{x}}}_{{\text{n}}}\right)\right)\left(\frac{-{\text{b}}+{\text{x}}}{{\left({\text{b}}-{\text{a}}\right)}^{2}}\right)$$
(32)
$${\text{b}}\left({\text{k}}+1\right)={\text{b}}\left({\text{k}}\right)+\upeta \left({{\text{y}}}_{{\text{r}}}\right)\left(\frac{{{\text{W}}}_{{\text{T}}}-{{\text{w}}}_{{\text{r}}}}{{{\text{W}}}_{{\text{T}}}^{2}}\right)\left({\upmu }_{{\text{C}}}\left({{\text{x}}}_{{\text{n}}}\right)\right)\left(\frac{{\text{x}}-{\text{a}}}{{\left({\text{b}}-{\text{a}}\right)}^{2}}\right)$$
(33)
$${\text{c}}\left({\text{k}}+1\right)={\text{c}}\left({\text{k}}\right)-\upeta \left({{\text{y}}}_{{\text{r}}}\right)\left(\frac{{{\text{W}}}_{{\text{T}}}-{{\text{w}}}_{{\text{r}}}}{{{\text{W}}}_{{\text{T}}}^{2}}\right)\left({\upmu }_{{\text{C}}}\left({{\text{x}}}_{{\text{n}}}\right)\right)\left(\frac{{\text{b}}-{\text{x}}}{{\left({\text{c}}-{\text{b}}\right)}^{2}}\right)$$
(34)

The analysis of the performance of neuro-fuzzy control is carried out by (21).

To analyze the performance of the NFC, a programming algorithm was designed on an Arduino UNO board, using basic operations (addition, subtraction, multiplication and division). The experimental results were as follows: a processing time of 120 ms, 43% memory. The programming algorithm used to implement NFC is shown below.

figure c

3 Implementation of the ip prototype

Figure 10a shows the electronic system of the InvPen, which is composed of an Arduino UNO board, a 10KΩ potentiometer, a stepper motor and an L298N module [26, 27]. Furthermore, Fig. 10b and c show the InvPen prototype. The position of the InvPen was determined using the potentiometer, which was connected to an analog input of the Arduino UNO board. To determine the control action of the InvPen, the Arduino UNO board performs the NFC or IAC process, the output of which is used to adjust the position of the InvPen by sending control signals to the L298 module, which provides the energy to move the motor.

Fig. 10
figure 10

MPN training result, a comparison of the reference signal and the output of the MPN, and b MSE

4 Simulation results

For the analysis of NFC, the Fuzzy Logic Toolbox was used and for IAC, the Neural Network Toolbox was used [28, 29]. To analyze the two types of control, it was carried out by obtaining the MSE, which indicates the precision of the system modeling by quantifying the difference between the desired results and the actual results. For this reason, the MSE is used to train in IAC and ANFIS. The experimental results obtained were: an MSE of 2.15101×10^(− 4) for the ANFIS, and an MSE of 1.4608x10^(− 4) for the IAC. Based on the above, the InvPen control presented a high degree of precision, since small MSE values indicate that the process modeling has less error. In this case, ANFIS and IAC managed to learn the dynamics of the InvPen. Figure 11a shows the reduction of MSE during ANFIS training and Fig. 11b shows the reduction of MSE during IAC training.

Fig. 11
figure 11

IP, a electronic diagram, b implementation of the electronic diagram, and c prototype

5 Experimental results

For performance testing of the PID, IAC and NFC, a step signal, a ramp signal, and a sine signal were used. Figure 12 shows the response of the three controllers to a step signal. In this case, the PID showed an overshoot of 10% and a settling time of 0.3 s. While the IAC and the NFC did not present an overshoot and the settling time is shorter. The overshoot that is observed is the maximum point that exceeds the desired level. The settling time is the time necessary to stabilize the system. A transient response can be observed, which causes the system to converge slowly. Figure 13 shows the response of the three controllers to a ramp signal. Figure 14 shows the response of the three controllers to a sinusoidal signal. As can be seen, none of the reference signals generated an overshoot in the InvPen response. Figure 15 shows the PID control signals for the reference signals. Figure 16 shows the IAC control signals for the reference signals. Figure 17 shows the NFC control signals for the reference signals. Additionally, Integral Square Error (ISE), Integral Absolute Error (IAE), Integral time Squared Error (ITSE), and Integral time Absolute Error (ITAE) were determined for the three controllers. These parameters are used to analyze the operation of a control system. Tables 2, 3 and 4 show the ISE, IAE, ITSE and ITAE values of the controllers for the different reference inputs.

Fig. 12
figure 12

InvPen response to a step signal

Fig. 13
figure 13

InvPen response to a ramp signal

Fig. 14
figure 14

InvPen response to a sinusoidal signal

Fig. 15
figure 15

PID control signals

Fig. 16
figure 16

IAC control signals

Fig. 17
figure 17

NFC control signals

Table 2 PID performance indices
Table 3 IAC performance indices
Table 4 NFC performance indices

On the other hand, the analysis of the robustness of the controllers was carried out by analyzing the response of the system to a disturbance. Figure 18 shows the step signal with a disturbance, Fig. 19 shows the ramp signal with a disturbance, and Fig. 20 shows the sinusoidal signal with a disturbance. As can be seen in the figures, the adjustment of the InvPen with the PID required a longer settling time than the settling time of the NFC or the IAC. In addition, impulses and oscillations were generated in the system response. On the contrary, the adjustment of the InvPen with the NFC or the IAC did not generate impulses and oscillations in the system response. Furthermore, the NFC and IAC had a shorter settling time than the settling time of the PID. Table 5 describes the main advantages and disadvantages of the responses of the three types of control, neuro-fuzzy, indirect adaptive and PID.

Fig. 18
figure 18

System response to a step signal with a disturbance

Fig. 19
figure 19

System response to a ramp signal with a disturbance

Fig. 20
figure 20

System response to a sinusoidal signal with a disturbance

Table 5 Advantages and disadvantages of the NFC, the IAC, and the PID

5.1 Comparación entre los controladores propuestos y otros trabajos

In [30], the InvPen was controlled with a fuzzy logic control (FLC) optimized by the maximum entropy principle and a genetic algorithm. To implement the control system, two enconders, two data acquisition cards and Simulink were used, which was used to monitor the system response, and generate the control signal and the reference signal for the InvPen. Table 6 shows the performance indices of FLC, IAC, and NFC. As can be seen, the proposed controllers (IAC and NFC) have better performance than the FLC.

Table 6 Performance indices

In [31], the InvPen was controlled with a PID along with a radial-based artificial neural network. The control system was analyzed with three reference signals (step signal, square signal and sine signal). In this sense, the response of the InvPen to the different reference signals had overshoots. Additionally, the system response in the presence of a disturbance had overshoots. In comparison, the proposed controllers (NFC and IAC) did not allow overshoots to be generated in the system response. Likewise, the IAC and the NFC prevented a disturbance from generating overshoots in the system response.

In [32], the InvPen was controlled with a PID control, whose gain values are determined by the pole placement method. The response of the InvPEn with this controller had overshoots and oscillations. In comparison, the IAC and NFC prevented the generation of overshoots and oscillations, indicating that the settling time with the IAC and NFC is shorter than the settling time with the PID.

6 Conclusions

In this work, it has been demonstrated through the design and implementation of three types of control applied to an inverted pendulum, that intelligent neuro-fuzzy and indirect adaptive controls are more robust and have greater precision than PID control. The two intelligent controls kept the InvPen in balance and with greater precision. For this, the three types of control were designed and implemented in hardware for their characterization. Both neuro-fuzzy and indirect adaptive programming algorithms only use basic operations (addition, subtraction, multiplication, and division) and two control statements (IF and FOR). The tuning and its behavior were carried out based on the input and output variables with respect to various indices such as settling time, rise time, mean square error, overshoots, convergence, and performance indices for control systems. Both experimental and simulation results demonstrate that intelligent control based on neuro-fuzzy and indirect adaptive provide fast response times with practically no overshoots, which is adequate to keep the IP in balance with great precision.