%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%% The Sugeno-Takagi-like fuzzy controller%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% To run a quick demo of this controller, open the simulink model fuzzy_controller.mdl and run the simulation.
% To use the controller on a different system (or plant) the reader has to
% tune the gains of the inputs for the controller: error gain, error_dot
% gain and the output gain.
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%% Description of the controller%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This controller is a two input one output fuzzy controller
% The first input is the error=x
% The second input is the error_dot=y(time derivative of the error)
% The output of the fuzzy controller is the CHANGE in the control action and NOT the control action.
%
% The fuzzy membership functions for the first and second inputs are isosceles triangular memberships (5 membership functions for each input).
% The triangles of the first input x have their peaks at [-x_a -x_a/2 0 x_a/2 x_a]. The length of the base of each triangle is of x_a .
% The triangles of the second input y have peaks at [-y_a -y_a/2 0 y_a/2 y_a]. The length of the base of each triangle is of y_a .
% x_a and y_a have been set to 1(in the fuzzy_system_data.m file). The user can change these but I would advise the user to change the gains for the error
% and error_dot instead of altering x_a and y_a.
% The membership functions for the output are crisp values rather than fuzzy memberships:
% The memberships for the output are: NB, NM, Z, PM and PB referring to negative big, negative medium, zero, positive medium and positive big respectively.
%
% Fuzzy rules (25) are as follows: (see the table 1, note that in the table the notation is(LN, SN, Z, SP, LP) corresponding to (NB, NM, Z, PM, PB) in the simulink code):
% Ruleij for i=1:5 and j=1:5:
%
% rule11: (if x is negative big) and (y is negative big) then (z is negative big)
% rule21: (if x is negative big) and (y is negative medium) then (z is negative big)
% .
% .
% .
% .
% rule55:
%
% The output z is computed as:
% z=sum(wij*zij)/sum(wij)
% where i=1:5 and j=1:5(25 rules)
% wij is the firing weight of rule ij (which is the minimum between the degree of membership of input 1 and the the degree of membership of input 2).
% zij is the value of z in the rule ij. For example for rule11 z11=NB, for rule21 z21=NB ...