pid.m

来自「螺旋桨PID控制 In response to constant pressu」· M 代码 · 共 73 行

M
73
字号
%creating function, asking for proportional, integral, and derivative gain
function project(KP,KI,KD)

%create uncontrolled transfer function model
sys = tf([516.198],[100 20*10^3 399741.90867])

%calculating poles and zeros
[z,p] = zpkdata(sys,'v')

%display impulse and step inputs to uncontrolled system
impulse(sys)
figure
step(sys)

%convert TF to state space model
[A,B,C,D] = tf2ss([516.198],[100 20*10^3 399741.90867])

%checking observability and controllability of uncontrolled model
Observ = obsv(A,C)
Unobserv = length(A) - rank(Observ);

if Unobserv <= 0
            disp('System is fully Observable')
        else
            disp('System is not fully Observable')
        end
    
Control = ctrb(A,B)
Uncontrol = length(A) - rank(Control);

if Uncontrol <= 0
            disp('System is fully Controllable')
        else
            disp('System is not fully controllable')
        end

%%%%%%%% adding a PID controller

sys2 = tf([KD KP (KI+516.183)],[100 (KD+(20*10^3)) (KP+399741.90867) KI])

%calculating new zeros and poles of controlled system
[z2,p2] = zpkdata(sys2,'v')

%displaying controlled response to step and impulse inputs
figure
impulse(sys2)
figure
step(sys2)
figure
pzmap(sys2)

%converting controlled TF to state space model
[A2,B2,C2,D2] = tf2ss([KD KP (KI-516.183)],[100 (KD+(20*10^3)) (KP+399741.90867) KI])

%checking observability and controllability of controlled model
Observ2 = obsv(A2,C2)
Unobserv2 = length(A2) - rank(Observ2);

if Unobserv2 <= 0
            disp('System with PID Controller is fully Observable')
        else
            disp('System with PID Controller is not fully Observable')
        end
    
Control2 = ctrb(A2,B2)
Uncontrol2 = length(A2) - rank(Control2);

if Uncontrol2 <= 0
            disp('System with PID Controller is fully Controllable')
        else
            disp('System with PID Controller is not fully controllable')
        end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?