T-S Fuzzy Algorithm Optimized by Genetic Algorithm for Dry Fermentation pH Control

: In the process of anaerobic dry fermentation to produce biogas, maintaining a suitable pH in the environment is more conducive to the degradation of crop straw. When the pH in the fermentation environment is too low, the process of anaerobic digestion by anaerobic bacteria is inhibited. Therefore, it is necessary to quickly adjust the pH. In this work, we studied the control technology of a pH regulation system and then constructed a T-S fuzzy controller. Upon simplifying the T-S fuzzy controller, the system delay time was reduced, and two genetic algorithms with different ﬁtness performance indicators were used to optimize the T-S fuzzy control. The simulation experiment in this study was designed through simulation software, and the results show that the improved control method has a fast regulation ability. Finally, on-site experiments were conducted using the four control methods under the acidiﬁcation conditions set in the experimental device. The results show that the control method used in this study to improve performance by integrating the error sum of squares has a short control time and small oscillation and overshoot, and it can better regulate the environmental pH to achieve appropriate conditions when acidiﬁcation occurs during anaerobic dry fermentation.


Introduction
The easy acidification of materials in the process of anaerobic dry fermentation to produce biogas has always been a challenge in the development of this technology [1,2]. Dry fermentation for biogas production is highly favored by researchers due to its unique features, such as low water demand during fermentation, low requirements for the length of crushed straw used as raw material, and diversity of raw materials [3]. In the process of dry fermentation to produce biogas, anaerobic bacteria decompose organic matter into biogas and nitrogen-rich organic residue under anaerobic conditions. When the pH of the fermentation material is lower than 5.5, methane production during the fermentation process will be inhibited, leading to a decrease in biogas production. Therefore, in order to increase the biogas production of dry straw fermentation material, it is necessary to control the pH of the material and establish a rapidly adjustable environmental pH control system [4,5], which is of great significance for improving fermentation efficiency and success rates.
During the dry fermentation process to produce biogas, the pH of the fermentation environment may be at an inappropriate level due to factors such as device leakage or the strong acid production capacity of the fermentation materials. However, adjusting the pH during the fermentation process is often slow, and it is a nonlinear process. Therefore, efficiently and quickly adjusting the pH of the fermentation environment to meet the appropriate requirements is an important research direction. Research on pH control in fermentation environments mainly includes modeling the process of pH control and optimizing the algorithms. At present, research on modeling the process of controlling environmental pH mainly focuses on two types: linear segmented control and nonlinear intelligent control [6]. In the research on optimizing nonlinear intelligent control algorithms, feedback control and adaptive control methods are mostly used. The T-S fuzzy controller used in this investigation has difficulty handling time-varying and delayed environmental pH control, and more efficient and fast optimization algorithms need to be studied [7].
In recent years, Faanes et al. [8] established a control model for the price of liquor based on the parameters of the reaction vessel, the concentration (C) and velocity (Q) of the input and output liquids, and the concentration of the control solution. The required volume of the control solution can be calculated based on the concentration of acidic or alkaline substances added to the reaction solution. Many times, the acid-base neutralization process is too complex, and it is difficult to describe the entire process using a single model. Therefore, using multiple models for control becomes a reasonable choice. The advantage of using multiple models is that it can transform a complex process into multiple simple links, such as simple models to segment and describe the complex acid-base neutralization process. Barraud et al. [9] modeled the acid-base neutralization process by studying the reaction characteristics of acid-base reagents in the production of precipitates using batch processing technology, and they determined the model parameters through experiments to achieve accurate control of the pH of the reaction liquor. Böling et al. [10] modeled multiple adaptive algorithms for pH control. Using prior knowledge, the acid-base neutralization process was divided into multiple small intervals, and three models were established for each interval. The model parameters were adjusted through experiments, and performance indicators (the difference between actual output and model prediction) were proposed to determine whether the model could accurately describe the acid-base neutralization process. The three operation arguments of the PID controller were calculated according to the identification model to achieve control of the liquor pH in the acid-base neutralization process.
The T-S fuzzy model uses linear systems theory to solve nonlinear problems, and it can use multiple linear equations to fit the nonlinear process of solution pH changes during acid-base neutralization [11][12][13]; these linear equations are the ultimate expression of the T-S fuzzy model. When the parameters and structure of the pH control model change during the acid-base neutralization process, it is difficult to achieve good control results using offline model control methods. For nonlinear, time-varying, and random external disturbances in the pH control of solution in the acid-base neutralization process, conventional fuzzy control algorithms have poor control effects due to fixed fuzzy rules. Salehi et al. [14] advanced a flexible fuzzy control algorithm that can automatically update fuzzy rules and control parameters according to the pH output error. During the operating process, only the pH of the liquor needs to be measured. However, the design process of this algorithm is complex, and multiple control parameters need to be set according to the control object. Mészáros et al. [15] combined neural network algorithms with fuzzy control algorithms, utilizing the powerful self-learning and association abilities of neural networks. When the pH of the control object changes, the membership functions and fuzzy rules can be modified automatically, mitigating the effects of system uncertainty and pattern mismatch on the accuracy of pH control. The algorithm has strong adaptability.
At present, there are mainstream fuzzy inference algorithms of the Mamdani type. A Mamdani fuzzy system consists of three parts: a fuzzy processing operator, fuzzy reasoning mechanism, and un-fuzzification processing operator. Mamdani-type fuzzy inference can realize the inference calculation from input to output through a set of rules of inference mastered in advance so as to establish an accurate identification system. [16] The main difference between Mamdani-type and T-S fuzzy systems lies in the end part. Compared to the post-event fuzzy subset of the Mamdani system, the post-event of the T-S fuzzy system is f(x), which can be a single value, a linear combination of inputs (corresponding to a first-order T-S fuzzy system), or a nonlinear combination. Therefore, the dynamic performance of the Mamdani system is relatively smooth, but the response speed is slow. The T-S fuzzy system has a relatively short response time but poor dynamic stability and large overshoot. Controlling the pH of anaerobic dry fermentation in this article requires rapid changes in pH when it inhibits the fermentation process. In general, acidification occurs, and the maximum pH of anaerobic fermentation can reach 8. Therefore, a fuzzy system with short response time and little overshoot is needed. The T-S fuzzy system is more suitable for use in controlling the pH of anaerobic dry fermentation than the Mamdani system.
To sum up, in the process of anaerobic dry fermentation to produce biogas in this paper, the primary tasks to improve rapidity and efficiency by adjusting the pH in the fermentation environment are as follows: (a) simplify the T-S fuzzy reasoning rules; (b) improve the genetic algorithms to optimize and simplify the T-S fuzzy operation under the two performance indicators of the fitness function; and (c) perform the T-S fuzzy operation. The simplified T-S fuzzy operation and the majorization of the optimized genetic algorithm for simplified T-S fuzzy control proposed in this article were emulated and validated on the MATLAB/Simulink platform. The conclusion drawn is that the proposed simplified T-S fuzzy operation using the error sum of squares integral as the evaluation index of the genetic algorithm is superior to other control algorithms. In this paper, we designed experimental verification for data monitoring, control terminals, data acquisition, and algorithm control. The experimental results show that the designed operating algorithm has a faster control rate and more accurate results compared to other control algorithms.
The study was performed as follows. First, we analyzed the process of pH regulation in anaerobic dry fermentation for biogas production and established a mathematical model for pH regulation through the acid-base ionization equilibrium equation. Second, we constructed a T-S fuzzy controller and optimized the simplified T-S fuzzy controller using an improved genetic algorithm. In this part, the simplified T-S fuzzy controller first used the integrated mean square error with integral absolute error and the integral of the error sum of squares as the evaluation index to improve the genetic algorithm, and finally, it used the improved genetic algorithm for majorization. Third, we compared the actual effects of four control methods through simulation software and on-site experiments, and we finally obtained the validation results of the pH control system for anaerobic dry fermentation for biogas production.

System Components
The pH control device for anaerobic dry fermentation for biogas production is shown in Figure 1. During the fermentation process, the computer is used as the main control unit to control how long the alkaline tank outlet solenoid valve is open and closed. Alkaline solution is injected through a pump, and the input amount of alkaline solution is monitored through a flow meter to modify the pH range of the fermentation material in the device. The stirring device is used to mix and stir the materials and the alkaline solution. The fermentation device monitors the liquid pH range in the fermentation environment using a pH sensor. If we consider whether the instant pH range fits the requirements for dry fermentation biogas production through the main control equipment, when there is a discrepancy, the alkali pump can be turned on to supplement the fermentation device with alkali. In the fermentation process, acid-base regulation is mainly implemented by the master control module of the upper computer, which collects the flow meter data and controls the alkali pump and solenoid valve for regulation.

Modifying the pH of Biogas Production during Dry Fermentation
In order to provide a suitable environment for dry fermentation to produce biogas, alkali liquor is added to the fermentation device when acidification occurs. Adding alkaline solution requires starting and stopping the pump so that the solution can be pumped into the fermentation device. In the actual process of adding alkaline solution, the mixing process is controlled by the control system, and the delay in response time caused by the opening of the pump and the use of the system can lead to a lag in pH adjustment.
When acidification occurs in the production of biogas through dry fermentation, it is necessary to adjust the pH of the fermentation material. When alkali liquor and biogas slurry are mixed together, it can be considered as an acid-base neutralization process, making the pH of the material consistent with the pH required for the environment and similar to the control system settings. The process of adjusting and controlling pH is nonlinear. Adjusting the pH during the actual fermentation material mixing process is influenced by many changing factors. Therefore, in this study, we designed an operable control model and analyzed it from the perspective of fermentation principles. Assuming that alkali liquor is injected into the fermentation device and mixed with the biogas slurry as the input of the pH model, the acid is quickly neutralized, and the mixed liquor concentration is output. The mixed liquor in the spray pipe is constantly filled, and the concentration at the top and bottom of the fermentation device is the same, as shown in Figure  2.

Modifying the pH of Biogas Production during Dry Fermentation
In order to provide a suitable environment for dry fermentation to produce biogas, alkali liquor is added to the fermentation device when acidification occurs. Adding alkaline solution requires starting and stopping the pump so that the solution can be pumped into the fermentation device. In the actual process of adding alkaline solution, the mixing process is controlled by the control system, and the delay in response time caused by the opening of the pump and the use of the system can lead to a lag in pH adjustment.
When acidification occurs in the production of biogas through dry fermentation, it is necessary to adjust the pH of the fermentation material. When alkali liquor and biogas slurry are mixed together, it can be considered as an acid-base neutralization process, making the pH of the material consistent with the pH required for the environment and similar to the control system settings. The process of adjusting and controlling pH is nonlinear. Adjusting the pH during the actual fermentation material mixing process is influenced by many changing factors. Therefore, in this study, we designed an operable control model and analyzed it from the perspective of fermentation principles. Assuming that alkali liquor is injected into the fermentation device and mixed with the biogas slurry as the input of the pH model, the acid is quickly neutralized, and the mixed liquor concentration is output. The mixed liquor in the spray pipe is constantly filled, and the concentration at the top and bottom of the fermentation device is the same, as shown in Figure 2.

Modifying the pH of Biogas Production during Dry Fermentation
In order to provide a suitable environment for dry fermentation to produce biogas, alkali liquor is added to the fermentation device when acidification occurs. Adding alkaline solution requires starting and stopping the pump so that the solution can be pumped into the fermentation device. In the actual process of adding alkaline solution, the mixing process is controlled by the control system, and the delay in response time caused by the opening of the pump and the use of the system can lead to a lag in pH adjustment.
When acidification occurs in the production of biogas through dry fermentation, it is necessary to adjust the pH of the fermentation material. When alkali liquor and biogas slurry are mixed together, it can be considered as an acid-base neutralization process, making the pH of the material consistent with the pH required for the environment and similar to the control system settings. The process of adjusting and controlling pH is nonlinear. Adjusting the pH during the actual fermentation material mixing process is influenced by many changing factors. Therefore, in this study, we designed an operable control model and analyzed it from the perspective of fermentation principles. Assuming that alkali liquor is injected into the fermentation device and mixed with the biogas slurry as the input of the pH model, the acid is quickly neutralized, and the mixed liquor concentration is output. The mixed liquor in the spray pipe is constantly filled, and the concentration at the top and bottom of the fermentation device is the same, as shown in Figure  2.  According to the laws of material and atomic conservation in the acid-base neutralization process, the state of equilibrium of the acid slurry in the control system will be related to the conservation of liquid and volume; thus, we can construct equations for controlling the conductivity and pH of the biogas slurry fermentation process: In the formula, V is the volume of the mixed liquid; H b is the density of alkali in the mixture; H x is the density of biogas slurry in the device; L x is the volume of biogas slurry; L b is the input amount of alkaline solution, and L b = t × L n , where t is the time for starting the pump and L n is the flow rate of alkali solution per minute each time the pump starts; L in is the input flow rate within the system device; K b is the weak base ionization equilibrium constant, and PK b = − log(K b ); and pH is a variable in output process [6,7,17,18].

System Model Construction
Based on the effect of the pH control system on the dry fermentation biogas production described above, this study adopts a classic first-order object as the research model: The object parameters have step-and time-varying characteristics, and their variation patterns are as follows: Take a = b = 30, c = 90, d = 3, e = 110, and f = 5. The step signal is in units of the input signal. Sampling time t s = 20 s. The preset step response with pH = 5.5 is taken as the input signal with open cycle machinery. The sample lapse is disabled at 20 s. The pH of the biogas slurry in the device is 5.5, and the step response curve of the system is fitted as a first-order similar count to calculate the system based on the pH data change. The system benefit K is determined to be 0.67, and t with delay time is 3. T of the time constant is 28. The monitoring process has a time delay.

PID Control Strategy
pH control during anaerobic dry fermentation is mainly achieved by adding alkaline solution to the device to achieve an acid-base balance. The process of adding liquid can be achieved using classic PID control. The system diagram is shown in Figure 3. PID control mainly tracks and differentiates the difference between the required value and the actual measured value. The results of the system's copper drum ratio, integration, and differentiation can be used as a means of controlling the liquid pH value. However, adding alkaline solution produces hysteresis and nonlinearity in the mixing process. Therefore, PID control generally performs in the pH value adjustment control process and cannot quickly and easily increase the pH in the fermentation device [19]. Processes 2023, 11, x FOR PEER REVIEW 6 of 18

T-S Fuzzy Control
In line with the pH control system model obtained above, the pH value during the acid-base neutralization process can be controlled.
Controlling the pH of dry fermentation biogas production is a multi-input singleoutput system (MISO) with n inputs of u1, u2, … un, where the output is O; after that, the T-S fuzzy rules model are as follows: R: If u1 is A1 and u2 is A2 and … and uk is Ak, then y = s1u1 + s2u2 + … + skuk + r (4) Among them, Aj (j = 1, 2, …, k) is a set composed of fuzzy subsets, and the parameters sj (j = 1, 2, …, k) and r are constants, which are identified based on the input and output data of the control system. Here, the function y = s1u1 + s2u2 + … + skuk + r is equivalent to various fuzzy control rules in traditional fuzzy inference.
The output of existing fuzzy systems is determined by multiple T-S fuzzy rules, and a specific set of input data m can simultaneously trigger x rules. The model can be represented as follows: Ri: If u1 is Ai1 and u2 is Ai2 and … and uk is Aik, then y = si1u1 + si2u2 + … + sikuk + ri (i = 1, 2, …, n) Among them, Aij (i = 1, 2, …, n) represents the corresponding fuzzy part in the ith control rule, where sij and ri (i = 1, 2, …, k) constants are identified according to INOUT data corresponding to the ith control rule.

T-S Fuzzy System Identification
The T-S fuzzy system is divided into a prerequisite section and a conclusion section, each of which can be divided into parameter identification and conclusion identification. These four parts will be introduced here.
(1) Identification of prerequisite parameters This refers to the prerequisite parameter for obtaining the minimum value of the performance function to install INOUT data. The fuzzy set can be divided according to needs. It is commonly divided into seven parts: negative large (NB), negative medium (NM), negative small (NS), 0, positive small (PS), positive medium (PM), and positive large (PB). This T-S fuzzy control mainly fuzzies the control process when the input and output are not clear. Controlling the pH in anaerobic dry fermentation for biogas production mainly involves quickly adjusting the pH to 7 in case of acidification in the fermentation device so that the anaerobic bacteria are at a comfortable pH level. The input of this process is specified in this study. When the pH value is less than or equal to 6, the pH control system

T-S Fuzzy Control
In line with the pH control system model obtained above, the pH value during the acid-base neutralization process can be controlled.
Controlling the pH of dry fermentation biogas production is a multi-input singleoutput system (MISO) with n inputs of u1, u2, . . . un, where the output is O; after that, the T-S fuzzy rules model are as follows: R: If u 1 is A 1 and u 2 is A 2 and . . . and u k is A k , then y = s 1 u 1 + s 2 u 2 + . . . + s k u k + r Among them, A j (j = 1, 2, . . ., k) is a set composed of fuzzy subsets, and the parameters s j (j = 1, 2, . . ., k) and r are constants, which are identified based on the input and output data of the control system. Here, the function y = s 1 u 1 + s 2 u 2 + . . . + s k u k + r is equivalent to various fuzzy control rules in traditional fuzzy inference.
The output of existing fuzzy systems is determined by multiple T-S fuzzy rules, and a specific set of input data m can simultaneously trigger x rules. The model can be represented as follows: Ri: If u 1 is A i1 and u 2 is A i2 and . . . and u k is A ik , then y = s i1 u 1 + s i2 u 2 + . . . + s ik u k + r i (i = 1, 2, . . ., n) Among them, A ij (i = 1, 2, . . ., n) represents the corresponding fuzzy part in the ith control rule, where s ij and r i (i = 1, 2, . . ., k) constants are identified according to INOUT data corresponding to the ith control rule.

T-S Fuzzy System Identification
The T-S fuzzy system is divided into a prerequisite section and a conclusion section, each of which can be divided into parameter identification and conclusion identification. These four parts will be introduced here.
(1) Identification of prerequisite parameters This refers to the prerequisite parameter for obtaining the minimum value of the performance function to install INOUT data. The fuzzy set can be divided according to needs. It is commonly divided into seven parts: negative large (NB), negative medium (NM), negative small (NS), 0, positive small (PS), positive medium (PM), and positive large (PB). This T-S fuzzy control mainly fuzzies the control process when the input and output are not clear. Controlling the pH in anaerobic dry fermentation for biogas production mainly involves quickly adjusting the pH to 7 in case of acidification in the fermentation device so that the anaerobic bacteria are at a comfortable pH level. The input of this process is specified in this study. When the pH value is less than or equal to 6, the pH control system is activated to regulate the pH in the fermentation device. The correct input-output data in the system are known, and only one input variable is used in this study when controlling the input. Therefore, 7 commonly used fuzzy rules can be combined into 3. The 3 fuzzy rules divide the domain of a function into 3 subsets: [small], [medium], and [large]. Their membership functions are composed of segmented straight lines, as shown in Figure 4, where p 1 , p 2 , . . ., and p 8 are prerequisite parameters. The result of the original 7 membership function methods was to represent NB as p 1 , NM as p 2 , NS as p 3 and p 4 , 0 as p 5 , PS as p 6 , PM as p 7 , and PB as p 8 . According to the above methods, use p 1 , p 2 instead of NB, p 3 , p 4 instead of N, p 4 , p 5 instead of ZO, p 5 , p 6 instead of PS, and p 7 , p 8 instead of PB. These alternate methods are used to achieve a response of 5 or 7 subsets in 3 subsets. These alternate methods are used to achieve a response of 5 or 7 subsets in 3 subsets. (2) Identification of prerequisite structure This refers to determining the specific number of input variables in the problem, optimizing the fuzzy space of input variables, and enabling the identified fuzzy model to accurately describe the target system.

(3) Identification of conclusion parameter
This refers to determining the coefficients in each rule conclusion output equation, usually using least squares or other methods to identify parameters using input and output data.
(4) Identification of conclusion structure This refers to determining the number of variables to include in the output equation for each rule conclusion.
The above is the calculation processes for T-S fuzzy system identification. Through these 4 steps, the T-S fuzzy model can be determined based on the INOUT data. However, when the quantization level of the controller input is refined, it is necessary to determine the amount of fuzzy rule increase, and the subsequent parameters of the fuzzy rules to be determined rapidly increase, thereby increasing the difficulty of controller design. The T-S fuzzy control process for adjusting the biogas pH in dry fermentation is shown in Figure  5.  (2) Identification of prerequisite structure This refers to determining the specific number of input variables in the problem, optimizing the fuzzy space of input variables, and enabling the identified fuzzy model to accurately describe the target system.

(3) Identification of conclusion parameter
This refers to determining the coefficients in each rule conclusion output equation, usually using least squares or other methods to identify parameters using input and output data.
(4) Identification of conclusion structure This refers to determining the number of variables to include in the output equation for each rule conclusion.
The above is the calculation processes for T-S fuzzy system identification. Through these 4 steps, the T-S fuzzy model can be determined based on the INOUT data. However, when the quantization level of the controller input is refined, it is necessary to determine the amount of fuzzy rule increase, and the subsequent parameters of the fuzzy rules to be determined rapidly increase, thereby increasing the difficulty of controller design. The T-S fuzzy control process for adjusting the biogas pH in dry fermentation is shown in Figure 5. is activated to regulate the pH in the fermentation device. The correct input-output data in the system are known, and only one input variable is used in this study when controlling the input. Therefore, 7 commonly used fuzzy rules can be combined into 3. These alternate methods are used to achieve a response of 5 or 7 subsets in 3 subsets. (2) Identification of prerequisite structure This refers to determining the specific number of input variables in the problem, optimizing the fuzzy space of input variables, and enabling the identified fuzzy model to accurately describe the target system.

(3) Identification of conclusion parameter
This refers to determining the coefficients in each rule conclusion output equation, usually using least squares or other methods to identify parameters using input and output data.
(4) Identification of conclusion structure This refers to determining the number of variables to include in the output equation for each rule conclusion.
The above is the calculation processes for T-S fuzzy system identification. Through these 4 steps, the T-S fuzzy model can be determined based on the INOUT data. However, when the quantization level of the controller input is refined, it is necessary to determine the amount of fuzzy rule increase, and the subsequent parameters of the fuzzy rules to be determined rapidly increase, thereby increasing the difficulty of controller design. The T-S fuzzy control process for adjusting the biogas pH in dry fermentation is shown in Figure  5. Figure 5. T-S fuzzy pH control system. Figure 5. T-S fuzzy pH control system.

Simplifying T-S Fuzzy Reasoning
The T-S fuzzy controller for dry fermentation biogas production has K rules, with (n + 1) k subsequent parameters. The more adjustable the subsequent parameters, the more difficult the on-site control. Therefore, this article simplifies the T-S model. Compared with the T-S fuzzy operation, we simplified it with the advantages of simple operation and fast answer speed. Operators accumulate data on the pH control of dry fermentation biogas production and set reasonable simplified T-S fuzzy control laws according to existing data. The input parameters of the system are targeted, making it convenient for operating processes to fulfill structured control demands, yet, due to the lack of optimization ability, T-S fuzzy rules rely on simple control strategies. This leads to a low control accuracy and large steady-state error of the system, making it difficult to achieve fast and accurate adjustment [20].
This article mainly adopts the following methods for simplification: R 1 : I f u 1 is A 1 1 , and u 2 is A 1 2 , . . . , and u n is A 1 n then s 1 = p 1 + p 2 u 2 + · · · + p n u n R 2 : I f u 1 is A 2 1 , and u 2 is A 2 2 , . . . , and u n is A 2 n then s 2 = k 1 s 1 . . .
Therefore, the unascertained arguments of simplified T-S fuzzy controller are p 1 , p 2 , . . ., p n , k 1 , k 2 , . . ., k m . The count of unascertained arguments is the sum of the number of controller input parameters and the total number of controller rules.
In this study, we first set values for p 1 , p 2 , . . ., p n based on experience and then waited until the number of optimization parameters was further reduced to the total number of control rules. The main characteristic of simplified T-S type fuzzy inference to obtain fuzzy control rules is that the parameter values of the subsequent components are proportional to each other, but each rule still changes with the input variable, so that all subsequent components of the fuzzy control rules will change according to actual needs.
A diagram of the simplified T-S fuzzy controller structure can be seen in Figure 6.

Simplifying T-S Fuzzy Reasoning
The T-S fuzzy controller for dry fermentation biogas production has K rules, with (n + 1) k subsequent parameters. The more adjustable the subsequent parameters, the more difficult the on-site control. Therefore, this article simplifies the T-S model.
Compared with the T-S fuzzy operation, we simplified it with the advantages of simple operation and fast answer speed. Operators accumulate data on the pH control of dry fermentation biogas production and set reasonable simplified T-S fuzzy control laws according to existing data. The input parameters of the system are targeted, making it convenient for operating processes to fulfill structured control demands, yet, due to the lack of optimization ability, T-S fuzzy rules rely on simple control strategies. This leads to a low control accuracy and large steady-state error of the system, making it difficult to achieve fast and accurate adjustment [20].
This article mainly adopts the following methods for simplification: Therefore, the unascertained arguments of simplified T-S fuzzy controller are p1, p2, …, pn, k1, k2, …, km. The count of unascertained arguments is the sum of the number of controller input parameters and the total number of controller rules.
In this study, we first set values for p1, p2, …, pn based on experience and then waited until the number of optimization parameters was further reduced to the total number of control rules. The main characteristic of simplified T-S type fuzzy inference to obtain fuzzy control rules is that the parameter values of the subsequent components are proportional to each other, but each rule still changes with the input variable, so that all subsequent components of the fuzzy control rules will change according to actual needs.
A diagram of the simplified T-S fuzzy controller structure can be seen in Figure 6.

Simplified T-S Fuzzy Control Optimized by Genetic Algorithm
Genetic algorithms, as more classic algorithms, have been widely used [21,22]. However, in the process of planning the T-S fuzzy controller in this study, the optimization effect using a classical genetic algorithm was poor, and better improvements can be made.
To address the problems in controlling the pH of biogas production in dry fermentation, in this study, we employed comparisons to select a better coding method and objective

Simplified T-S Fuzzy Control Optimized by Genetic Algorithm
Genetic algorithms, as more classic algorithms, have been widely used [21,22]. However, in the process of planning the T-S fuzzy controller in this study, the optimization effect using a classical genetic algorithm was poor, and better improvements can be made. To address the problems in controlling the pH of biogas production in dry fermentation, in this study, we employed comparisons to select a better coding method and objective function. In order to improve the reaction time and optimization efficiency, some improvements were made to the classical genetic algorithm. The flowchart (Figure 7) is as follows: function. In order to improve the reaction time and optimization efficiency, some improvements were made to the classical genetic algorithm. The flowchart (Figure 7) is as follows:

Determining Coding Strategy
Genetic algorithms generally use binary encoding, but when solving specific problems, long code strings are prone to occur, and decoding and encoding operations can take a lot of time and present other problems [23]. In order to make the problem description more straightforward, easily introduce heuristic information from relevant fields, and enhance the search ability of genetic algorithms, this article adopts real number encoding. With this method, there is no need for binary encoding and decoding operations, and the genetic operation process is directly carried out in the problem space, which can overcome the shortcomings of solving continuous optimization problems and improve the accuracy and speed of the optimization algorithm. The controller-aided design in this article mainly adopts the inheritance algorithm, and the variables involved are continuous variables, so the real number encoding method is adopted.

Determination of Fitness Function
As long as an improved genetic algorithm is used to intelligently optimize the design of the controller, the optimization of the objective function must be closely related to the system regulation index function, reflecting the regulation effect of the system.
In this paper, two optimization target modes are adopted. The first is the integrated mean squared error and absolute error (IAE): The second is the integrated squared error (ISE): In this paper, the optimization objective of the controller is J * = minJ(I AE) or J * = minJ(ISE), and the fitness function is the directly selected objective function.

Selection Strategy
There are individuals in the genetic population that we choose to eliminate based on their ability to adapt to the problem environment. Those with strong adaptability are left as breeding offspring. In this study, we used the combination of an optimal retention strategy and the roulette wheel selection method. First, we find the individual Y 1 with the best fitness in the current population {Y i }, save it in a variable W that does not participate in mutation and crossover operations, and then select the remaining individuals in a way that is proportional to the adaptive capacity of the individual, crossover and mutation operations, to produce the next-generation population {Y i + 1}. When the best individual Y 2 in {Y i − 1} is better than Y 1 , we use Y 2 instead of W; otherwise, it will remain unchanged. By doing so, the average fitness value of the population can be continuously improved while ensuring that the fitness value of the best individual does not decrease. This greatly improves the convergence speed and makes it easier to obtain the optimal solution.

Crossover Operation
In a genetic algorithm, the crossover operation is used to select the parent chromosomes that participate based on a certain probability of crossover. Here, we use directional crossover to effectively expand the search space.
The intersection based on direction is as follows: In the equation, r 1 , r 2 is the chromosome vector and θ is a random number between [0, 1].

Selection of Adaptive Cross-Mutation Strategies
The performance of control algorithms is directly determined by the quality of the mutation operator design [24]. The method of designing an adaptive mutation operator in this paper was to avoid using mutation operations during the standard evolution process, allowing it to evolve quickly. Once it enters the precocious state, measures are taken to quickly leave that state and allow the evolution process to continue. The formula is as follows: W n (m) = NT × cov + 0.001 (10) where m represents the current algebra, NT represents the continuous and unevolutionary algebra from the last evolution to the end of the current generation, and cov is the coefficient of increased variability; this number is usually taken as the minimum value.

Simulation Experiment on pH Control of Biogas Production by Dry Fermentation
In order to check the function of the T-S fuzzy control plan optimized by the genetic algorithm, we designed a simulation of the T-S fuzzy controller using MATLAB. The T-S fuzzy control machinery model optimized by the genetic algorithm with simplified T-S fuzzy control and two fitness indicators is shown in Figure 8. The pH of the alkaline solution is 9, the flow rate of the water entering the fermentation device is 1.2 L/s, and the machinery delay is 2 s. We used the pH values of 5.4 and 6.0 collected by the two sensors as input signals in the fermentation test device and set a stable-state pH of 7. Using the pH sensors to monitor changes in pH levels, two control processes to increase the pH from 5.4 to 7 and from 6.0 to 7 were compared. By analyzing the relative error, response time, and overshoot, we can conclude that the T-S fuzzy control optimized by the genetic algorithm has a good control effect.
Processes 2023, 11, x FOR PEER REVIEW 12 of 18 Figure 8. Simulation of pH control system for anaerobic dry fermentation. Figure 8. Simulation of pH control system for anaerobic dry fermentation.
The pH inside the fermentation device was tracked with a 200 s simulation time. A step signal with an amplitude of 1 at t = 0 was entered. The simulation waveforms of different control algorithms are shown in Figure 9. In the graph, we find the T-S fuzzy control had a long response time of 98 s and a medium overshoot of 0.14. The simplified T-S fuzzy controller had a faster response time of 73 s and a larger overshoot of 0.19. The T-S fuzzy controller optimized by the genetic algorithm using a mean integrated squared error with integral absolute error had a response time of 36 s and overshoot of 0.08. The T-S fuzzy controller optimized by the genetic algorithm using the error sum of squares as the fitness measure had a short response time of 27 s and small overshoot of 0.03, and it is able to modify the pH in a short time. Compared with the other three control algorithms, it performs well at regulating the pH in dry fermentation biogas production. From the graph, it can be seen that the T-S fuzzy control has the slowest response time and medium overshoot, while the simplified T-S fuzzy control has a faster response time but a large overshoot over time. The T-S fuzzy control optimized by the IAE genetic algorithm had a moderate overshoot, but compared to the ISE optimized algorithm, it had a larger overshoot and a longer response time.  The function arguments of the four algorithms are shown in Table 1. The table shows the overshoot and response time. The response time of the simplified T-S fuzzy control was 25 s less and the overshoot was 0.05 more than the T-S fuzzy control technique. The response time of T-S fuzzy control optimized by the genetic algorithm using the integrated mean squared error and integral absolute error was 66 s, 62 s and 37 s less and the overshoot was 0.29, 0.06 and 0.11 less than PID, T-S fuzzy and simplified T-S fuzzy control, respectively. The response time of T-S fuzzy control optimized by the genetic algorithm using the sum of squared error as the fitness measure was 75 s, 71 s, 46 s and 9 s less and the overshoot was 0.34, 0.11, 0.16 and 0.05 less than T-S fuzzy, simplified T-S fuzzy and T-S fuzzy control optimized by the genetic algorithm using the integrated mean square error and integral absolute error, respectively.

Test Materials and Equipment
The pH control experiment for dry fermentation biogas production was conducted in March 2023 at the East Laboratory of Nanjing Agricultural Mechanization Research Institute of the Ministry of Agriculture and Rural Affairs. The test platform included a 2W-25 solenoid valve, Siemens s200 PLC, SEN-HZ21WI flow meter, JUMO pH sensor, and niMU11 pump. The maximum flow rate of the water pump was 1.5 L/min. The small and medium-sized water pumps on the experimental platform were powered by 220 V AC points, and the controller and sensor power were converted from 220 to 24 V DC before being supplied to the control system. The height of the test platform was 1.5 m and the width was 1 m.
The experimental control objects were electromagnetic valves and small water pumps, and the experimental material was biogas slurry without solid floating particles. T-S fuzzy control, simplified T-S fuzzy control, IAE-optimized T-S fuzzy control and ISEoptimized T-S fuzzy control were used to measure and verify the pH of the anaerobic dry fermentation process.
To test the stability of the algorithms, anaerobic dry fermentation pH control experiments were conducted. A schematic diagram of the experimental equipment is shown in Figure 10. The testing system mainly consisted of an upper computer, a signal acquisition unit, a signal processing unit, a pH sensor, and an alkali injection module. The signal was transmitted through the RS232 protocol. The control module was the alkali injection module. The experiment took input values equal to the set pH values, with configuration software as the core, and received coupled data from the pH sensor and flow meter. During mixing and stirring of solid and liquid, the main control module of the system adjusted the pH in the fermentation environment by controlling the injection amount of alkali solution. The amount of alkali solution added was controlled based on the calculated demand, and the mixing was completed by the stirring device. When the pH met the required value, the system maintained a stable state.

Precision Analysis of pH Control System for Anaerobic Dry Fermentation
In this study, the control efficiency of the anaerobic dry fermentation pH control system was reflected by the flow error and electromagnetic valve response time. The main positions affecting the efficiency of pH control are at the front and rear ends of the solenoid valve. There are certain errors in the intermittent liquid supply by small water pumps, and there are also errors in the monitoring of flow meters. Flow meter error is a key error. The main cause of flow error is the uncertainty of the viscosity of the biogas slurry. In addition, the electromagnetic flow meter can affect monitoring accuracy based on changes in the electromagnetic field.

Precision Analysis of pH Control System for Anaerobic Dry Fermentation
In this study, the control efficiency of the anaerobic dry fermentation pH control system was reflected by the flow error and electromagnetic valve response time. The main positions affecting the efficiency of pH control are at the front and rear ends of the solenoid valve. There are certain errors in the intermittent liquid supply by small water pumps, and there are also errors in the monitoring of flow meters. Flow meter error is a key error. The main cause of flow error is the uncertainty of the viscosity of the biogas slurry. In addition, the electromagnetic flow meter can affect monitoring accuracy based on changes in the electromagnetic field.

Experimental Study on pH Control in Anaerobic Dry Fermentation Environment
To verify the stability of the algorithms, two sets of anaerobic dry fermentation pH control experiments were conducted. The pH experiment collected data from the pH sensor through the PLC after the system was running stably. The experiment involved a combination of adjusting the pH of the biogas slurry and maintaining the fixed pH of 9 of the alkaline liquor. T-S fuzzy control, simplified T-S fuzzy control, simplified T-S fuzzy control optimized by the IAE genetic algorithm and simplified T-S fuzzy control optimized by the ISE genetic algorithm were used. Experiment 1: The control algorithm is described using floating-point precision with a sampling period of 2 s. A set of pH adjustment schemes is set with an initial pH of 5.4 in the simulation scheme and a target pH of 7 after adjustment ( Table 2). A comparison of the test results is shown in Figure 11. From the graph, it can be seen that as the initial pH of the fermentation environment increases, the performance of all four control algorithms improves. The response time of T-S control is 12 s more than PID control and the overshoot is 0.15 less than PID control. The response time of simplified T-S fuzzy control is 11 s and 23 s less than PID and T-S fuzzy control, respectively, and the overshoot is 0.09 less than PID and 0.06 more than T-S fuzzy control. The response time of T-S fuzzy controller optimized by the IAE genetic algorithm is 53 s, 65 s and 42 s less and the overshoot is 0.2, 0.05 and 0.11 less than PID, T-S fuzzy and simplified T-S fuzzy control, respectively. The response time of T-S fuzzy control optimized by the ISE genetic algorithm is 77 s, 89 s, 66 s and 24 s less and the overshoot is 0.28, 0.12, 0.19 and 0.08 less than PID, T-S fuzzy, simplified T-S fuzzy and T-S fuzzy control optimized by the IAE genetic algorithm.

Experimental Study on pH Control in Anaerobic Dry Fermentation Environment
To verify the stability of the algorithms, two sets of anaerobic dry fermentation pH control experiments were conducted. The pH experiment collected data from the pH sensor through the PLC after the system was running stably. The experiment involved a combination of adjusting the pH of the biogas slurry and maintaining the fixed pH of 9 of the alkaline liquor. T-S fuzzy control, simplified T-S fuzzy control, simplified T-S fuzzy control optimized by the IAE genetic algorithm and simplified T-S fuzzy control optimized by the ISE genetic algorithm were used. Experiment 1: The control algorithm is described using floating-point precision with a sampling period of 2 s. A set of pH adjustment schemes is set with an initial pH of 5.4 in the simulation scheme and a target pH of 7 after adjustment ( Table 2). A comparison of the test results is shown in Figure 11. From the graph, it can be seen that as the initial pH of the fermentation environment increases, the performance of all four control algorithms improves. The response time of T-S control is 12 s more than PID control and the overshoot is 0.15 less than PID control. The response time of simplified T-S fuzzy control is 11 s and 23 s less than PID and T-S fuzzy control, respectively, and the overshoot is 0.09 less than PID and 0.06 more than T-S fuzzy control. The response time of T-S fuzzy controller optimized by the IAE genetic algorithm is 53 s, 65 s and 42 s less and the overshoot is 0.2, 0.05 and 0.11 less than PID, T-S fuzzy and simplified T-S fuzzy control, respectively. The response time of T-S fuzzy control optimized by the ISE genetic algorithm is 77 s, 89 s, 66 s and 24 s less and the overshoot is 0.28, 0.12, 0.19 and 0.08 less than PID, T-S fuzzy, simplified T-S fuzzy and T-S fuzzy control optimized by the IAE genetic algorithm. Experiment 2: The control algorithm is described using floating-point precision with a sampling period of 2 s. A set of pH adjustment schemes is set with an initial pH of 6 in the simulation scheme and a target pH of 7 after adjustment (Table 3). A comparison of the test results is shown in Figure 12. From the graph, it can be seen that as the initial pH of the fermentation environment increases, the performance of all four control algorithms improves. The response time of T-S control is 15 s less and the overshoot is 0.21 less than PID control. The response time of simplified T-S fuzzy control is 37 s and 22 s less and the overshoot is 0.18 and 0.03 more than PID and T-S fuzzy control. The response time of T-S fuzzy control optimized by the IAE genetic algorithm is 61 s, 46 s and 24 s less and the overshoot is 0.25, 0.04 and 0.07 less than PID, T-S fuzzy and simplified T-S fuzzy control, respectively. The response time of the T-S fuzzy controller optimized by the ISE genetic algorithm is 84 s, 69 s, 47 s and 23 s less and the overshoot is 0.32, 0.11, 0.14 and 0.07 less than PID, T-S fuzzy, simplified T-S fuzzy and T-S fuzzy control optimized by the ISE genetic algorithm. Experiment 2: The control algorithm is described using floating-point precision with a sampling period of 2 s. A set of pH adjustment schemes is set with an initial pH of 6 in the simulation scheme and a target pH of 7 after adjustment (Table 3). A comparison of the test results is shown in Figure 12. From the graph, it can be seen that as the initial pH of the fermentation environment increases, the performance of all four control algorithms improves. The response time of T-S control is 15 s less and the overshoot is 0.21 less than PID control. The response time of simplified T-S fuzzy control is 37 s and 22 s less and the overshoot is 0.18 and 0.03 more than PID and T-S fuzzy control. The response time of T-S fuzzy control optimized by the IAE genetic algorithm is 61 s, 46 s and 24 s less and the overshoot is 0.25, 0.04 and 0.07 less than PID, T-S fuzzy and simplified T-S fuzzy control, respectively. The response time of the T-S fuzzy controller optimized by the ISE genetic algorithm is 84 s, 69 s, 47 s and 23 s less and the overshoot is 0.32, 0.11, 0.14 and 0.07 less than PID, T-S fuzzy, simplified T-S fuzzy and T-S fuzzy control optimized by the ISE genetic algorithm.

Experimental Study on pH Control in Anaerobic Dry Fermentation Environment
The above experimental results are from one experiment. We measured the control results of the actual pH sensor control system at 80 s. According to the experimental requirements, we adjusted the initial pH values in the fermentation device to 5.4 and 6.0, and we used five algorithms to control the results for each initial value at 80 s. Then, we took the average value from 10 experiments. Under the condition of inputting a control solution with a pH of 9, the pH in the fermentation device was adjusted to 7 according to the system control requirements. The experimental results are shown in Table 4.

Experimental Study on pH Control in Anaerobic Dry Fermentation Environment
The above experimental results are from one experiment. We measured the control results of the actual pH sensor control system at 80 s. According to the experimental requirements, we adjusted the initial pH values in the fermentation device to 5.4 and 6.0, and we used five algorithms to control the results for each initial value at 80 s. Then, we took the average value from 10 experiments. Under the condition of inputting a control solution with a pH of 9, the pH in the fermentation device was adjusted to 7 according to the system control requirements. The experimental results are shown in Table 4. According to the experimental results in Table 4, when the initial pH is 5.4 and the target value is 7, the simplified T-S fuzzy control optimized by the ISE genetic algorithm reduces the relative error by 3.1% compared to PID control, by 2.4% compared to T-S fuzzy control, by 1.6% compared to simplified T-S fuzzy control, and by 0.8% compared to simplified T-S fuzzy control optimized by the IAE genetic algorithm IAE. When the initial pH is 6 and the target value is 7, the simplified T-S fuzzy control optimized by the ISE genetic algorithm reduces relative error by 2.6% compared to PID control, by 1.4% compared to T-S fuzzy control, by 1.5% compared to simplified T-S fuzzy control, and 1.3% compared to simplified T-S fuzzy control optimized by the IAE genetic algorithm. According to the above experimental results, the simplified T-S fuzzy control optimized by the ISE genetic algorithm has the best control effect.

Conclusions
This study proposes an improved genetic algorithm to optimize the T-S fuzzy controller, which has better response time for addressing the acidification problem in the process of dry fermentation for biogas production and reduces hysteresis, thereby reducing the fermentation time in the acidified environment.
Through the control simulation and actual experimentation with the pH of the dry fermentation biogas production process, the function of the monitor designed in this study was checked by comparing the response time, steady-state time, overshoot data, and rise time among all algorithms.
The test results indicate that the T-S fuzzy control system optimized by the improved genetic algorithm has good dynamic performance. Compared with the other three algorithms, this algorithm is significantly superior in overshoot, response time and steady-state time. This controller can reduce the adjustment of pH during the actual fermentation process, and the results are excellent. In the future, further consideration will be given to combining it with other control algorithms to better adapt to the more complex pH regulation of anaerobic dry fermentation for biogas production.
Author Contributions: This study was conceptualized by P.W. and X.S. The test setup was completed by P.W., R.L. and H.Q. The software was designed by P.W. and Y.C. M.C. and J.C. provided resources and P.W. curated the data. The original draft of the manuscript was prepared by P.W. M.C. reviewed and edited the manuscript. All authors have read and agreed to the published version of the manuscript. Data Availability Statement: All relevant data presented in the article are stored according to institutional requirements and, as such, are not available online. However, all data used in this manuscript can be made available upon request to the authors.