Monday, 19 March 2012

Simulation Test

Objective
To test the simulation that has been done.

Activity
Test the simulation to gain the result that is needed. The test would be using various transfer function to gain the needed result.

Analysis
The result for the test can be seen below:

Result for transfer function:
0.009201 z + 0.005709
--------------------------
z^2 - 1.088 z + 0.2369

Result for the test
The programming:
% File Name : fyp.m
% A fuzzy controller is designed to control the system
% The inputs to the FLC are error and change in error.
% clear all;
% clc;
npoints = 1000;
d = 100;
vk = 0;
vk1 = 0;
tk = 0;
tk1 =0;
ref = 1.0;
perr = 0;
delerr = 0;

% Code for step input generation
ref = 1;
nfin = npoints;

step =  nfin/d;
ni = 1;
nf = d;
flag = 1;
for i = 1:step
    if(flag == 1)
        r(ni:nf) = 1;
        ni = nf+1;
        nf = nf+d;
        flag = 0;
    else
        r(ni:nf) = -1;
        ni = nf+1;
        nf = nf+d;
        flag = 1;
    end
end

fismat = readfis('try1.fis');

for i = 1:npoints
    %ref = r(i);
    ref = 1;
    tk2 = 1.078*tk1-0.2426*tk+0.009201*vk1+0.005709*vk;
    out(i) = tk2;
    tk = tk1;
    tk1 = tk2;
    err = ref - tk2;
    delerr = err - perr;
    perr = err;
    error(i) = err;
    delerror(i) = delerr;
    vk = vk1;
    vk1 = evalfis([err delerr],fismat);
    vkout(i) = vk1;
end;
figure(1);
grid on;
i=0:npoints-1;
plot(i,out(1:npoints),'k');
xlabel('k');
ylabel('Output');
title('Basic FLC : Attitude Response for Step Input');

The result shows the response curve of the motor system that is designed in the programming. The output should be 1 but for this result, the output is 0.9.

Result for transfer function:
1/s^2

Result for the test



The programming:
% File Name : NSYS1.m
% Given system is
% theta(k+2) = 2*theta(k+1) - theta(k)+ 0.5*m(k+1) + 0.5*m(k)
% A fuzzy controller is designed to control the system
% The inputs to the FLC are error and change in error.
% clear all;
% clc;
npoints = 1000;
d = 100;
mk = 0;
mk1 = 0;
tk = 0;
tk1 =0;
ref = 1.0;
perr = 0;
delerr = 0;

% Code for step input generation
ref = 1;
nfin = npoints;

step =  nfin/d;
ni = 1;
nf = d;
flag = 1;
for i = 1:step
    if(flag == 1)
        r(ni:nf) = 1;
        ni = nf+1;
        nf = nf+d;
        flag = 0;
    else
        r(ni:nf) = -1;
        ni = nf+1;
        nf = nf+d;
        flag = 1;
    end
end

fismat = readfis('naga38.fis');

for i = 1:npoints
    %ref = r(i);
    ref = 1;
    tk2 = 2*tk1-tk+0.5*mk1+0.5*mk;
    out(i) = tk2;
    tk = tk1;
    tk1 = tk2;
    err = ref - tk2;
    delerr = err - perr;
    perr = err;
    error(i) = err;
    delerror(i) = delerr;
    mk = mk1;
    mk1 = evalfis([err delerr],fismat);
    mkout(i) = mk1;
end;
figure(1);
grid on;
i=0:npoints-1;
plot(i,out(1:npoints),'k');
xlabel('k');
ylabel('Output');
title('Basic FLC : Attitude Response for Step Input');


The result shows the response curve of the motor system that is designed in the programming. The output is the same with reference speed that have been set.

 
 

 
 


Saturday, 10 March 2012

MATLAB programming for the DC motor control using Fuzzy Logic Controller

Objective
To create the programming for the DC motor control using Fuzzy Logic Controller.

Activity
Programming for the DC motor control using Fuzzy Logic Controller is created in the MATLAB applications. The programming will be according to the function needed which is to control the speed of the DC motor. So, the response curve of the DC motor will be the result in the program.

Analysis
The programming for the DC motor control using Fuzzy Logic Controller is shown below:

% File Name : fyp.m
% A fuzzy controller is designed to control the system
% The inputs to the FLC are error and change in error.
% clear all;
% clc;
npoints = 1000;
d = 100;
vk = 0;
vk1 = 0;
tk = 0;
tk1 =0;
ref = 1.0;
perr = 0;
delerr = 0;

% Code for step input generation
ref = 1;
nfin = npoints;

step =  nfin/d;
ni = 1;
nf = d;
flag = 1;
for i = 1:step
    if(flag == 1)
        r(ni:nf) = 1;
        ni = nf+1;
        nf = nf+d;
        flag = 0;
    else
        r(ni:nf) = -1;
        ni = nf+1;
        nf = nf+d;
        flag = 1;
    end
end

fismat = readfis('try1.fis');

for i = 1:npoints
    %ref = r(i);
    ref = 1;
    tk2 = 1.078*tk1-0.2426*tk+0.009201*vk1+0.005709*vk;
    out(i) = tk2;
    tk = tk1;
    tk1 = tk2;
    err = ref - tk2;
    delerr = err - perr;
    perr = err;
    error(i) = err;
    delerror(i) = delerr;
    vk = vk1;
    vk1 = evalfis([err delerr],fismat);
    vkout(i) = vk1;
end;
figure(1);
grid on;
i=0:npoints-1;
plot(i,out(1:npoints),'k');
xlabel('k');
ylabel('Output');
title('Basic FLC : Attitude Response for Step Input');

Thursday, 23 February 2012

Design the Fuzzy Logic Controller

Objective
To design the FLC using the MATLAB applications.

Activity
Design the FLC in MATLAB applications with 2 input which is error and change of error and the output will be voltage. The membership functions of system is designed in MATLAB. The rules of the fuzzy is decided in MATLAB.



Membership function for first input (error)
Membership function for second input (change of error)


Membership function of the output

Analysis
To design all the membership functions need a very long time because there is no systematic procedure to design  the membership function like to know the limit range, how many membership function needed and many more. So, it need try and error procedure which is time consuming. We need to try every possible way to make it work properly.

Tuesday, 14 February 2012

Transfer function of DC motor in discrete transfer function

Objective
To convert continuous transfer function to discrete transfer function.

Activity
Use the MATLAB applications to convert continuous transfer function to discrete transfer function.

Analysis
The program to convert continuous to discrete are as below:


The first step in designing the discrete control system is to convert the continuous transfer function to a discrete transfer function. The MATLAB command c2d will do this for you. The c2d command requires the following three arguments: system, the sampling time (Ts) and method for conversion. In this example, we will use the zero-order hold ('zoh') method.
From the design requirement, let the sampling time, Ts equal 0.12 seconds, which is 1/10 the time constant of a system with a settling time of 2 seconds. Let's create a new m-file and enter the following commands:
    R = 1;
    L = 0.5;
    Kt = 0.01;
    J = 0.01;
    b = 0.1;
    
    num = Kt;
    den = [(J*L) (J*R)+(L*b) (R*b)+(Kt^2)];
    
    motor = tf(num,den)
    
    Ts = 0.12;
    motor_d= c2d(motor,Ts,'zoh')
    
Running this m-file should return the following:
     
    Transfer function:
    0.009201 z + 0.005709
    ----------------------
    z^2 - 1.088 z + 0.2369
     
    Sampling time: 0.12

Thursday, 2 February 2012

Transfer Function of DC motor in s domain

Objective
To do the derivation for the DC motor transfer function.

Activity
Find the derivation for the transfer function of DC motor in s domain.

Analysis
The derivation of the DC motor transfer function can be seen below:



DC motor model

The transfer function for the DC motor is:

Gv(s)=(θ(s))/V(s) =K/([(R+Ls)(Js+b)+K^2])

We assume the physical parameter of the motor is:

* moment of inertia of the rotor (J) = 0.01 kg.m^2/s^2
* damping ratio of the mechanical system (b) = 0.1 Nms
* electromotive force constant (K=Ke=Kt) = 0.01 Nm/Amp
* electric resistance (R) = 1 ohm
* electric inductance (L) = 0.5 H
* input (V): Source Voltage
* output (theta): position of shaft
* The rotor and shaft are assumed to be rigid

Saturday, 28 January 2012

Research of the project

Objective
  1. To do some research for this project.
  2. To gain knowledge about this project.
Activity
Research about other project that related to this project, which using the FLC. Research about the MATLAB application. Research about the Fuzzy Logic Controller, how the FLC works, the advantages of FLC, the limitations and more. 

Analysis
Information is gathered using resources such as internet, books and journals that available in the library. Many journals have been read to familiarize  about the project.

Friday, 20 January 2012

Project Description

The purpose of this project is to control the speed of DC motor by using fuzzy logic controller with MATLAB applications. The scopes includes the simulation and modeling of DC motor, implementation of fuzzy logic controller to DC motor using MATLAB applications. This research was about to introduce the new ability of estimating speed and control the DC motor. By using the controller, the speed can be tuned until it get similar to the desired output that user need. There are some problem occur while controlling the DC motor. The problems occur such as losses and efficiency of the motor. To encounter the problem, the controller is needed and for this project Fuzzy Logic Controller will be used. FLC is chosen as a controller for this project because it consist several advantages compared to the other classical controller. The structure of FLC consists of the following 3 major components which the first one is fuzzifier that used for measurement of the input. The second one is rule base which provides the system with decision making. The third is defuzzifier which combines the actions that have been decided. The objectives of this project are to design a DC motor with Fuzzy Logic Controller using MATLAB applications and to control the speed of DC motor.