PID controller and PID tuner for a SIMO system
27 次查看(过去 30 天)
显示 更早的评论
Hello,
I've been trying to search how to tune my PID using pidTuner and pidtune but I dont know how should I do it since my system has 1 input and 2 outputs. Because of this, I can´t use pidTuner as it seems that only works for SISO plants or 2 DOF PID controllers. Another thing to say is, that, this is my first control script in matlab, so I´m sure that there is a better way to create the system itself or the PID. Any help is highly appreciated!
So far, I managed to create the control scheme, but I need help for tunning the PID.
%% INIT
clear variables;
close all;
clc;
%% Reference input
% time
time=150;
%SINUSOIDAL
t = (0:0.1:time);
A=4;
w=0.8;
u1=A*sin(w*t);
%dr=zeros(1,length(r)-1);
%dr(1,:)=diff(r)./diff(t);
du1=gradient(u1,t);
%STEP
u2=step(tf(1,1,'InputDelay',10),t);
du2=gradient(u2,t);
%% variable initialization
[a,b,Kp,Kd,Ki,deltaT]= initVar();
%define space state system
f2 = @(t,X) [X(2); a*X(1)+b*X(2)];
%% DEFINE SYSTEM
% x1'= x2;
% x2'= a*x1+b*x2+u
As=[0 1;a b];
Bs=[0;1];
Cs=[1 0;0 1];
Ds=[0;0];
sys = ss(As,Bs,Cs,Ds);
systf=tf(sys);
%% PID
FC=pid(Kp,Ki,Kd,deltaT);
%% LOOP
% close the loop with the PID controller
size(systf*FC)
feedin=1;
feedout=1;
csys = feedback(systf*FC,feedin,feedout,1);
%output
ys= lsim(csys,u2,t);
rf=ys(:,1);
drf=ys(:,2);
max(rf)
max(drf)
%% PLOT
% plot position and speed of the system
figure
subplot(2,1,1)
plot(t,rf,'k', 'LineWidth',2)
hold on
plot(t,u2,'r', 'LineWidth',2)
xlabel('time(s)','fontweight','bold','FontSize',12)
ylabel('position','fontweight','bold','FontSize',12)
title('function evolution')
subplot(2,1,2)
plot(t,drf,'k', 'LineWidth',2)
hold on
plot(t,du2,'r', 'LineWidth',2)
xlabel('time(s)','fontweight','bold','FontSize',12)
ylabel('speed','fontweight','bold','FontSize',12)
%plot surface generated by the function
% [x1,x2] = meshgrid(-5:5);
% surff=a*x1+b*x2;
% figure
% surf(x1,x2,surff)
% view(135,45)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% FUNCTION
function [a,b,Kp,Kd,Ki,deltaT]= initVar()
%coefs
a=-0.3;
b=-1.1;
%gains
Kp=3;
Kd=0.8;
Ki=0.9;
deltaT=1e-1;
end
0 个评论
采纳的回答
Sam Chak
2022-7-24
编辑:Sam Chak
2022-7-24
Hi @Mikel
Your system is
.
If you algebraically design u as
,
then the closed-loop becomes
.
Since you didn't specify the performance requirements, here is just a little test on the theoretical calculation. This method assumes that you can measure the velocity directly.
% parameters
a = -0.3;
b = -1.1;
% system
As = [0 1; a b];
Bs = [0; 1];
Cs = [1 0; 0 1];
Ds = [0; 0];
sys = ss(As, Bs, Cs, Ds);
Gp = tf(sys)
% gains designed by a simple algebra manipulation
Kp = 0.7;
Ki = 0.0;
Kd = 0.9;
Tf = 0.1;
Gc = pid(Kp, Ki, Kd, Tf)
% closed-loop
Gcl = feedback(Gc*Gp(1), 1)
% step(Gcl, 10) % can see the effect of zero that causes the overshoot
% Add a prefilter at the Reference Input to cancel out the zero (numerator of Gcl)
Gf = tf(10, [9.7 7])
% closed-loop with prefilter
Gclf = minreal(series(Gf, Gcl))
% system response
[y, t] = step(Gclf, 10);
plot(t, y), grid on
% PID output (I think so)
Gu = feedback(Gc, Gp(1));
Gfu = minreal(series(Gf, Gu))
step(Gfu, 10), grid on
Note: The following Block diagram in Simulink should produce the same outputs as demonstrated in MATLAB:
2 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Classical Control Design 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!