# Creating a controller based on fuzzy logic with multichannel tuning

“But we are making rockets!”

In the previous article, I checked whether it is possible to automatically adjust a fuzzy controller using “standard optimization methods”. It turned out possible and the result of automatic configuration is quite satisfactory. At least for the rocket whose model was used.

For non-stationary control objects where the object's parameters vary in wide ranges, a fuzzy controller may not provide sufficient control quality in all ranges of operation. In this case, it is necessary to use a fuzzy regulator with “multichannel tuning”.

Check whether it is possible to configure such a regulator with standard optimization methods.
Consider the synthesis of a fuzzy regulator with a multichannel setting to stabilize a ballistic missile in the pitch angle. As suggested in the comments, the rocket will be the V-2. We use an example from the same book by Gostev V.V. "Fuzzy regulators in automatic control systems".

All terms used in this text are taken from this book and may not correspond to the strict terminology of the theory of automatic control.

# Formulation of the problem

A ballistic missile that uses a large number of local control systems is essentially a non-stationary control object. The transfer functions that describe a rocket as a control object differ from the transfer functions of cruise aircraft in that they have unstable links, so the movement of an unguided rocket along a program trajectory would be unstable.

Below is considered a ballistic missile stabilization system in pitch angle (longitudinal motion channel). The system consists of the following functionally necessary elements: a
reference element (a free gyroscope with a potentiometric sensor characterized by Kp coefficients);
amplifier with Ku gain, and hydraulic steering gear.

Taking the pitch angle as the output coordinate of the rocket , and the steering angle as the input coordinate , we determine the transfer function in the form: (An analog steering gear and a rocket are included in the control object) The transfer function parameters will be time-dependent polynomials. Mathematically, they can be defined by polynomials:     In the problem, it is assumed that the start time of the flight corresponds to 6 seconds. Polynomial values ​​are accepted with a shift of 6 seconds.
A mathematical model of a nonstationary oscillatory link is described by a differential equation: A mathematical model of a nonstationary forcing link is described by a differential equation: The error of the mismatch, the input to the fuzzy controller, is the difference between the set and the desired pitch angle.

The structural diagram of the model is presented in Figure 1. To understand the principle of model formation, the X1, X variables and their derivatives ( X1 ″, X1 ″, X ' ) are indicated on the communication lines according to the link equations. The green rectangle indicates the part of the model diagram corresponding to the oscillatory component, and the yellow one indicates the forcing.

The parameters a (t), b (t), c (t), r (t) are specified in the form of gain factors, in “amplifier” type blocks. The parameter is specified in the gain of the integrator. Figure 1. Model block diagram.

The program trajectory, the specified pitch angle u (t) = 1 + 0.5sin (πt / 30).
The graphs of the rocket parameters change during the flight are presented in Figure 2.
The value t = 6 is taken as the start of the flight, the value (time + 6) is used as a function of the polynomials, where time is the current simulation time. Figure 2. Graphs of changes in rocket parameters.

# Fuzzy Controller

As a regulator based on fuzzy logic, we use the regulator presented in Figure 3. The input is the mismatch between the specified pitch angle and the real, spent missile, pitch angle.

The block delay per quantization step provides discretization of the conversion of a continuous signal to a discrete one with a sampling step of 0.01 sec.

Using two more delays, per discretization step, the first and second derivative of the deviation are calculated by difference methods.

Phasification blocks calculate the values ​​of terms for deviation, rate of change and acceleration. (For more on this, see the previous text ). At the output of each phasephlation block, we get a vector of terms for linguistic variables. (see table 1)
 Linguistic variable Terms Deviation More Norma Less Rate of change Grows does not change falls Accelerate change Increases constant decreases
Blocks demultiplexers disassemble vectors into individual terms, which are transmitted to blocks of logical processing according to the rules of fuzzy inference.
The result of the work of fuzzy inference also has three linguistic variables: “reduce”, “do not change”, “increase”. In the form of a scheme, the following inference rules are written.

• If more and grows and the growth rate increases => decrease .
• If the norm , and does not change and is constant => do not change .
• If Less and Falls and the fall rate increases => increase . Figure 3. Regulatory scheme based on fuzzy logic.

As the membership function in denazification, triangular functions with a common base are used (see Fig. 4). Figure 4. Triangular phasification functions with a common base.

It is assumed that the functions are symmetric with respect to 0; in this case, one Mach value is enough to describe three triangular functions . For the Max = 30 shown in the figure.

For the output, the same membership functions are used.

To fully define the controller, it is necessary to set the maximum values ​​for the phasification blocks of variables:

- deltaMax - the maximum deviation;
- divMax - maximum derivative of the deviation;
- div2Max - maximum second derivative of the deviation;
- uMax - maximum control action.

# Full process optimization

The maximum control action is taken equal to uMах - 70.
Thus, it remains for us to choose 3 parameters for the phasephcation function.
In this problem, we have the mismatch is served as a step at the zero time of model time, u (t) = 1 + 0.5.sin (πt / 30).

The program trajectory, the specified pitch angle u (t) = 1 + 0.5sin (πt / 30), causes a step effect at the first second of the transition process, as it turned out in experiments with the previous task, the regulators tuned to a smooth control process, at a step effect, can do not provide the required quality of the transition process.

Therefore, for optimization, we form 3 criteria:

1. Transition time - we need as soon as possible to go on a given programmatic trajectory.
2. Standard deviation.
3. The number of switchings - in the experiments with the previous task, we got the option when the output control system had high-frequency oscillations of the control action.

The general scheme of the optimization block is shown in Figure 5. Figure 5. Optimization block diagram.

Input parameters of the optimization block:

- deviation from the specified pitch angle.
- regulatory impact.

To calculate the time of the transition process, a switch is used in which the current model time is fed to one of the inputs. After the block there is a delay for the quantization period, the value from the delay is transmitted to the second input.

The deviation module is used as a switch. If the deviation modulus is greater than the specified switching value (0.02), then the current time is output from the block, if the modulus is less than the specified value, then the memorized time is transmitted to the output when the deviation was greater. If further the deviation again exceeds the limit, we again get time. Thus, at the exit, we always have the last time, when the deviation exceeded the specified one.
The change of the control sign from + to - is taken as the switching unit. To calculate the number of switchings, we use the “pulse along the front” block, which, when the input is changed from 0 to 1, gives a pulse with a duration to the integration step, the pulse counting is performed by the integrator. At the exit from the block - the number of switching.

- The optimization block selects the values ​​of the parameters to be optimized in such a way as to minimize all three parameters:
- deltaMax - the maximum deviation;
- divMax - maximum derivative of the deviation;
- div2Max is the maximum second derivative of the deviation.

# Result optimization for the full transition process.

By launching the optimization process, we obtained the following optimal parameters for the fuzzy controller:

- deltaMax = 0.185– maximum deviation;
- divMax = 0.278 - the maximum derivative of the deviation;
- div2Max = 1.291 is the maximum second derivative of the deviation.

The results of the optimized process are shown in Figure 6. Figure 6a. The transition process. Figure 6b. Management options.

It can be seen that, in general, the optimization was successful, but there are deviations from the specified pitch angle almost throughout the entire process. The enlarged deviation graph shows that deviations after optimization and completion of the transition process are in the redistribution of 0.015 - 0.02. (see fig. 7) Figure 7. Deviation in the process of management.

# Optimization of the flight segments.

Let's try to improve the process by selecting the parameters of the fuzzy controller for different parts of the rocket flight.

The first section is the time from the start to the exit to the specified trajectory. Based on the deviation graph, the transition process associated with the initial step effect ends somewhere at 20 seconds. (see fig. 7). At this site there is an optimization in time of the transition process.

Set the end time of the calculation of 20 seconds. And perform the optimization, removing the standard deviation from the criteria. We will optimize the transition time and the number of switching. The optimization block diagram is shown in Figure 8. Figure 8. Optimization scheme in the first leg of the flight.

Automatic optimization for the first leg of flight for up to 20 seconds produced the following parameters for fuzzy regulation:

- deltaMax = 0.056 is the maximum deviation;
- divMax = 0.0968 - the derivative of the deviation is maximum;
- div2Max = 0.987 - the maximum second derivative of the deviation.

The transition process after optimization is shown in Figure 9. The

deviation on an enlarged scale is presented in Figure 10 Figure 9a. The transition process. Figure 9b. Management options. Figure 10. The deviation on an enlarged scale of the first leg of the flight.

The graphs show that the value of the overshoot has decreased and the deviation after the completion of the transition process has become less than 0.005.

To optimize the next leg of the flight, we will perform a simulation with the saved state obtained in the first leg.

The simulation takes place from 20 to 40 seconds of the flight of a ballistic missile, optimization occurs throughout the process.

Since the transition process is completed by the beginning of the second segment, we carry out optimization only by the deviation and the number of switchings. The optimization block diagram is shown in Figure 11. Figure 11. Optimization scheme in the second leg of the flight.

Automatic optimization for the second leg of the flight from 20 to 40 seconds produced the following parameters for fuzzy regulation:

- deltaMax = 0.056 - maximum deviation;
- divMax = 0.0974 - the maximum derivative of the deviation;
- div2Max = 0.980 is the maximum second derivative of the deviation.

For the given parameters, the deviation of the pitch angle from the predetermined value decreases over the entire second time segment of the flight. But if you use the parameters obtained by optimization on the second leg of the flight to control up to 66 seconds, you can see that the accuracy starts to decrease and the deviation starts to increase after 40 seconds (see Fig. 12). Figure 12. Control process of a ballistic missile with settings optimized for 20–40 seconds of flight.

Repeat optimization for the third leg of the flight. Save the results 40 seconds.

We use them to start and optimize in the area from 40 to 66 seconds.

Automatic optimization for the last leg of the flight from 40 to 66 seconds produced the following parameters for fuzzy regulation:

- deltaMax = 0.0146– the maximum deviation;
- divMax = 0.0157– maximum derivative of deviation;
- div2Max = 0.555 is the maximum second derivative of the deviation.

The graph of the control process in the last leg of the flight of a ballistic missile after optimization is presented in Figure 13. Figure 13. The process of controlling the ballistic missile in the last leg of the flight.

From Figure 13 it can be seen that with the new settings, the deviation in the flight time interval of 40-66 seconds does not increase, unlike the settings optimized for the second leg of the flight (see Fig. 12).

Thus, we obtained the settings of the fuzzy controller for the three flight segments. Let's create a mode switch that will switch the controller settings during the flight. The mode switch is shown in Figure 14. Figure 14. The mode switch of a fuzzy ballistic missile controller.

We will switch the modes according to time, in the upper part a simple logic circuit compares the current model time with the switching points. As a result, the multiplexer forms a control vector of three values. In this vector, the value 1 is at the position of the current time interval.

The parameters of the fuzzy regulator calculated earlier by optimization methods are packed into vectors of three values.

Using a sampling block of three values, the one to which the control corresponds to 1 is selected in the vector. Thus, when the time changes, the parameters passed to the fuzzy controller change according to the current flight segment.

For clarity, the values ​​transmitted via the communication line are displayed in the diagram. Figure corresponds to the last leg of the flight of a ballistic missile. Time is more than 40 seconds. Control vector (0,0,1) the last parameter from the set is fed to the controller.

The result of the simulation of the pitch angle control of the rocket with the switching of the controller parameters is presented in Figure 15. Figure 15a. The transition process. Figure 15b. Management options.

Conclusions:
The controller based on fuzzy logic can be configured by optimization method to work in the mode of switching parameters.

The deviation when working with variable parameters in the above example decreased by 3 - 5 times compared with the operation of the controller with constant parameters.