UPAFuzzySystems: A Python Library for Control and Simulation with Fuzzy Inference Systems

: The main goal of control theory is input tracking or system stabilization. Different feedback-computed controlled systems exist in this area, from deterministic to soft methods. Some examples of deterministic methods are Proportional (P), Proportional Integral (PI), Proportional Derivative (PD), Proportional Integral Derivative (PID), Linear Quadratic (LQ), Linear Quadratic Gaussian (LQG), State Feedback (SF), Adaptative Regulators, and others. Alternatively, Fuzzy Inference Systems (FISs) are soft-computing methods that allow using the human expertise in logic in IF–THEN rules. The fuzzy controllers map the experience of an expert in controlling the plant. Moreover, the literature shows that optimization algorithms allow the adaptation of FISs to control different processes as a black-box problem. Python is the most used programming language, which has seen the most signiﬁcant growth in recent years. Using open-source libraries in Python offers numerous advantages in software development, including saving time and resources. In this paper, we describe our proposed UPAFuzzySystems library, developed as an FISs library for Python, which allows the design and implementation of fuzzy controllers with transfer-function and state-space simulations. Additionally, we show the use of the library for controlling the position of a DC motor with Mamdani, FLS, Takagi–Sugeno, fuzzy P, fuzzy PD, and fuzzy PD-I controllers.


Introduction
The main goal of control theory is to be tracking the input or system stabilization that produces an adjusted output associated with a process that responds to different behaviors.Achieving this implies designing a control law adapted to the process model.To obtain this model means using physics and mathematical principles with parametrizing stage after modeling to achieve similar behavior to the process [1,2].
A feedback Computer-Controlled System (CCS) has an input that samples the Process Variable (PV) with an Analog-Digital Converter (ADC).Then, the CCS uses this information to calculate an algorithm that considers the Reference Variable (RV) or desired value for PV by producing an analog output-converted from digital with a Digital-Analog Converter (DAC).All the conversions and steps in the CCS are shown in Figure 1 [3].
Alternatively, Fuzzy Inference Systems (FISs) are soft-computing methods that offer a linguistic way of dealing with complex processes and the possibility of translating human experience into logic in IF-THEN rules.
The FISs were introduced in the early 1970s by Lotfi A. Zadeh.This invention represented a breakthrough in set theory, as fuzzy logic mimics the human decision process.In 1975, Ebrahim Mamdani initiated the FIS to control a steam engine and boiler by creating linguistic synthesis control rules based on human expert operators, obtaining the first fuzzy controller [4].
The fuzzy controllers make it possible to design the control law with rules that represent the experience of the experts in controlling the plant.Moreover, the literature shows that algorithms such as Least Square Estimator (LSE), Genetic Algorithms (GAs), Particle Swarm Optimization (PSO), and Gradient Descent (GD), among others, allow the optimization of FISs for controlling different processes such as black-box problems [5][6][7][8][9][10].
FIS controllers simplify the control of complex systems without linearities and time variations, but their programming and configuration are more complex than classical approaches.However, there are several commercial alternatives for implementing and simulating FIS controllers.
The MATLAB TM fuzzy logic toolbox enables the design and implementation of FIS for control, modeling, and simulation [11].Current research papers that implement the MATLAB TM fuzzy logic toolbox investigate the following: reducing chemical oxygen demand in low-strength wastewater [12], controlling the speed of motors for robots [13], designing the control of a three-phase grid-connected inverter using a Raspberry Pi system [14], the design, modeling, and simulation of one-degree of freedom inverted pendulum [15], and designing a single-stage photovoltaic system with energy recovery control [16].
Additionally, "IT2-FLS" is another toolbox of MATLAB TM for implementing fuzzy logic of interval type 2. It includes different construction stages, including design, description, and implementation.However, it does not contain parameters or methods specific to control systems [17].
A commercial alternative for implementing and controlling FIS is National Instruments, whose LabVIEW TM software provides a graphical programming framework.In addition, LabVIEW TM allows the implementation of real-time controllers using the same brand of diving instruments, such as USB-6001/6002/6003/6211 and others [18].LabVIEW with FIS has shown promising results in controlling Carbon Dioxide Fertilization in a Alternatively, Fuzzy Inference Systems (FISs) are soft-computing methods that offer a linguistic way of dealing with complex processes and the possibility of translating human experience into logic in IF-THEN rules.
The FISs were introduced in the early 1970s by Lotfi A. Zadeh.This invention represented a breakthrough in set theory, as fuzzy logic mimics the human decision process.In 1975, Ebrahim Mamdani initiated the FIS to control a steam engine and boiler by creating linguistic synthesis control rules based on human expert operators, obtaining the first fuzzy controller [4].
The fuzzy controllers make it possible to design the control law with rules that represent the experience of the experts in controlling the plant.Moreover, the literature shows that algorithms such as Least Square Estimator (LSE), Genetic Algorithms (GAs), Particle Swarm Optimization (PSO), and Gradient Descent (GD), among others, allow the optimization of FISs for controlling different processes such as black-box problems [5][6][7][8][9][10].
FIS controllers simplify the control of complex systems without linearities and time variations, but their programming and configuration are more complex than classical approaches.However, there are several commercial alternatives for implementing and simulating FIS controllers.
The MATLAB™ fuzzy logic toolbox enables the design and implementation of FIS for control, modeling, and simulation [11].Current research papers that implement the MAT-LAB™ fuzzy logic toolbox investigate the following: reducing chemical oxygen demand in low-strength wastewater [12], controlling the speed of motors for robots [13], designing the control of a three-phase grid-connected inverter using a Raspberry Pi system [14], the design, modeling, and simulation of one-degree of freedom inverted pendulum [15], and designing a single-stage photovoltaic system with energy recovery control [16].
Additionally, "IT2-FLS" is another toolbox of MATLAB™ for implementing fuzzy logic of interval type 2. It includes different construction stages, including design, description, and implementation.However, it does not contain parameters or methods specific to control systems [17].
A commercial alternative for implementing and controlling FIS is National Instruments, whose LabVIEW™ software provides a graphical programming framework.In addition, LabVIEW™ allows the implementation of real-time controllers using the same brand of diving instruments, such as USB-6001/6002/6003/6211 and others [18].Lab-VIEW with FIS has shown promising results in controlling Carbon Dioxide Fertilization in a Greenhouse Environment [18], Air Valve for soprano recorders with automatic note recognition [19], Gain Scheduling of PID Controller Based on Fuzzy Systems [20], and a suspension system for a quarter-hour car [21], to name a few.
On the other hand, according to the 2022 TIOBE (The Importance of Being Earnest) index, Python is the most widely used programming language and has experienced significant growth in recent years (Figure 2) [22].
Greenhouse Environment [18], Air Valve for soprano recorders with automatic note recognition [19], Gain Scheduling of PID Controller Based on Fuzzy Systems [20], and a suspension system for a quarter-hour car [21], to name a few.
On the other hand, according to the 2022 TIOBE (The Importance of Being Earnest) index, Python is the most widely used programming language and has experienced significant growth in recent years (Figure 2) [22].
Python has specific libraries for implementing simulations and control using classical approaches with model analysis and control laws.Therefore, Python should have an open-source library for implementation and simulation with FIS controllers.In addition, most of the control libraries or toolboxes in Python are open-source-a philosophy for access to programs that allows code modifications, the sharing of contributions, and use under license restrictions intended to limit responsibility.
Using open-source libraries in Python offers numerous advantages for software development.First, open-source libraries approve developers to save time using algorithms already implemented for different proposals [23].Second, they provide high quality and reliability because they are constantly updated and maintained by a large and diverse community of developers [24].Third, open-source libraries are cost-effective because they do not require licensing fees, aiding organizations to allocate more resources to other areas of their project [25].Finally, using open-source libraries in Python has led to faster timeto-market and better product quality [26].
Despite that, there are other open-source alternatives for simulating FISs.They are related to developing expert systems and fuzzy logic in software applications.In addition, the control domain is not their priority, and they cannot simulate controllers with mathematical model descriptions, transfer functions, and inputs as a ramp or step response.
According to the Python Package Index (PyPI), the most relevant libraries for the implementation of FIS and fuzzy control include the average number of downloads based on Shield's IO statistics [27]: • "Fuzzy-logic-toolbox": Library licensed in 2020 based on the behavior in MATLAB TM without simulation of fuzzy controllers with an average of 47 downloads per month [28].

•
"Scikit-fuzzy": A library licensed in 2012 to popularize fuzzy logic in Python, agreeing to simulate and describe FIS using rounding arithmetic with IEEE (Institute of Electrical and Electronics Engineers) standards.However, simulations with transfer Python has specific libraries for implementing simulations and control using classical approaches with model analysis and control laws.Therefore, Python should have an open-source library for implementation and simulation with FIS controllers.In addition, most of the control libraries or toolboxes in Python are open-source-a philosophy for access to programs that allows code modifications, the sharing of contributions, and use under license restrictions intended to limit responsibility.
Using open-source libraries in Python offers numerous advantages for software development.First, open-source libraries approve developers to save time using algorithms already implemented for different proposals [23].Second, they provide high quality and reliability because they are constantly updated and maintained by a large and diverse community of developers [24].Third, open-source libraries are cost-effective because they do not require licensing fees, aiding organizations to allocate more resources to other areas of their project [25].Finally, using open-source libraries in Python has led to faster time-to-market and better product quality [26].
Despite that, there are other open-source alternatives for simulating FISs.They are related to developing expert systems and fuzzy logic in software applications.In addition, the control domain is not their priority, and they cannot simulate controllers with mathematical model descriptions, transfer functions, and inputs as a ramp or step response.
According to the Python Package Index (PyPI), the most relevant libraries for the implementation of FIS and fuzzy control include the average number of downloads based on Shield's IO statistics [27]: • "Fuzzy-logic-toolbox": Library licensed in 2020 based on the behavior in MAT-LAB™ without simulation of fuzzy controllers with an average of 47 downloads per month [28].

•
"Scikit-fuzzy": A library licensed in 2012 to popularize fuzzy logic in Python, agreeing to simulate and describe FIS using rounding arithmetic with IEEE (Institute of Electrical and Electronics Engineers) standards.However, simulations with transfer functions or mathematical models lack control structures such as fuzzy PID controllers.Shield's IO statistics state that it has an average of 26,000 times per month.
• "fuzzylab": Licensed in 2007, this is a library based on Octave Fuzzy Logic Toolkit 0.4.6.This library allows the simulation of FISs without including the implementation of controls with transfer functions, mathematical models, or other control structures in its methods.However, its developers used it to control an autonomous robot's navigation system [29,30], averaging 53 downloads per month.

•
"fuzzython": Released in 2013, it allows the construction of FIS, including the Mamdani, Sugeno, and Tsukamoto models, but it misses tools for working with fuzzy control or the simulation of systems with transfer function or state-space model descriptions [31], with an average of 12 downloads per month.

•
"Type2Fuzzy": Licensed in 2007, this library allows work with type 2 FIS, in general descriptions for software applications, but it does not include methods for working with transfer functions, state-space models, and fuzzy control [32] with an average of 53 downloads per month.

•
"Fuzzy-machines": This is a 2018 licensed library for working with FIS but does not include methods for working with fuzzy controllers, transfer functions, or state-space descriptions, with an average of 18 times per month.

•
"pyfuzzylite": A 2007 licensed Library for developing FIS and controllers 2007 over a graphic interface.It allows working in Mamdani, Takagi-Sugeno, Larsen, Tsukamoto, Inverse Tsukamoto, and Hybrids.However, it does not include fuzzy PID controllers or methods for simulation with transfer functions and state-space representations [33] from an average of 302 downloads per month.

•
"Simpful": It depends on "numpy" and "scipy" libraries.It has properties of polygonal and functional models.It allows the definition of fuzzy rules as text strings in natural language, the description of complex fuzzy two rules built with logical operators, and Mamdani and Takagi-Sugeno interference methods.However, it does not consider parameters for automatic control [33].Shield's IO statistics state that it has an average of 113,000 times per month.

•
"pyFume": It collects classes and methods for the antecedent set and associated parameters of a Takagi-Sugeno (TS) fuzzy system from data using the Simpful library.The antecedent set and related parameters of a Takagi-Sugeno fuzzy model are extracted from data and then building an executable fuzzy model using the Simpful library.It only applies fuzzy logic and does not consider automatic control parameters [34].Shield's IO statistics state that it has an average of 120,000 times per month.
In this work, we describe our proposal UPAFuzzySystems library developed in the Universidad Politécnica de Aguascalientes (UPA) as an FISs library for Python, which supports the design and implementation of the fuzzy controller with transfer function and state-state representations already published in open-source license in [34].In addition, our proposal uses the "control" library for simulation.According to Shield's statistics IO, the "control" library is the most used library for simulating controllers in Python, with 57,000 downloads per month.Furthermore, our proposal includes P, PD, PI, and PID fuzzy controller structures.This proposal is a novel idea since no other Python library allows the simulation and test of fuzzy controllers with transfer functions and state-space models.Furthermore, there are no other alternatives in Python for designing fuzzy controllers with PID structures.Moreover, we compare all these libraries in terms of their capabilities in designing FISs and fuzzy controllers and simulating them (Table 1).

Materials and Methods
FISs belong to the soft-computing methods because, unlike hard-computing methods, they consent to work with tolerances and imprecisions and make decisions under uncertainty.Moreover, our natural language deals with imprecision in inference because we allow fuzzy boundaries instead of well-defined ones [35,36].
FISs authorize using membership degrees in sets to express logic with fuzzy boundaries.The membership value µ defines the degree of membership in the ranges [0, 1].
A membership function µ(x) defines µ for each x point of the universe X in a fuzzy set A as in Equation (1).
For example, deciding whether a person is young or old, with an age's universe in the range [0, 100] years, one could use well-defined bounds (Figure 3a) to express a falsely narrow categorization or use FISs with trapezoidal µ(x) to correctly represent the imprecisions and uncertainties of the problem, as shown in Figure 3b.FISs belong to the soft-computing methods because, unlike hard-computing methods, they consent to work with tolerances and imprecisions and make decisions under uncertainty.Moreover, our natural language deals with imprecision in inference because we allow fuzzy boundaries instead of well-defined ones [35,36].
FISs authorize using membership degrees in sets to express logic with fuzzy boundaries.The membership value  defines the degree of membership in the ranges [0,1].
A membership function () defines  for each  point of the universe  in a fuzzy set  as in Equation (1).
For example, deciding whether a person is young or old, with an age's universe in the range [0,100] years, one could use well-defined bounds (Figure 3a) to express a falsely narrow categorization or use FISs with trapezoidal () to correctly represent the imprecisions and uncertainties of the problem, as shown in Figure 3b.
The FISs derive conclusions using logical IF-THEN rules, with premises using fuzzy sets and consequences that can use fuzzy sets for Mamdani, FLSmith; functions for Takagi-Sugeno; and raw numbers in fuzzy linear and PID controllers [5,36].The FISs structure includes the following phases: preprocessing, fuzzification, rule base, inference engine, defuzzification, and post-processing (Figure 4).
on empirical values or in the statistical metrics of a dataset by specifying the raw membership values and the corresponding element of the universe as in Equation (6) The FISs derive conclusions using logical IF-THEN rules, with premises using fuzzy sets and consequences that can use fuzzy sets for Mamdani, FLSmith; functions for Takagi-Sugeno; and raw numbers in fuzzy linear and PID controllers [5,36].The FISs structure includes the following phases: preprocessing, fuzzification, rule base, inference engine, defuzzification, and post-processing (Figure 4).IF-THEN rules imply working with connectives to define interactions midst premises represented with fuzzy sets.Moreover, these connectives agree with the definition of fuzzy composite sets in  dimensions that map interactions between premises.Connectives include the intersection (AND) and union (OR) operations, which are based on classical set theory but adapted to fuzzy logic.Equations ( 7) and (8) define the AND (∧) and OR (∨) connectives for nonlinear FIS, and Equations ( 9) and (10) define the AND (∧) and OR (∨) connectives for linear systems respectively, in that order [35,36].
After defining premises with their connectives, Implications (→), or Equivalences (↔) enable the derivation of conclusions or consequences with rules in the form IF-THEN of Equation (11).Implications more commonly used in controllers include the Mamdani implication in Equation (12), which gathers the consequence based on the fuzzy input universe X to the fuzzy output universe Y.The Mamdani and FLS controllers (FL Smidth) use this implication [5].
Alternatively, Takagi and Sugeno contain fuzzy rules that generate a set of linear functions depending on the premises.Takagi-Sugeno controllers generate output functions depending on the error and change in error as in Equation ( 13).Linear and fuzzy PID controllers and Takagi-Sugeno controllers use this approach [5].
Finally, defuzzification allows an appropriate scalar output for the controlled process or specific application of the FIS.There are several defuzzification methods, including Center of Gravity (COG) for continuous fuzzy sets in Equation ( 14), Center of Gravity for Singletons (COGS) (Equation ( 15) for singletons and Equation ( 16) for discrete systems), Bisector of Area (BOA) in Equation ( 17), Mean of Maxima (MOM) in Equation ( 18), Leftmost Maxima or Smallest of Maxima (LM) in Equation (19), and Rightmost Maxima or Largest of Maxima (RM) in Equation (20) [5,36]. ) FIS controllers apply different combinations of universes, membership functions, inference rules, connectives, implications, and defuzzification.However, all the configurations have common input premises that depend on the error and output consequences to change the process state.Table 2 describes some of these configurations.
The P controller has two gains, GE and GU, as shown in Figure 5. First, GE sets the control deviation of the plant to be in the ranges [−100, 100] required for this controller (Table 2).Then, GU sets the gain so that it is equal to K p of the previously designed classical P controller.Equations ( 21) and ( 22) determine the GE and GU, respectively [36].9) and (10) Equation ( 13) Equation ( 15) No-linear P Not defined Equations ( 7) and ( 8) Equation ( 11) Equations ( 14) No-linear PD Not defined Equations ( 7) and ( 8) Equation ( 11) Equations ( 14) No-linear PID Not defined Equations ( 7) and ( 8) Equation ( 11) Equations ( 14) The fuzzy P, PD, and PID controllers start with a linear structure, as in goal of using the linear approach is to first design a twin of a P, PD, or PID c the process with classic controllers.Then, the structure is changed to a no-This change allows having a no-linear FIS controller with the benefits of der integrals without having too complex rules [36].
The P controller has two gains,  and , as shown in Figure 5. First, control deviation of the plant to be in the ranges [−100,100] required for th (Table 2).Then,  sets the gain so that it is equal to   of the previously de sical P controller.Equations ( 21) and (22) determine the  and , resp The controller FIS PD in Figure 6 has three gains , , and .FI FIS P, uses  to adjust the error to be in the ranges [−100,100] and then us (22) to determine .Then,  is determined from the lead time   usi (23).The controller FIS PD in Figure 6 has three gains GE, GU, and GCE.FIS PD, of the FIS P, uses GE to adjust the error to be in the ranges [−100, 100] and then uses Equation ( 22) to determine GU.Then, GCE is determined from the lead time T d using Equation (23).

𝑮𝑪𝑬 = 𝑮𝑬 ⋅ 𝑻 𝒅
The controller FIS PID in Figure 7 uses the same structure as the controller PD with GE and GU for scaling the input with Equation ( 21) and obtaining the equivalent K p with Equation ( 22).Similarly, it uses GCE to map the derivative gain from the derivative time T d using Equation (23).However, FIS PID includes an integrative effect controlled by the gain GIE and maps the effect of the integrative time T i , thus Equation (24).
The controller FIS PD in Figure 6 has three gains , , and .FI FIS P, uses  to adjust the error to be in the ranges [−100,100] and then us (22) to determine .Then,  is determined from the lead time   usin (23).The controller FIS PID in Figure 7 uses the same structure as the contro  and  for scaling the input with Equation ( 21) and obtaining the eq with Equation (22).Similarly, it uses  to map the derivative gain from th time   using Equation (23).However, FIS PID includes an integrative effe by the gain  and maps the effect of the integrative time   , thus Equatio Having defined the linear structures FIS P, PD, and PID, let us explain t system with the IF-THEN rules.The conditions and consequences for these r on the type of FIS controller.Linear P, Linear PD, and Linear PID, for examp similar to those of the linear controller to create a clone of a classical controll sign stage.Then, they switch to no-linear rules such as those used in Mamd Takagi-Sugeno controllers [36].Table 3 shows the type of rules used in differ trollers.Having defined the linear structures FIS P, PD, and PID, let us explain the inference system with the IF-THEN rules.The conditions and consequences for these rules depend on the type of FIS controller.Linear P, Linear PD, and Linear PID, for example, use rules similar to those of the linear controller to create a clone of a classical controller in the design stage.Then, they switch to no-linear rules such as those used in Mamdani, FLS, or Takagi-Sugeno controllers [36].Table 3 shows the type of rules used in different FIS controllers.

𝑮𝑪𝑬 = 𝑮𝑬 ⋅ 𝑻 𝒅
Our proposed library UPAFuzzySystems for Python is already published as an opensource license.It implements fuzzy universes with fuzzy sets, FIS systems, and FIS controllers with a simple definition of all required parameters by three different Python classes fuzzy_universe, inference_system, and fuzzy_controller.All the codes of UPAFuzzySystems are in [34].
The class fuzzy_universe is the first-level definition, i.e., all other classes require it for describing premises or consequences with fuzzy universes.A continuous or discrete fuzzy universe contains fuzzy sets defined in the universe with membership values for defining certain situations.The class fuzzy_universe also has several methods for adding and removing fuzzy sets with all membership functions from Equations ( 2)-( 6), all of which can be found in [34].
The class fuzzy_inference is the second-level class.It allows the description of the IF-THEN rules using the premises and consequences defined with the class fuzzy_universe.Moreover, the class fuzzy_controller uses it to specify its IF-THEN rules.All methods related to fuzzy_inference class are in [33].Finally, the class controller defines the fuzzy controllers with specific structures and simulates their behavior with transfer functions and state-space equations.All methods for working with the class fuzzy_controllers are in [34].

Results and Discussion
The results in this section cover the steps and results in implementing fuzzy universes, fuzzy inference systems, and fuzzy controllers with UPAFuzzySystems.

Important Libraries
When working with figures in Python, the "matplotlib" library is used and imported in line 1 of Code 1.Then, in line 2, the proposed library "UPAFuzzySystems" is inserted to implement fuzzy universes, inference systems, and controllers.Then, we import the "numpy" library in line 3 to define vectors, matrices, and operations with numbers.Finally, the "control" library in line 4 allows defining transfer functions and state-space equations for simulation.The Python code to import the libraries is in Code 1.

Fuzzy Universes with Fuzzy_Universe Class
After importing the main libraries, an example of fuzzy universes with a description of Collision Distances from 0 to 60 m in near, middle, and long-range allows explaining the use of the fuzzy_universe class in the "UPAFuzzySystems" library.
Code 2 in line 1 defines the universe from 0 to 60 with 100 samples using a "numpy" library.Then, line 2 corresponds to an instance of the class fuzzy_universe, passing the name of the universe and the instruction to perform a continuous universe.
Next, we add fuzzy sets for all collision regions in lines 3-5 by passing the name of the fuzzy set, the type of fitness function, and its vertices.This example uses trapezoidal and triangular membership functions according to Equations ( 2) and ( 3), respectively.
Finally, in line 6, we access the plot of the fuzzy_universe, and in lines 7-10, the figure was modified to change the axis names.All the Python code for the implementation is in Figure 8 shows the results obtained with the view_fuzzy method executed in line 6 of Code 2 and the updated information in the axis.

Fuzzy Inference System with Inference_System Class
The IF-THEN rules of an inference system require premises and consequences.Therefore, we define a consequence of speed for the premise defined in Section 3.2.We follow the approach described in Code 2 and create the consequence in Figure 9.

Fuzzy Inference System with Inference_System Class
The IF-THEN rules of an inference system require premises and consequen Therefore, we define a consequence of speed for the premise defined in Section 3.2 follow the approach described in Code 2 and create the consequence in Figure 9.After that, we set the rules for the FIS: in this case, a slow speed for a near coll distance, a medium speed for a medium-range collision distance, and a fast speed far-range collision distance.In other words, the rules: Code 3 defines the inference system.First, we create an instance of the class i ence_system and pass the name to assign in line 1.Then, lines 2 and 3 define the pre and the consequence, respectively.Next, lines 4-6 describe the rules for the FIS, pass list of premises with a list per premise with its name and the corresponding fuzz name, a list of connectives, and a list of consequences with a list per consequence wit

Fuzzy Inference System with Inference_System Class
The IF-THEN rules of an inference system require premises and consequen Therefore, we define a consequence of speed for the premise defined in Section 3.2.follow the approach described in Code 2 and create the consequence in Figure 9.After that, we set the rules for the FIS: in this case, a slow speed for a near colli distance, a medium speed for a medium-range collision distance, and a fast speed f far-range collision distance.In other words, the rules: Code 3 defines the inference system.First, we create an instance of the class in ence_system and pass the name to assign in line 1.Then, lines 2 and 3 define the prem and the consequence, respectively.Next, lines 4-6 describe the rules for the FIS, passi list of premises with a list per premise with its name and the corresponding fuzzy name, a list of connectives, and a list of consequences with a list per consequence wit name and the corresponding fuzzy set name.
Hence, in line 7, the type of rules is configured.In this case, the Mamdani sys with its configuration is shown in Table 2.Then, in line 8, the FIS is created.To display system's surface in line 9, call the method surface_fuzzy_system and pass a lis After that, we set the rules for the FIS: in this case, a slow speed for a near collision distance, a medium speed for a medium-range collision distance, and a fast speed for a far-range collision distance.In other words, the rules: Code 3 defines the inference system.First, we create an instance of the class infer-ence_system and pass the name to assign in line 1.Then, lines 2 and 3 define the premise and the consequence, respectively.Next, lines 4-6 describe the rules for the FIS, passing a list of premises with a list per premise with its name and the corresponding fuzzy set name, a list of connectives, and a list of consequences with a list per consequence with its name and the corresponding fuzzy set name.
Hence, in line 7, the type of rules is configured.In this case, the Mamdani system with its configuration is shown in Table 2.Then, in line 8, the FIS is created.To display the system's surface in line 9, call the method surface_fuzzy_system and pass a list of "numpy" arrays, one per input premise, as before.Finally, lines 10-13 handle the axis labels.The Python code to define the inference system is in Code 3. The surface obtained is in Figure 10.

Fuzzy Controller with Fuzzy_Controller Class
Let us define the Direct Current (DC) motor position as the process variable to control.The parameters and the transfer function are in Table 4. Ref. [38] details the DC motor used and the process for obtaining its model.Code 4 shows the code for defining the transfer function, its parameters, a test input, and a test signal with disturbances using the control library.The test input starts at zero and gradually changes in 5 ms to the equivalent radian for 45° (0.78539816 rad) 0.25 s later.Lines 1-7 give the parameters, line 8 describes the universe, line 9 generates the input, line

Fuzzy Controller with Fuzzy_Controller Class
Let us define the Direct Current (DC) motor position as the process variable to control.The parameters and the transfer function are in Table 4. Ref. [38] details the DC motor used and the process for obtaining its model.Code 4 shows the code for defining the transfer function, its parameters, a test input, and a test signal with disturbances using the control library.The test input starts at zero and gradually changes in 5 ms to the equivalent radian for 45 • (0.78539816 rad) 0.25 s later.Lines 1-7 give the parameters, line 8 describes the universe, line 9 generates the input, line 10 defines the starting seed for randomness, line 11 represents the uniform random perturbation around 10% of the reference input, line 12 defines the s term for the frequency space, and line 13 stipulates the transfer function.Once we define the input and the plant's transfer function, we describe the controller's structure.In this case, a feedback controller with a fuzzy control system (Figure 11).
10 defines the starting seed for randomness, line 11 represents the uniform random perturbation around 10% of the reference input, line 12 defines the  term for the frequency space, and line 13 stipulates the transfer function.Once we define the input and the plant's transfer function, we describe the controller's structure.In this case, a feedback controller with a fuzzy control system (Figure 11).Moreover, we define a control structure, including random perturbations expected as a 10% reference input or (), to test the fuzzy controllers' robustness (Figure 12).

One-Input Mamdani Fuzzy Controller
After defining the system, we design the fuzzy controller with premises and consequences concerning the error and the control behavior.Therefore, we implement these premises following the approach in Code 2. First, defining a single error input with a universe in the ranges [−100,100] of the angular position in rad and then a single output controller with a universe [−20,20] volt (V). Figure 13 shows the premise, and Figure 14 shows the consequence.Moreover, we define a control structure, including random perturbations expected as a 10% reference input or X(s), to test the fuzzy controllers' robustness (Figure 12). 10 defines the starting seed for randomness, line 11 represents the uniform random perturbation around 10% of the reference input, line 12 defines the  term for the frequency space, and line 13 stipulates the transfer function.Once we define the input and the plant's transfer function, we describe the controller's structure.In this case, a feedback controller with a fuzzy control system (Figure 11).Moreover, we define a control structure, including random perturbations expected as a 10% reference input or (), to test the fuzzy controllers' robustness (Figure 12).

One-Input Mamdani Fuzzy Controller
After defining the system, we design the fuzzy controller with premises and consequences concerning the error and the control behavior.Therefore, we implement these premises following the approach in Code 2. First, defining a single error input with a universe in the ranges [−100,100] of the angular position in rad and then a single output controller with a universe [−20,20] volt (V). Figure 13 shows the premise, and Figure 14 shows the consequence.

One-Input Mamdani Fuzzy Controller
After defining the system, we design the fuzzy controller with premises and consequences concerning the error and the control behavior.Therefore, we implement these premises following the approach in Code 2. First, defining a single error input with a universe in the ranges [−100, 100] of the angular position in rad and then a single output controller with a universe [−20, 20] volt (V). Figure 13 shows the premise, and Figure 14 shows the consequence.Subsequently obtaining premises and consequences, we define the rules for the using the approach described in Code 3. The fuzzy rules used for the controller are: Next, we set the system configuration given in Table 2 for a Mamdani inference tem.Then, we simulate the FIS.The surface generated for the simulation of the rule shown in Figure 15.Subsequently obtaining premises and consequences, we define the rules for the using the approach described in Code 3. The fuzzy rules used for the controller are: Next, we set the system configuration given in Table 2 for a Mamdani inference tem.Then, we simulate the FIS.The surface generated for the simulation of the rule shown in Figure 15.Subsequently obtaining premises and consequences, we define the rules for the FIS using the approach described in Code 3. The fuzzy rules used for the controller are: Next, we set the system configuration given in Table 2 for a Mamdani inference system.Then, we simulate the FIS.The surface generated for the simulation of the rules is shown in Figure 15.
Then, using the inference system defined and stored in the variable Mamdani1, we create an instance of the class fuzzy_controller, passing the inference system, the type of inference system (in this case, fuzzy with one input), the transfer function, and the sampling time, as in line 1 of Code 5. Line 2 builds the controller.Line 3 provides the fuzzy controller for simulation with processes defined in the space of the state model.Finally, line 4 returns the system with the transfer function for simulation.

IF Error is
Next, we set the system configuration given in Table 2 for a Mamdani infere tem.Then, we simulate the FIS.The surface generated for the simulation of the shown in Figure 15.Once we obtained the system with the transfer function for simulation in line 4 of Code 5, we solved the simulation using the control library in line 1 and plotted the results in lines 2-7 of Code 6. Figure 16 shows the simulation results of the DC motor position (blue) controlled with the fuzzy controller while summited to the input created (orange).The absolute error is 1.92 × 10 −11 , and the absolute percentage error is 2.45 × 10 −9 % in steady conditions.The maximum value reached is 8.47 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the end value is 7.85 × 10 −1 rad, the time rising is 3.86 × 10 −2 s, the overshoot is 7.87%, the time peak is 7.46 × 10 −2 s, and the settling time is 1.25 × 10 −1 s.
Then, using the inference system defined and stored in the variable Mamdani1, we create an instance of the class fuzzy_controller, passing the inference system, the type of inference system (in this case, fuzzy with one input), the transfer function, and the sampling time, as in line 1 of Code 5. Line 2 builds the controller.Line 3 provides the fuzzy controller for simulation with processes defined in the space of the state model.Finally, line 4 returns the system with the transfer function for simulation.Code 6. Python code for simulation of fuzzy controller and plotting results.
Figure 16 shows the simulation results of the DC motor position (blue) controlled with the fuzzy controller while summited to the input created (orange).The absolute error is 1.92 × 10 −11 , and the absolute percentage error is 2.45 × 10 −9 % in steady conditions.The maximum value reached is 8.47 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the end value is 7.85 × 10 −1 rad, the time rising is 3.86 × 10 −2 s, the overshoot is 7.87%, the time peak is 7.46 × 10 −2 s, and the settling time is 1.25 × 10 −1 s.   Figure 17 shows the simulation results of the DC motor position (blue) con with the fuzzy controller while summited to the input created (orange) and the d ance signal (green).The absolute error is 1.20 × 10 −2 , and the absolute percentag is 1.53% in steady conditions.The maximum value reached is 8.60 × 10 −1 rad, th mum value is 0.00 rad, the start value is 0.00 rad, the end value is 7.97 × 10 −1 r time rising is 3.86 × 10 −2 s, the overshoot is 7.86%, the time peak is 7.26 × 10 −2 the settling time is 6.38 × 10 −1 s.

One-Input FLS Controller
Using the same rules as for the Mamdani controller with one input and th fuzzy sets, we define the FLS controller.Nevertheless, we configure the UPAFuz tems library to work with the FLS structure and modify the connectives and impli described in Table 2. Code 7 shows the lines that define the inference system for t controller.Line 7 is the one that differs from a Mamdani controller and configu inference system for the FLS controller structure.For coding the FLS inference system, we simulate the system's surface over th universe using the method described in Code 3 and obtain the results shown in Fig Figure 17.DC motor position controlled with a Mamdani controller, including disturbances in the input of the plant.
Figure 17 shows the simulation results of the DC motor position (blue) controlled with the fuzzy controller while summited to the input created (orange) and the disturbance signal (green).The absolute error is 1.20 × 10 −2 , and the absolute percentage error is 1.53% in steady conditions.The maximum value reached is 8.60 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the end value is 7.97 × 10 −1 rad, the time rising is 3.86 × 10 −2 s, the overshoot is 7.86%, the time peak is 7.26 × 10 −2 s, and the settling time is 6.38 × 10 −1 s.

One-Input FLS Controller
Using the same rules as for the Mamdani controller with one input and the same fuzzy sets, we define the FLS controller.Nevertheless, we configure the UPAFuzzySystems library to work with the FLS structure and modify the connectives and implications described in Table 2. Code 7 shows the lines that define the inference system for the FLS controller.Line 7 is the one that differs from a Mamdani controller and configures the inference system for the FLS controller structure.For coding the FLS inference system, we simulate the system's surface over the input universe using the method described in Code 3 and obtain the results shown in Figure 18.
For coding the FLS inference system, we simulate the system's surface over th universe using the method described in Code 3 and obtain the results shown in Fig Figure 18.Surface obtained with the one-input FlS controller.In the next step, we build and simulate the controller using the methods in Code 5 and Code 6.The simulation results show a smoother response than the Mamdani controller and avoid overshooting the system response (Figure 19).The absolute error is 1.35 × 10 −3 , and the absolute percentage error is 1.72 × 10 −1 % at steady state.The maximum value achieved is 7.84 × 10 −1 rad, the minimum value −2.39 × 10 −16 rad, the start value −8.40 × 10 −17 rad, the final value 7.84 × 10 −1 rad, the rise time 1.71 × 10 −1 s, the overshoot 0.00%, the peak time 7.22 × 10 −1 s, and the settling time 3.71 × 10 −1 s.
In the next step, we build and simulate the controller using the methods in and Code 6.The simulation results show a smoother response than the Mamdani c ler and avoid overshooting the system response (Figure 19).Similarly, we test the FLS controller with one input, including the disturbances at the input of the plant, as in the block diagram in Figure 12.The results are shown in Figure 20.
In the next step, we build and simulate the controller using the methods in and Code 6.The simulation results show a smoother response than the Mamdani c ler and avoid overshooting the system response (Figure 19).The absolute e 1.35 × 10 −3 , and the absolute percentage error is 1.72 × 10 −1 % at steady state.Th mum value achieved is 7.84 × 10 −1 rad, the minimum value −2.39 × 10 −16 rad, t value −8.40 × 10 −17 rad, the final value 7.84 × 10 −1 rad, the rise time 1.71 × 10 − overshoot 0.00%, the peak time 7.22 × 10 −1 s, and the settling time 3.71 × 10 −1 s  Figure 20 shows the results of the FLS controller with one input and signal d ance for the DC motor position (blue) while summited to the input created (oran the disturbance signal (green).The absolute error is 7.18 × 10 −3 , and the absolute p age error is 9.14 × 10 −1 % in steady conditions.The maximum value reac 7.93 × 10 −1 rad, the minimum value is −2.39 × 10 −16 rad, the start value is − 10 −17 rad, the end value is 7.93 × 10 −1 rad, the time rising is 1.99 × 10 −1 s, the ov is 0.00%, the time peak is 7.22 × 10 −1 s, and the settling time is 6.80 × 10 −1 s. Figure 20 shows the results of the FLS controller with one input and signal disturbance for the DC motor position (blue) while summited to the input created (orange) and the disturbance signal (green).The absolute error is 7.18 × 10 −3 , and the absolute percentage error is 9.14 × 10 −1 % in steady conditions.The maximum value reached is 7.93 × 10 −1 rad, the minimum value is −2.39 × 10 −16 rad, the start value is −8.40 × 10 −17 rad, the end value     The surface simulation using the method described in Code 3 is shown in Figure 23 where the output is a second-order response resulting from the second-order functions in the output universe.Finally, we configure the controller using the same method as in Code 5 and presen the simulation results with the approach in Code 6. Figure 24 shows the results of th simulation.The absolute error is 1 .22 × 10 −8 , and the absolute percentage error i 1.55 × 10 −6 % under stable conditions.The maximum value obtained is 7.85 × 10 −1 rad the minimum value is 0.00 rad, the start value is 0.00 rad, the end value is 7.85 × 10 − rad, the rise time is 1.25 × 10 −1 s, the overshoot is 0.00%, the peak time is 7.22 × 10 −1 s and the settling time is 1.91 × 10 −1 s.The surface simulation using the method described in Code 3 is shown in Figure 23, where the output is a second-order response resulting from the second-order functions in the output universe.The surface simulation using the method described in Code 3 is shown in Figure 23 where the output is a second-order response resulting from the second-order functions in the output universe.Finally, we configure the controller using the same method as in Code 5 and presen the simulation results with the approach in Code 6. Figure 24 shows the results of th simulation.The absolute error is 1 .22 × 10 −8 , and the absolute percentage error i 1.55 × 10 −6 % under stable conditions.The maximum value obtained is 7.85 × 10 −1 rad the minimum value is 0.00 rad, the start value is 0.00 rad, the end value is 7.85 × 10 − rad, the rise time is 1.25 × 10 −1 s, the overshoot is 0.00%, the peak time is 7.22 × 10 −1 s and the settling time is 1.91 × 10 −1 s.Finally, we configure the controller using the same method as in Code 5 and present the simulation results with the approach in Code 6. Figure 24 shows the results of the simulation.The absolute error is 1.22 × 10 −8 , and the absolute percentage error is 1.55 × 10 −6 % under stable conditions.The maximum value obtained is 7.85 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the end value is 7.85 × 10 −1 rad, the rise time is 1.25 × 10 −1 s, the overshoot is 0.00%, the peak time is 7.22 × 10 −1 s, and the settling time is 1.91 × 10 −1 s.Finally, we configure the controller using the same method as in Code 5 and present the simulation results with the approach in Code 6. Figure 24 shows the results of the simulation.The absolute error is 1 .22 × 10 −8 , and the absolute percentage error is 1.55 × 10 −6 % under stable conditions.The maximum value obtained is 7.85 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the end value is 7.85 × 10 −1 rad, the rise time is 1.25 × 10 −1 s, the overshoot is 0.00%, the peak time is 7.22 × 10 −1 s, and the settling time is 1.91 × 10 −1 s.Again, we test the Takagi-Sugeno controller with one input, including the disturbance at the input of the plant, as in the block diagram in Figure 12.The results are in Figure 25.
Again, we test the Takagi-Sugeno controller with one input, including the disturbance at the input of the plant, as in the block diagram in Figure 12.The results are in Figure 25. Figure 25 shows the results of the Takagi-Sugeno controller with one input and signa disturbance for the DC motor position (blue) while summited to the input created (orange) and the disturbance signal (green).The absolute error is 1.35 × 10 −2 , and the absolute percentage error is 1.72 % in steady conditions.The maximum value reached is 8.00 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the end value is 7.99 × 10 −1 rad, the time rising is 1.33 × 10 −1 s, the overshoot is 1.60 × 10 −1 %, the time peak is 5.28 × 10 −1 s, and the settling time is 6.54 × 10 −1 s.

Two-Input Mamdani Controller
The definition of the two-input Mamdani controller implies the definition of two premises, the first for the error and the second as the change in it or its derivative.Therefore, we specify three universes: one for the error premise, one for the change in the error premise, and another for the control consequence.The required code uses the same approach as in Code 2. The premises and consequences for the two-input Mamdani control ler are in Figures 26-28.Figure 25 shows the results of the Takagi-Sugeno controller with one input and signal disturbance for the DC motor position (blue) while summited to the input created (orange) and the disturbance signal (green).The absolute error is 1.35 × 10 −2 , and the absolute percentage error is 1.72% in steady conditions.The maximum value reached is 8.00 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the end value is 7.99 × 10 −1 rad, the time rising is 1.33 × 10 −1 s, the overshoot is 1.60 × 10 −1 %, the time peak is 5.28 × 10 −1 s, and the settling time is 6.54 × 10 −1 s.

Two-Input Mamdani Controller
The definition of the two-input Mamdani controller implies the definition of two premises, the first for the error and the second as the change in it or its derivative.Therefore, we specify three universes: one for the error premise, one for the change in the error premise, and another for the control consequence.The required code uses the same approach as in Code 2. The premises and consequences for the two-input Mamdani controller are in  premises, the first for the error and the second as the change in it or its derivative.fore, we specify three universes: one for the error premise, one for the change in th premise, and another for the control consequence.The required code uses the sa proach as in Code 2. The premises and consequences for the two-input Mamdani c ler are in Figures 26-28.Having specified the premises and consequences of the two-input Mamdani controller, we define the nine rules in the instance of the inference_system class of the UPAFuzzy-Systems library for each possible combination between inputs, following the structure described in Table 3.Thus, the specified rules are: The code to define these rules in the proposed library with the two-input Mamdani controller is in Code 9. Having specified the premises and consequences of the two-input Mamdani controller, we define the nine rules in the instance of the inference_system class of the UPAFuzzySystems library for each possible combination between inputs, following the structure described in Table 3.Thus, the specified rules are: 1.
If error is Neg and change error is Neg then control is Neg; 2.
If error is Neg and change error is Zero then control is Neg; 3.
If error is Zero and change error is Neg then control is Zero; 4.
If error is Neg and change error is Pos then control is Zero; 5.
If error is Zero and change error is Zero then control is Zero; 6.
If error is Zero and change error is Pos then control is Zero; 7.
If error is Pos and change error is Neg then control is Zero; 8.
If error is Pos and change error is Zero then control is Pos; 9.
If error is Pos and change error is Pos then control is Pos.
The code to define these rules in the proposed library with the two-input Mamdani controller is in Code 9.
Then, we obtain the surface response for the two-input Mamdani controller by simulating the error and the change in error inputs as defined in Code 3. Nevertheless, we now use two inputs for the surface simulation.Figure 29 shows the simulated surface.
, x FOR PEER REVIEW Two-input Mamdani controller surface using the UPAFuzzySystems library.
After defining the rules and simulating the surface, we configure the fuzzy_c we set the type of the controller to Fuzzy2 now has two inputs.The Python code for the configuration changes only in lin the Fuzzy2 definition (Code 10).
Python code for configuring two-input Mamdani controller using the UPAFuzz library.
mdani2 Finally, we simulate the controller using the approach described in Code 6. F shows the obtained controller's response.The absolute error is After defining the rules and simulating the surface, we configure the fuzzy_controller as before, but this time, we set the type of the controller to Fuzzy2, since the controller now has two inputs.The Python code for the configuration changes only in line one with the Fuzzy2 definition (Code 10).Finally, we simulate the controller using the approach described in Code 6. Figure 30 shows the obtained controller's response.The absolute error is 2.00 × 10 −6 rad, and the absolute percentage error is 2.54 × 10 −4 % at steady state.The maximum value reached is 8.12 × 10 −1 rad, the minimum value is −7.99 × 10 −18 rad, the start value is −4.28 × 10 −18 rad, the final value is 7.85 × 10 −1 rad, the rise time is 2.66 × 10 −2 s, the overshoot time is 3.33%, the peak time is 4.46 × 10 −2 s, and the settling time is 1.47 × 10 −1 s. absolute percentage error is 2.54 × 10 −4 % at steady state.The maximum valu is 8.12 × 10 −1 rad, the minimum value is −7.99 × 10 −18 rad, the star −4.28 × 10 −18 rad, the final value is 7.85 × 10 −1 rad, the rise time is 2.66 × 1 overshoot time is 3.33 %, the peak time is 4.46 × 10 −2 s, and the settlin 1.47 × 10 −1 s.   Figure 31 shows the results of the Mamdani controller with two inputs disturbance for the DC motor position (blue) while summited to the input create and the disturbance signal (green).The absolute error is 2.88 × 10 −2 , and th percentage error is 3.66 % in steady conditions.The maximum value r 8.25 × 10 −1 rad, the minimum value is −7.99 × 10 −18 rad, the start value i 10 −18 rad, the end value is 7.57 × 10 −1 rad, the time rising is 2.66 × 10 −2 s, the is 9.09%, the time peak is 6.62 × 10 −1 s, and the settling time is 7.14 × 10 −1 s 3.4.5.Two-Input FLS Controller Using the same rules as for the two-input Mamdani controller and the s sets, we define the two-input FLS controller.Nevertheless, we configure the U Systems library to work with the FLS structure and change the connectives an tions described in Table 2. Figure 32 displays the simulated surface for the two controller.Figure 31 shows the results of the Mamdani controller with two inputs and signal disturbance for the DC motor position (blue) while summited to the input created (orange) and the disturbance signal (green).The absolute error is 2.88 × 10 −2 , and the absolute percentage error is 3.66% in steady conditions.The maximum value reached is 8.25 × 10 −1 rad, the minimum value is −7.99 × 10 −18 rad, the start value is −4.28 × 10 −18 rad, the end value is 7.57 × 10 −1 rad, the time rising is 2.66 × 10 −2 s, the overshoot is 9.09%, the time peak is 6.62 × 10 −1 s, and the settling time is 7.14 × 10 −1 s.

Two-Input FLS Controller
Using the same rules as for the two-input Mamdani controller and the same fuzzy sets, we define the two-input FLS controller.Nevertheless, we configure the UPAFuzzySystems library to work with the FLS structure and change the connectives and implications described in Table 2. Figure 32 displays the simulated surface for the two-input FLS controller.Finally, we simulate the FLS controller using the approach described in Code 6. Figure 33 represents the controller's response obtained.This time, the absolute error is 3.59 × 10 −4 , and the absolute percentage error is 4.58 × 10 −2 %.The maximum value reached is 7.85 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the final value is 7.85 × 10 −1 rad, the rise time is 2.37 × 10 −1 s, the overshoot is 0.00 %, the time peak is 7.22 × 10 −1 s, and the settling time is 3.79 × 10 −1 s.Again, we test the FLS controller with two inputs, including the disturbance input of the plant, as shown in the block diagram in Figure 12.The results are sh Figure 34.Again, we test the FLS controller with two inputs, including the disturbances at the input of the plant, as shown in the block diagram in Figure 12.The results are shown in Figure 34.
Figure 34 shows the results of the FLS controller with two inputs and signal disturbance for the DC motor position (blue) while summited to the input created (orange) and the disturbance signal (green).The absolute error is 1.11 × 10 −2 , and the absolute percentage error is 1.41% in steady conditions.The maximum value reached is 7.96 × 10 −1 rad, the minimum value is −5.79 × 10 −5 rad, the start value is 0.00 rad, the end value is 7.96 × 10 −1 rad, the time rising is 2.67 × 10 −1 s, the overshoot is 0.00 %, the time peak is 7.22 × 10 −1 s, and the settling time is 6.74 × 10 −1 s.Again, we test the FLS controller with two inputs, including the disturbance input of the plant, as shown in the block diagram in Figure 12.The results are sh Figure 34. Figure 34 shows the results of the FLS controller with two inputs and signal ance for the DC motor position (blue) while summited to the input created (oran the disturbance signal (green).The absolute error is 1.11 × 10 −2 , and the absolute p age error is 1.41% in steady conditions.The maximum value reached is 7.96 × 10 the minimum value is −5.79 × 10 −5 rad, the start value is 0.00 rad, the end 7.96 × 10 −1 rad, the time rising is 2.67 × 10 −1 s, the overshoot is 0.00 %, the tim is 7.22 × 10 −1 s, and the settling time is 6.74 × 10 −1 s.

Two Inputs Takagi-Sugeno Controller
In this case, we define the control consequence in the Takagi-Sugeno config for two inputs, as described in Table 1.The premises are identical to the Mamd FLS controllers with two inputs.Therefore, the consequence definition now ha functions related to the error and change in error premises.Next, we introduce t with the inference system class.Again, these are the same as the Mamdani and F trollers with two inputs.The Python code to define the fuzzy universe with fuzzy s the inference system for the Takagi-Sugeno controller with two inputs is in Code Code 11.Code for defining the inference system and the fuzzy universe for the two-input Sugeno controller.

1)
Figure 34.Two-input FLS controller response with disturbances.In this case, we define the control consequence in the Takagi-Sugeno configuration for two inputs, as described in Table 1.The premises are identical to the Mamdani and FLS controllers with two inputs.Therefore, the consequence definition now has three functions related to the error and change in error premises.Next, we introduce the rules with the inference system class.Again, these are the same as the Mamdani and FLS controllers with two inputs.The Python code to define the fuzzy universe with fuzzy sets and the inference system for the Takagi-Sugeno controller with two inputs is in Code 11.
Figure 35 displays the output consequence, which differs from the two-input Mamdani and FLS controllers, in that the output premises are functions of the error and its change.
Here, the premises are identical to those in Figures 26 and 27.After defining the universes and configuring the FIS, we simulate the Takagi surface reaction with two inputs according to the method in Code 3. The resul Figure 36.After defining the universes and configuring the FIS, we simulate the Takagi-Sugeno surface reaction with two inputs according to the method in Code 3. The results are in Figure 36.We then define the controller configuration according to Code 5, modified for the Takagi-Sugeno structure, and plot the results using the approach in Code 6. Figure 37 shows the controller response.The absolute error is 3.16 × 10 −12 , and the absolute percentage error is 4.02 × 10 −10 % under stable conditions.The maximum value obtained is 7.96 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the final value is 7.85 × 10 −1 rad, the rise time is 6.66 × 10 −2 s, the overshoot is 1.37%, the time peak is 1.21 × 10 −1 s, and the settling time is 8.47 × 10 −2 s.We then define the controller configuration according to Code 5, modified Takagi-Sugeno structure, and plot the results using the approach in Code 6. Fig shows the controller response.The absolute error is 3.16 × 10 −12 , and the absolu centage error is 4.02 × 10 −10 % under stable conditions.The maximum value obta 7.96 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, th value is 7.85 × 10 −1 rad, the rise time is 6.66 × 10 −2 s, the overshoot is 1.37%, t peak is 1.21 × 10 −1 s, and the settling time is 8.47 × 10 −2 s.Similarly, we test the Takagi-Sugeno controller with two inputs, including turbances at the input of the plant, as shown in the block diagram in Figure 12.The are in Figure 38. Figure 38 shows the results of the two-input Takagi-Sugeno controller with disturbance for the DC motor position (blue) while summited to the input created ( and the disturbance signal (green).The absolute error is 1.07 × 10 −2 , and the a percentage error is 1.37 % in steady conditions.The maximum value reac 8.02 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the en Similarly, we test the Takagi-Sugeno controller with two inputs, including the disturbances at the input of the plant, as shown in the block diagram in Figure 12.The results are in Figure 38.We then define the controller configuration according to Code 5, modified for the Takagi-Sugeno structure, and plot the results using the approach in Code 6. Figure 37 shows the controller response.The absolute error is 3.16 × 10 −12 , and the absolute percentage error is 4.02 × 10 −10 % under stable conditions.The maximum value obtained is 7.96 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the final value is 7.85 × 10 −1 rad, the rise time is 6.66 × 10 −2 s, the overshoot is 1.37%, the time peak is 1.21 × 10 −1 s, and the settling time is 8.47 × 10 −2 s.Similarly, we test the Takagi-Sugeno controller with two inputs, including the disturbances at the input of the plant, as shown in the block diagram in Figure 12.The results are in Figure 38. Figure 38 shows the results of the two-input Takagi-Sugeno controller with signal disturbance for the DC motor position (blue) while summited to the input created (orange) and the disturbance signal (green).The absolute error is 1.07 × 10 −2 , and the absolute percentage error is 1.37 % in steady conditions.The maximum value reached is 8.02 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the end value Figure 38 shows the results of the two-input Takagi-Sugeno controller with signal disturbance for the DC motor position (blue) while summited to the input created (orange) and the disturbance signal (green).The absolute error is 1.07 × 10 −2 , and the absolute percentage error is 1.37% in steady conditions.The maximum value reached is 8.02 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the end value is 7.96 × 10 −1 rad, the time rising is 6.66 × 10 −2 s, the overshoot is 7.07 × 10 −1 %, the time peak is 5.22 × 10 −1 s, and the settling time is 6.34 × 10 −1 s.

Linear P Fuzzy Controller
The UPAFuzzySystems library also contains the linear P controller with the structure shown in Figure 5.To work with this structure, the configured inference base configured is linear.Therefore, the fuzzy_universe and inference_system classes configure the premises, consequences, and rules to define a linear controller.Since the P fuzzy controller requires no change in error input, the linear system definition uses only a premise in the error case and a consequence controller, which are comparable in Table 2. Code 12 provides the premise, consequence, and required rules.
Figures 39 and 40 display the premise and consequence plot for the linear system defined for working with the linear fuzzy P controller according to Table 2.
Employing the same approach in Code 3, we simulate the linear system's surface, which must be a line, as shown in Figure 41.3.5. P,PD,and PID Fuzzy Controllers 3.5.1. Linear P Fuzzy Controller The UPAFuzzySystems library also contains the linear P controller with the structure shown in Figure 5.To work with this structure, the configured inference base configured is linear.Therefore, the fuzzy_universe and inference_system classes configure the premises, consequences, and rules to define a linear controller.Since the P fuzzy controller requires no change in error input, the linear system definition uses only a premise in the error case and a consequence controller, which are comparable in Table 2. Code 12 provides the premise, consequence, and required rules.
Figures 39 and 40 display the premise and consequence plot for the linear system defined for working with the linear fuzzy P controller according to Table 2.   Employing the same approach in Code 3, we simulate the linear system's surface which must be a line, as shown in Figure 41.When the linear inference system is defined, the linear P fuzzy controller must include the  and  gains according to Equations (21) and (22).The Python code for configuring the controller with those gains is in Code 13.
Code 13.Python code for configuring the linear fuzzy proportional controller with the UPAFuzzy-Systems library.

=TF
After defining the controller, we simulate it following the method in Code 6.The controller response is shown in Figure 42.The absolute error is 1.26 × 10 −9 , and the absolute percentage error is 1.60×10 −7 % in steady conditions.The maximum value reached is 9.88 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the final value is 7.85 × 10 −1 rad, the rise time is 1.45 × 10 −2 s, the overshoot is 2.58 × 10 +1 % the time peak is 3.26 × 10 −2 s, and the settling time is 1.27 × 10 −1 s.Employing the same approach in Code 3, we simulate the linear system's surface which must be a line, as shown in Figure 41.When the linear inference system is defined, the linear P fuzzy controller must include the  and  gains according to Equations (21) and (22).The Python code for configuring the controller with those gains is in Code 13.Similarly, we test the linear proportional fuzzy controller, including the disturbances at the input of the plant, as shown in the block diagram in Figure 12.The results are in Figure 43. Figure 43 shows the results of the linear proportional fuzzy controller with signal disturbance for the DC motor position (blue) while summited to the input created (orange) and the disturbance signal (green).The absolute error is 3.60 × 10 −3 , and the absolute percentage error is 4.58 × 10 −1 % in steady conditions.The maximum value reached is 9.93 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the end value is 7.89 × 10 −1 rad, the time rising is 1.45 × 10 −2 s, the overshoot is 2.58 × 10 +1 %, the time peak is 3.46 × 10 −2 s, and the settling time is 1.65 × 10 −1 s.

Linear PD Fuzzy Controller
The Linear PD controller with the structure defined in Figure 6 implies working with a linear inference base with two inputs.Therefore, the class fuzzy_universe and infer-ence_system configure the premises, consequences, and rules to define a two-input linear controller.The PD fuzzy controller requires two premises: the error and its change.A consequence controller, comparable in Table 2, obtains the premise, consequence, and rules needed for a two-input linear fuzzy system.Code 14 shows the complete implementation of the linear fuzzy system with two inputs.Code 14. Code for defining the two-input fuzzy linear system with UPAFuzzySystems library.   Figure 43 shows the results of the linear proportional fuzzy controller with signal disturbance for the DC motor position (blue) while summited to the input created (orange) and the disturbance signal (green).The absolute error is 3.60 × 10 −3 , and the absolute percentage error is 4.58 × 10 −1 % in steady conditions.The maximum value reached is 9.93 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the end value is 7.89 × 10 −1 rad, the time rising is 1.45 × 10 −2 s, the overshoot is 2.58 × 10 +1 %, the time peak is 3.46 × 10 −2 s, and the settling time is 1.65 × 10 −1 s.

Linear PD Fuzzy Controller
The Linear PD controller with the structure defined in Figure 6 implies working with a linear inference base with two inputs.Therefore, the class fuzzy_universe and infer-ence_system configure the premises, consequences, and rules to define a two-input linear controller.The PD fuzzy controller requires two premises: the error and its change.A consequence controller, comparable in Table 2, obtains the premise, consequence, and rules needed for a two-input linear fuzzy system.Code 14 shows the complete implementation of the linear fuzzy system with two inputs.Figure 43 shows the results of the linear proportional fuzzy controller with signal disturbance for the DC motor position (blue) while summited to the input created (orange) and the disturbance signal (green).The absolute error is 3.60 × 10 −3 , and the absolute percentage error is 4.58 × 10 −1 % in steady conditions.The maximum value reached is 9.93 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the end value is 7.89 × 10 −1 rad, the time rising is 1.45 × 10 −2 s, the overshoot is 2.58 × 10 +1 %, the time peak is 3.46 × 10 −2 s, and the settling time is 1.65 × 10 −1 s.

Linear PD Fuzzy Controller
The Linear PD controller with the structure defined in Figure 6 implies working with a linear inference base with two inputs.Therefore, the class fuzzy_universe and inference_system configure the premises, consequences, and rules to define a two-input linear controller.The PD fuzzy controller requires two premises: the error and its change.A consequence controller, comparable in Table 2, obtains the premise, consequence, and rules needed for a two-input linear fuzzy system.Code 14 shows the complete implementation of the linear fuzzy system with two inputs.
Lines 4 and 13 in Code 14 produce the plots of the error and change in error premises, as shown in Figure 44 and Figure 45, respectively.The control consequence plot obtained with line 23 is shown in Figure 46.After defining the two-input linear inference system, we simulate its surface following the method described in Code 3. Figure 47 shows the obtained surface with the twoinput linear system.After defining the two-input linear inference system, we simulate its surface following the method described in Code 3. Figure 47 shows the obtained surface with the two-input linear system.
After obtaining the linear inference system, the definition of the linear PD fuzzy controller must include the GU, GE, and GCE gains defined in Equations ( 21)- (23).The Python code configures the PD fuzzy controller with those gains in Code 15.
Finally, we simulate the linear PD fuzzy controller following the approach in Code 6.The response of the system is in Figure 48.The absolute error is 1.83 × 10 −7 , and the absolute percentage error is 2.33 × 10 −5 % in steady conditions.The maximum value achieved is 7.85 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the end value is 7.85 × 10 −1 rad, the rise time is 3.86 × 10 −2 s, the overshoot is 0.00%, the peak time is 7.22 × 10 −1 s, and the settling time is 1.23 × 10 −1 s.   Figure 49 shows the results of the linear PD fuzzy controller with signal distu for the DC motor position (blue) while summited to the input created (orange) a   Figure 49 shows the results of the linear PD fuzzy controller with signal dis for the DC motor position (blue) while summited to the input created (orange) disturbance signal (green).The absolute error is 3.47 × 10 −3 , and the absolute pe error is 4.42 × 10 −1 % in steady conditions.The maximum value reached is 7.9 Figure 49 shows the results of the linear PD fuzzy controller with signal disturbance for the DC motor position (blue) while summited to the input created (orange) and the disturbance signal (green).The absolute error is 3.47 × 10 −3 , and the absolute percentage error is 4.42 × 10 −1 % in steady conditions.The maximum value reached is 7.91 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the end value is 7.89 × 10 −1 rad, the time rising is 3.86 × 10 −2 s, the overshoot is 2.60 × 10 −1 %, the time peak is 5.18 × 10 −1 s, and the settling time is 1.61 × 10 −1 s.

Linear PD-I Fuzzy Controller
The Linear PD-I fuzzy controller uses as a basis a two-input linear system as the linear PD controller.Therefore, we use the same system defined in Code 14.However, now, we add a third gain and the integration connection as shown in Figure 7. Thus, the simulation surface of the two-input linear system is the same as in Figure 47.
After that, we specify the configuration of the PD-I fuzzy controller with its gains GU, GE, GCE, and GIE defined in Equations ( 21)- (24).The Python code for configuring the PD-I fuzzy controller with its gains is in Code 16.
Code 16.Configuration of PD-I fuzzy controller with the UPAFuzzySystems library.Finally, we simulate the controller following the approach in Code 6.The output response is shown in Figure 50.The absolute error is 5.77 × 10 −15 , and the absolute percentage error is 7.35 × 10 −13 % in steady conditions.The maximum value achieved is 7.85 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the end value is 7.85 × 10 −1 rad, the time rising is 1.05 × 10 −2 s, the overshoot is 0.00%, the time peak is 7.22 × 10 −1 s, and the settling time is 3.46 × 10 −2 s.
percentage error is 7.35 × 10 −13 % in steady conditions.The maximum value ach 7.85 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the en is 7.85 × 10 −1 rad, the time rising is 1.05 × 10 −2 s, the overshoot is 0.00 %, the tim is 7.22 × 10 −1 s, and the settling time is 3.46 × 10 −2 s.Similarly, we test the linear PD-I fuzzy controller, including the disturbances at the input of the plant, as shown in the block diagram in Figure 12.The results are in Figure 51.
Figure 51 shows the results of the linear PD-I fuzzy controller with signal disturbance for the DC motor position (blue) while summited to the input created (orange) and the disturbance signal (green).The absolute error is 2.05 × 10 −3 , and the absolute percentage error is 2.61 × 10 −1 % in steady conditions.The maximum value reached is 7.91 × 10 −1 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the end value is 7.87 × 10 −1 rad, the time rising is 1.05 × 10 −2 s, the overshoot is 4.11 × 10 −1 %, the time peak is 5.12 × 10 −1 s, and the settling time is 3.46 × 10 −2 s.  Figure 51 shows the results of the linear PD-I fuzzy controller with signal distu for the DC motor position (blue) while summited to the input created (orange) disturbance signal (green).The absolute error is 2.05 × 10 −3 , and the absolute per error is 2.61 × 10 −1 % in steady conditions.The maximum value reached is 7.91 rad, the minimum value is 0.00 rad, the start value is 0.00 rad, the end v 7.87 × 10 −1 rad, the time rising is 1.05 × 10 −2 s, the overshoot is 4.11 × 10 −1 %, t peak is 5.12 × 10 −1 s, and the settling time is 3.46 × 10 −2 s.

Controllers Comparison
Each fuzzy controller implemented using the UPAFuzzySystems library has d control characteristics produced in the control response.These characteristics are solute error (absolute_error), the absolute percentage error (percentage_error), th mum value (max_value), the minimum value (min_value), the start value (start_ the end value (end_value), the time rising (time_rising), the overshoot (oversho time peak (time_overshoot), and the settling time (settling_time).Table 5 compa control characteristics for each controller applied to the position control of a DC m

Controllers Comparison
Each fuzzy controller implemented using the UPAFuzzySystems library has different control characteristics produced in the control response.These characteristics are the absolute error (absolute_error), the absolute percentage error (percentage_error), the maximum value (max_value), the minimum value (min_value), the start value (start_value), the end value (end_value), the time rising (time_rising), the overshoot (overshoot), the time peak (time_overshoot), and the settling time (settling_time).Table 5 compares the control characteristics for each controller applied to the position control of a DC motor.
Additionally, Figure 52 compares graphically the control responses of all fuzzy controllers implemented following an input or reference with an angular position of 45 degrees (7.85 × 10 −1 rad).As the figure shows, there are variations in the overshoot, time rising, settling time, and time peak.Still, all the controllers maintain an error below 1% of the reference in steady conditions.Additionally, Figure 52 compares graphically the control responses of all fuz trollers implemented following an input or reference with an angular position o grees (7.85E-01 rad).As the figure shows, there are variations in the overshoot, time settling time, and time peak.Still, all the controllers maintain an error below 1% reference in steady conditions.The more essential features of a controlled system are the absolute error, the a percentage error, the overshoot, the settling time, and the time rising.These featur tify the response speed of the controller, its stability, and how well it follows the re Maintaining them near zero improves the controller response.As Figure 53   The more essential features of a controlled system are the absolute error, the absolute percentage error, the overshoot, the settling time, and the time rising.These features identify the response speed of the controller, its stability, and how well it follows the reference.Maintaining them near zero improves the controller response.As Figure 53 shows, the fuzzy linear PD-I controller has the best results controlling the position of a DC motor.However, for controlling the position of the DC motor, all the controllers maintain the reference error minimally, and the settling time is also similar between them.At the same time, the more significant dispersions are in the overshoot and the time to achieve it, as the boxplot in Figure 54 shows.We also performed an ANOVA test to verify our conclusions about the best controllers and their features of interest without disturbances.We evaluated the test without overshooting features because not all the controllers have overshot.Using the features absolute error, percentage error, settling time, and time rising as groups, we obtained the results in Table 6, which support that the fuzzy linear PD-I controller has the best results among all the fuzzy controllers because of the p  = 0.000172.Moreover, we also repeat the comparison between controllers analyzing their responses with disturbances in Table 7.However, for controlling the position of the DC motor, all the controllers maintain the reference error minimally, and the settling time is also similar between them.At the same time, the more significant dispersions are in the overshoot and the time to achieve it, as the boxplot in Figure 54 shows.However, for controlling the position of the DC motor, all the controllers maintain the reference error minimally, and the settling time is also similar between them.At the same time, the more significant dispersions are in the overshoot and the time to achieve it, as the boxplot in Figure 54 shows.We also performed an ANOVA test to verify our conclusions about the best controllers and their features of interest without disturbances.We evaluated the test without overshooting features because not all the controllers have overshot.Using the features absolute error, percentage error, settling time, and time rising as groups, we obtained the results in Table 6, which support that the fuzzy linear PD-I controller has the best results among all the fuzzy controllers because of the p  = 0.000172.Moreover, we also repeat the comparison between controllers analyzing their responses with disturbances in Table 7.We also performed an ANOVA test to verify our conclusions about the best controllers and their features of interest without disturbances.We evaluated the test without overshooting features because not all the controllers have overshot.Using the features absolute error, percentage error, settling time, and time rising as groups, we obtained the results in Table 6, which support that the fuzzy linear PD-I controller has the best results among all the fuzzy controllers because of the p value = 0.000172.
Moreover, we also repeat the comparison between controllers analyzing their responses with disturbances in Table 7.
Additionally, we compare graphically the control responses of all fuzzy controllers implemented following an input or reference with an angular position of 45 degrees (7.85 × 10 −1 rad) and 10% of the input reference uniform random disturbances (Figure 55).As the figure shows, there are variations in the overshoot, time rising, settling time, and time peak.However, due to the disturbances, all the controllers now increase the error to 3.66% of the reference in steady conditions.implemented following an input or reference with an angular position of 45 (7.85 × 10 −1 rad) and 10% of the input reference uniform random disturbances 55).As the figure shows, there are variations in the overshoot, time rising, settlin and time peak.However, due to the disturbances, all the controllers now increase t to 3.66% of the reference in steady conditions.Again, we also compare the more essential features of a controlled system w fuzzy controllers and signal disturbances.As Figure 56 shows, the fuzzy linear PD troller has the best results controlling a DC motor's position and is the most robus Again, we also compare the more essential features of a controlled system with the fuzzy controllers and signal disturbances.As Figure 56 shows, the fuzzy linear PD-I controller has the best results controlling a DC motor's position and is the most robust.However, for controlling the position of the DC motor, all the controllers ma reference error below 4% of error, and the settling time is also similar between t the same time, the more significant dispersions are in the overshoot and the achieve it, as the boxplot in Figure 57 shows.However, for controlling the position of the DC motor, all the controllers maintain a reference error below 4% of error, and the settling time is also similar between them.At the same time, the more significant dispersions are in the overshoot and the time to achieve it, as the boxplot in Figure 57 shows.
We also performed an ANOVA test to verify our conclusions about the best controllers and their features of interest with disturbances.Again, we evaluated the test without overshooting features because not all the controllers have overshot.Using the features absolute error, percentage error, settling time, and time rising as groups, we obtained the results in Table 8, which support that the fuzzy linear PD-I controller has the best results among all the fuzzy controllers in the presence of disturbances because of the p value = 0.000038.However, for controlling the position of the DC motor, all the controllers maintain a reference error below 4% of error, and the settling time is also similar between them.At the same time, the more significant dispersions are in the overshoot and the time to achieve it, as the boxplot in Figure 57 shows.We also performed an ANOVA test to verify our conclusions about the best controllers and their features of interest with disturbances.Again, we evaluated the test without overshooting features because not all the controllers have overshot.Using the features absolute error, percentage error, settling time, and time rising as groups, we obtained the results in Table 8, which support that the fuzzy linear PD-I controller has the best results among all the fuzzy controllers in the presence of disturbances because of the   = 0.000038.

Conclusions
This work proposes the UPAFuzzySystems library for designing inference systems with fuzzy logic, simulation, and control with fuzzy controllers, transfer functions, and state-space models in discrete and continuous universes.To our knowledge, this proposal is the only open-source Python library that integrates these functions.

Conclusions
This work proposes the UPAFuzzySystems library for designing inference systems with fuzzy logic, simulation, and control with fuzzy controllers, transfer functions, and state-space models in discrete and continuous universes.To our knowledge, this proposal is the only open-source Python library that integrates these functions.Section 3.2 showed that the UPAFuzzySystems library could define fuzzy universes for different situations, such as collision distance and recommended speed.Section 3.3 shows how to specify the rules in an FIS system linking premises, connectives, and consequences.Moreover, the library successfully simulates the problem's surface response with input arrays defining the inputs for the premise and obtaining its corresponding consequence in a continuous universe.
Additionally, the UPAFuzzySystems library also successfully controls and simulates the position of a DC motor plant (transfer function defined in Table 4 and codified in Code 4) with the fuzzy controllers: one-input Mamdani controller in Section 3.4.1,oneinput FLS controller in Section 3.4.2,Similarly, the UPAFuzzySystems library allows the implementation of one-input and two-input linear fuzzy systems, together with the P (Section 3.5.1),PD (Section 3.5.2),and PD-I (Section 3.5.3)controllers.
The controllers implemented using the proposed library reduce the steady error below 1% without disturbances and below 4% in the presence of 10% uniform random disturbances.Furthermore, we obtained interest features in control systems, such as overshoot, steady time, time rising, and time peak, that vary depending on the controller.Those variations occur because of the different changes in the control structures, such as the premises, the consequences, the connectives, the implication, the fuzzification, and the defuzzification methods.Moreover, some of these structures even include derivatives that allow predicting changes in the error behavior or integrals that allow gradual error reduction.
After performing an ANOVA analysis with the values of the features and the error with each controller, supported with a p value = 0.000038, we concluded that the PD-I controller obtains the best error reduction and features of interest.These best features include a faster response, no overshoot, and no oscillations after reaching the reference, even in the presence of disturbances, as detailed in Section 3.6.
Our proposal successfully implements different fuzzy structures for designing FISs systems in general problems or controlling the position of a DC motor.However, following the codes we use in this work, UPAFuzzySystems can help researchers and designers solve

Figure 1 .
Figure 1.CCS diagram, including the ADC and DAC converters.

Figure 1 .
Figure 1.CCS diagram, including the ADC and DAC converters.

Figure 3 .
Figure 3. Person Age.(a) Crisp logic with clearly defined boundaries.(b) Fuzzy logic with unclear boundaries.The () forms have a significant impact on the FISs behavior.The most common membership functions include the triangle in Equation (2) as a function of the vertices , ,  ; the trapezoid in Equation (3) depending on vertices , , ,  the Gaussian in Equation (4) as a function of the parameters  and ; the generalized bell in Equation (5) subject to parameters , , , and others.Moreover, one can assign  directly based

Figure 3 .
Figure 3. Person Age.(a) Crisp logic with clearly defined boundaries.(b) Fuzzy logic with unclear boundaries.The µ(x) forms have a significant impact on the FISs behavior.The most common membership functions include the triangle in Equation (2) as a function of the vertices a, b, c; the trapezoid in Equation (3) depending on vertices a, b, c, d; the Gaussian in Equation (4) as a function of the parameters c and σ; the generalized bell in Equation (5) subject to parameters a, b, c, and others.Moreover, one can assign µ directly based on empirical

Figure 4 .
Figure 4. Structure of a Fuzzy Inference System.

Figure 4 .
Figure 4. Structure of a Fuzzy Inference System.

Figure 5 .
Figure 5. Structure of P fuzzy controller.

Figure 5 .
Figure 5. Structure of P fuzzy controller.

Linear
One input: If error is Neg then control is −100 If error is Zero then control is 0 If error is Pos then control is 100 Two inputs: If error is Neg and change error is Neg then control is −200 If error is Neg and change error is Pos then control is 0 If error is Pos and change error is Neg then control is 0 If error is Pos and change error is Pos then control is 200 Takagi-Sugeno One input: If error is Neg then control is a•error + b If error is Zero then control is 0 If error is Pos then control is c •error + d Two inputs: If error is Neg and change error is Neg then control is a•error + b•cherror + c If error is Neg and change error is Pos then control is 0 If error is Pos and change error is Neg then control is 0 If error is Pos and change error is Pos then control is d•error + e•cherror + c Linear P If error is Neg then control is −100 If error is Zero then control is 0 If error is Pos then control is 100 Linear PD If error is Neg and change error is Neg then control is −200 If error is Neg and change error is Pos then control is 0 If error is Pos and change error is Neg then control is 0 If error is Pos and change error is Pos then control is 200 Linear PID If error is Neg and change error is Neg then control is −200 If error is Neg and change error is Pos then control is 0 If error is Pos and change error is Neg then control is 0 If error is Pos and change error is Pos then control is 200

Figure 8 .
Figure 8.View obtained of a fuzzy universe of collision distance with UPAFuzzySystems libra

Figure 9 .
Figure 9. Fuzzy universe of recommended speeds with UPAFuzzySystems library.

Figure 8 .
Figure 8.View obtained of a fuzzy universe of collision distance with UPAFuzzySystems library.

Figure 8 .
Figure 8.View obtained of a fuzzy universe of collision distance with UPAFuzzySystems libra

Figure 9 .
Figure 9. Fuzzy universe of recommended speeds with UPAFuzzySystems library.

Figure 9 .
Figure 9. Fuzzy universe of recommended speeds with UPAFuzzySystems library.

Figure 10 .
Figure 10.Surface obtained from inference system with UPAFuzzySystems library.

Code 4 .
Code for defining transfer function and its parameters in a DC motor.

Figure 11 .
Figure 11.Feedback controller for controlling position in a DC motor with a fuzzy system.

Figure 12 .
Figure 12.Feedback controller for controlling position in a DC motor with a fuzzy system and random disturbances.

Figure 11 .
Figure 11.Feedback controller for controlling position in a DC motor with a fuzzy system.

Code 4 .
Code for defining transfer function and its parameters in a DC motor.

Figure 11 .
Figure 11.Feedback controller for controlling position in a DC motor with a fuzzy system.

Figure 12 .
Figure 12.Feedback controller for controlling position in a DC motor with a fuzzy system and random disturbances.

Figure 12 .
Figure 12.Feedback controller for controlling position in a DC motor with a fuzzy system and random disturbances.

Figure 13 .
Figure 13.Error premise for position control in a DC motor.

Figure 14 .
Figure 14.Control consequence for position control in a DC motor.

Figure 13 .
Figure 13.Error premise for position control in a DC motor.

Figure 13 .
Figure 13.Error premise for position control in a DC motor.

Figure 14 .
Figure 14.Control consequence for position control in a DC motor.

Figure 14 .
Figure 14.Control consequence for position control in a DC motor.

Figure 16 .
Figure 16.DC motor position controlled with a Mamdani defined with UPAFuzzySystems library.Similarly, we test the Mamdani controller with one input, but this time including the disturbances at the input of the plant as in the block diagram in Figure12.The obtained results are shown in Figure17.

Figure 16 .
Figure 16.DC motor position controlled with a Mamdani defined with UPAFuzzySystems library.

Figure 17 .
Figure 17.DC motor position controlled with a Mamdani controller, including disturbanc input of the plant.

Code 7 .
Lines for defining one input FLS controller in the UPAFuzzySystems library.

Figure 18 .
Figure 18.Surface obtained with the one-input FlS controller.

Figure 19 .
Figure 19.DC motor position controlled with an FLS controller defined with UPAFuzzy library.Similarly, we test the FLS controller with one input, including the disturbance input of the plant, as in the block diagram in Figure12.The results are shown in 20.

Figure 20 .
Figure 20.DC motor position controlled with an FLS controller, including disturbance sign Figure 20 shows the results of the FLS controller with one input and signal d ance for the DC motor position (blue) while summited to the input created (orang the disturbance signal (green).The absolute error is 7.18 × 10 −3 , and the absolute p age error is 9.14 × 10 −1 % in steady conditions.The maximum value reac

Figure 19 .
Figure 19.DC motor position controlled with an FLS controller defined with UPAFuzzySystems library.

Figure 19 .
Figure 19.DC motor position controlled with an FLS controller defined with UPAFuzzy library.Similarly, we test the FLS controller with one input, including the disturbance input of the plant, as in the block diagram in Figure12.The results are shown in 20.

Figure 20 .
Figure 20.DC motor position controlled with an FLS controller, including disturbance sign

Figure 20 .
Figure 20.DC motor position controlled with an FLS controller, including disturbance signal.

Figures 21 and 22
Figures 21 and 22  display the plots of the premise and consequences of the fuzzy sets in the one-input Takagi-Sugeno controller.The consequence plot shows the functions depending on the error premise.

Figures 21
Figures 21 and 22  display the plots of the premise and consequences of the fuzzy sets in the one-input Takagi-Sugeno controller.The consequence plot shows the functions depending on the error premise.

Figure 21 .
Figure 21.Premise fuzzy sets of the one-input Takagi-Sugeno controller.

Figure 21 .
Figure 21.Premise fuzzy sets of the one-input Takagi-Sugeno controller.

Figure 22 .
Figure 22.Consequence fuzzy sets of the one-input Takagi-Sugeno controller.

Figure 23 .
Figure 23.Surface response of the one-input Takagi-Sugeno controller.

Figure 22 .
Figure 22.Consequence fuzzy sets of the one-input Takagi-Sugeno controller.

Figure 22 .
Figure 22.Consequence fuzzy sets of the one-input Takagi-Sugeno controller.

Figure 23 .
Figure 23.Surface response of the one-input Takagi-Sugeno controller.

Figure 23 .
Figure 23.Surface response of the one-input Takagi-Sugeno controller.

Figure 23 .
Figure 23.Surface response of the one-input Takagi-Sugeno controller.

Figure 24 .
Figure 24.Controller response of the one-input Takagi-Sugeno controller.

Figure 24 .
Figure 24.Controller response of the one-input Takagi-Sugeno controller.

Figure 25 .
Figure 25.Controller response of the one-input Takagi-Sugeno controller with disturbances.

Figure 25 .
Figure 25.Controller response of the one-input Takagi-Sugeno controller with disturbances.

Figure 26 .
Figure 26.Error universe as a premise for a two-input Mamdani controller.

Figure 27 .
Figure 27.Change in error universe as a premise for a two-input Mamdani controller.

Figure 26 .
Figure 26.Error universe as a premise for a two-input Mamdani controller.

Figure 26 .
Figure 26.Error universe as a premise for a two-input Mamdani controller.

Figure 27 .
Figure 27.Change in error universe as a premise for a two-input Mamdani controller.

Figure 27 .
Figure 27.Change in error universe as a premise for a two-input Mamdani controller.

Figure 28 .
Figure 28.Control universe consequence for a two-input Mamdani controller.

1 .
If error is Neg and change error is Neg then control is Neg 2. If error is Neg and change error is Zero then control is Neg 3. If error is Zero and change error is Neg then control is Zero 4. If error is Neg and change error is Pos then control is Zero 5.If error is Zero and change error is Zero then control is Zero 6.If error is Zero and change error is Pos then control is Zero 7. If error is Pos and change error is Neg then control is Zero 8.If error is Pos and change error is Zero then control is Pos 9.If error is Pos and change error is Pos then control is Pos.

Figure 28 .
Figure 28.Control universe consequence for a two-input Mamdani controller.

Figure 30 .
Figure 30.Two-input Mamdani controller response using the UPAFuzzySystems librar Similarly, we test the Mamdani controller with two inputs, including th ances at the input of the plant, as shown in the block diagram in Figure 12.The shown in Figure 31.

Figure 30 .
Figure 30.Two-input Mamdani controller response using the UPAFuzzySystems library.Similarly, we test the Mamdani controller with two inputs, including the disturbances at the input of the plant, as shown in the block diagram in Figure 12.The results are shown in Figure 31.

Figure 32 .
Figure 32.Two-input FLS controller surface with the UPAFuzzySystems library.

Figure 33 .
Figure 33.Two-input FLS controller response by the UPAFuzzySystems library.

Figure 33 .
Figure 33.Two-input FLS controller response by the UPAFuzzySystems library.

Figure 33 .
Figure 33.Two-input FLS controller response by the UPAFuzzySystems library.

Figure 35
Figure 35 displays the output consequence, which differs from the tw Mamdani and FLS controllers, in that the output premises are functions of the e its change.Here, the premises are identical to those in Figures 26 and 27.
Figure 35 displays the output consequence, which differs from the tw Mamdani and FLS controllers, in that the output premises are functions of the e its change.Here, the premises are identical to those in Figures 26 and 27.

Figure 35 .
Figure 35.Consequence of the two-input Takagi-Sugeno controller by the UPAFuzzySy brary.

Figure 35 .
Figure 35.Consequence of the two-input Takagi-Sugeno controller by the UPAFuzzySystems library.

Figure 36 .
Figure 36.Surface of the two-input Takagi-Sugeno controller using the UPAFuzzySystems library.

Figure 36 .
Figure 36.Surface of the two-input Takagi-Sugeno controller using the UPAFuzzySystems

Figure 37 .
Figure 37.Control response of the two-input Takagi-Sugeno controller using the UPAFuzzy library.

Figure 38 .
Figure 38.Control response of the two-input Takagi-Sugeno controller with disturbances.

Figure 37 .
Figure 37.Control response of the two-input Takagi-Sugeno controller using the UPAFuzzySystems library.

Figure 36 .
Figure 36.Surface of the two-input Takagi-Sugeno controller using the UPAFuzzySystems library.

Figure 37 .
Figure 37.Control response of the two-input Takagi-Sugeno controller using the UPAFuzzySystems library.

Figure 38 .
Figure 38.Control response of the two-input Takagi-Sugeno controller with disturbances.

Figure 38 .
Figure 38.Control response of the two-input Takagi-Sugeno controller with disturbances.

Figure 39 .
Figure 39.Premise of the one-input linear controller via the UPAFuzzySystems library.

Figure 39 .
Figure 39.Premise of the one-input linear controller via the UPAFuzzySystems library.

Figure 40 .
Figure 40.Consequence of the one-input linear controller using the UPAFuzzySystems library.

Figure 41 .
Figure41.Surface of the one-input linear controller using the UPAFuzzySystems library.

Figure 40 .
Figure 40.Consequence of the one-input linear controller using the UPAFuzzySystems library.

Figure 40 .
Figure 40.Consequence of the one-input linear controller using the UPAFuzzySystems library.

Figure 41 .
Figure 41.Surface of the one-input linear controller using the UPAFuzzySystems library.

Figure 42 .
Figure 42.Response of the linear proportional fuzzy controller using the UPAFuzzySystems library.

Figure 43 .
Figure 43.Response of the linear proportional fuzzy controller with disturbances.

Figure 42 .
Figure 42.Response of the linear proportional fuzzy controller using the UPAFuzzySystems library.Similarly, we test the linear proportional fuzzy controller, including the disturbances at the input of the plant, as shown in the block diagram in Figure12.The results are in Figure43.

Figure 42 .
Figure 42.Response of the linear proportional fuzzy controller using the UPAFuzzySystems library Similarly, we test the linear proportional fuzzy controller, including the disturbances at the input of the plant, as shown in the block diagram in Figure 12.The results are in Figure 43.

Figure 43 .
Figure 43.Response of the linear proportional fuzzy controller with disturbances.

Code 14 .Figure 43 .
Figure 43.Response of the linear proportional fuzzy controller with disturbances.

Figure 44 .
Figure 44.Premise error of the two-input linear controller using the UPAFuzzySystems library.

Figure 45 .
Figure 45.Premise change in error of the two-input linear controller using the UPAFuzzySystems library.

Figure 44 .
Figure 44.Premise error of the two-input linear controller using the UPAFuzzySystems library.

Lines 4
and 13 in Code 14 produce the plots of the error and change in error premises, as shown in Figure 44 and Figure 45, respectively.The control consequence plot obtained with line 23 is shown in Figure 46.

Figure 44 .
Figure 44.Premise error of the two-input linear controller using the UPAFuzzySystems library.

Figure 45 .
Figure 45.Premise change in error of the two-input linear controller using the UPAFuzzySystems library.

Figure 45 .
Figure 45.Premise change in error of the two-input linear controller using the UPAFuzzySystems library.

Figure 46 .
Figure 46.Consequence control of the two-input linear controller using the UPAFuzzySystems library.

Figure 47 .
Figure47.Surface of the two-input linear controller using the UPAFuzzySystems library.

Figure 46 .
Figure 46.Consequence control of the two-input linear controller using the UPAFuzzySystems library.

Figure 47 .
Figure 47.Surface of the two-input linear controller using the UPAFuzzySystems library.Code 15.Python code for configuring the PD fuzzy controller in the UPAFuzzySystems library.

Figure 48 .
Figure 48.Response of the linear PD fuzzy controller using the UPAFuzzySystems library.Again, we test the linear PD fuzzy controller, including the disturbances at th of the plant, as shown in the block diagram in Figure 12.The results are shown in 49.

Figure 49 .
Figure 49.Response of the linear PD fuzzy controller with disturbances.

Figure 48 .
Figure 48.Response of the linear PD fuzzy controller using the UPAFuzzySystems library.Again, we test the linear PD fuzzy controller, including the disturbances at the input of the plant, as shown in the block diagram in Figure 12.The results are shown in Figure 49.

Figure 48 .
Figure 48.Response of the linear PD fuzzy controller using the UPAFuzzySystems library Again, we test the linear PD fuzzy controller, including the disturbances at t of the plant, as shown in the block diagram in Figure 12.The results are shown i 49.

Figure 49 .
Figure 49.Response of the linear PD fuzzy controller with disturbances.

Figure 49 .
Figure 49.Response of the linear PD fuzzy controller with disturbances.

Figure 50 .
Figure 50.Response of the linear PD-I fuzzy controller using the UPAFuzzySystems library Similarly, we test the linear PD-I fuzzy controller, including the disturbance input of the plant, as shown in the block diagram in Figure 12.The results are in 51.

Figure 50 .
Figure 50.Response of the linear PD-I fuzzy controller using the UPAFuzzySystems library.

Figure 50 .
Figure 50.Response of the linear PD-I fuzzy controller using the UPAFuzzySystems library Similarly, we test the linear PD-I fuzzy controller, including the disturbance input of the plant, as shown in the block diagram in Figure 12.The results are in 51.

Figure 51 .
Figure 51.Response of the linear PD-I fuzzy controller with disturbances.

Figure 51 .
Figure 51.Response of the linear PD-I fuzzy controller with disturbances.

Figure 52 .
Figure 52.Comparison of control responses of fuzzy controllers implemented with the UP Systems library.
sho fuzzy linear PD-I controller has the best results controlling the position of a DC m

Figure 52 .
Figure 52.Comparison of control responses of fuzzy controllers implemented with the UPAFuzzySystems library.

Figure 53 .
Figure 53.Comparison of the characteristics of interest in fuzzy controllers with the UPAFuzzySystems library.

Figure 54 .
Figure 54.Boxplot of characteristics in fuzzy controllers implemented with the UPAFuzzySystems library.

Figure 53 .
Figure 53.Comparison of the characteristics of interest in fuzzy controllers with the UPAFuzzySystems library.

Figure 53 .
Figure 53.Comparison of the characteristics of interest in fuzzy controllers with the UPAFuzzySystems library.

Figure 54 .
Figure 54.Boxplot of characteristics in fuzzy controllers implemented with the UPAFuzzySystems library.

Figure 54 .
Figure 54.Boxplot of characteristics in fuzzy controllers implemented with the UPAFuzzySystems library.

Figure 55 .
Figure 55.Comparison of control responses of fuzzy controllers with disturbances.

Figure 55 .
Figure 55.Comparison of control responses of fuzzy controllers with disturbances.

Figure 56 .
Figure 56.Comparative of characteristics of interest in fuzzy controllers with disturbances

Figure 56 .
Figure 56.Comparative of characteristics of interest in fuzzy controllers with disturbances.

Figure 56 .
Figure 56.Comparative of characteristics of interest in fuzzy controllers with disturbances.

Figure 57 .
Figure 57.Boxplot of characteristics in fuzzy controllers with disturbances.

Figure 57 .
Figure 57.Boxplot of characteristics in fuzzy controllers with disturbances.

Table 1 .
Comparison of Python libraries for FISs and their capabilities, including UPAFuzzySystems.

Table 3 .
Rules for the different FIS controllers.

error is Neg then control is Neg If error is Zero then control is Zero If error is Pos then control is Pos Two input: If error is Neg and change error is
Neg then control is N If error is Neg and change error is Zero then control is N If error is Zero and change error is Neg then control is Z If error is Neg and change error is Pos then control is Z If error is Zero and change error is Zero then control is If error is Zero and change error is Pos then control is Z If error is Pos and change error is Neg then control is Z if error is Pos and change error is Zero then control is P

Table 3 .
Rules for the different FIS controllers.
MamdaniOne input: If error is Neg then control is Neg If error is Zero then control is Zero If error is Pos then control is Pos Two input: If error is Neg and change error is Neg then control is Neg If error is Neg and change error is Zero then control is Neg If error is Zero and change error is Neg then control is Zero If error is Neg and change error is Pos then control is Zero If error is Zero and change error is Zero then control is Zero If error is Zero and change error is Pos then control is Zero If error is Pos and change error is Neg then control is Zero if error is Pos and change error is Zero then control is Pos If error is Pos and change error is Pos then control is Pos FLS One input: If error is Neg then control is Neg If error is Zero then control is Zero If error is Pos then control is Pos Two input: If error is Neg and change error is Neg then control is Neg If error is Neg and change error is Zero then control is Neg If error is Zero and change error is Neg then control is Zero If error is Neg and change error is Pos then control is Zero If error is Zero and change error is Zero then control is Zero If error is Zero and change error is Pos then control is Zero If error is Pos and change error is Neg then control is Zero if error is Pos and change error is Zero then control is Pos If error is Pos and change error is Pos then control is Pos

Table 4 .
Parameters and transfer function for controlling position in a DC motor.

Table 4 .
Parameters and transfer function for controlling position in a DC motor.

Code 7 .
Lines for defining one input FLS controller in the UPAFuzzySystems library.

Table 5 .
Comparison of control characteristics in fuzzy controllers implemented w UPAFuzzySystems library.

Table 6 .
ANOVA analysis of fuzzy controllers without overshoot.

Table 6 .
ANOVA analysis of fuzzy controllers without overshoot.

Table 6 .
ANOVA analysis of fuzzy controllers without overshoot.

Table 7 .
Comparison of control characteristics in fuzzy controllers with disturbances.

Table 8 .
ANOVA analysis of fuzzy controllers without overshoot.

Table 8 .
ANOVA analysis of fuzzy controllers without overshoot.