MATLAB: Basic to Control


Berikut ini adalah script MATLAB untuk dasar kendali dengan PID.



clear all, close all, clc;

%% Define the plant

P = tf([1],[1 0 -9]);
% transfer function of the plant
% P =
%      1
%   -------
%   s^2 - 9
pole(P)
% yields s = 3 and s = -3
% thus the plant is not stable

%% The PID controller

Kp = 90;
Ki = 60;
Kd = 30;
% taking into Laplace form
% K = Kd*s + Kp + Ki/s


K = tf([Kd Kp Ki],[1 0]);
% PID controller
% K =
%
%   30 s^2 + 90 s + 60
%   ------------------
%           s
CP = series(K,P);
% the open-loop equals to:
% CP = K*P

CL = feedback(CP,1);
% closed-loop (CL) feedback of the system
pole(CL);
% yields
% s = -27.0919 + 0.0000i
% s =  -1.4540 + 0.3170i
% s =  -1.4540 - 0.3170i

%% Verify the stablility of CL

if isstable(CL,1)
    'Closed-loop is stable'
else
    'Closed-loop is not stable'
end

%% Step response of the system

t = 0:0.1:5;

step(CL,t)
Closed-loop system tersebut stabil. Berikut ini adalah step-response.



Lihat juga tentang.
Kendali state space MATLAB.