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');

1 comment:

  1. salam,
    I want to ask u some question..it possible to have the fuzzy code to control speed and position for DC motor? or just do the matlab simulation after get the transfer function equation?if it possible can u teach me how to create the code based on transfer function equation.. please advice...tq

    ReplyDelete