PID controller and PID tuner for a SIMO system

34 views (last 30 days)
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

Accepted Answer

Sam Chak
Sam Chak on 24 Jul 2022
Edited: Sam Chak on 24 Jul 2022
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)
Gp = From input to output... 1 1: ----------------- s^2 + 1.1 s + 0.3 s 2: ----------------- s^2 + 1.1 s + 0.3 Continuous-time transfer function.
% 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)
Gc = s Kp + Kd * -------- Tf*s+1 with Kp = 0.7, Kd = 0.9, Tf = 0.1 Continuous-time PDF controller in parallel form.
% closed-loop
Gcl = feedback(Gc*Gp(1), 1)
Gcl = 9.7 s + 7 -------------------------- s^3 + 11.1 s^2 + 21 s + 10 Continuous-time transfer function.
% 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])
Gf = 10 --------- 9.7 s + 7 Continuous-time transfer function.
% closed-loop with prefilter
Gclf = minreal(series(Gf, Gcl))
Gclf = 10 -------------------------- s^3 + 11.1 s^2 + 21 s + 10 Continuous-time transfer function.
% 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))
Gfu = 10 s^2 + 11 s + 3 -------------------------- s^3 + 11.1 s^2 + 21 s + 10 Continuous-time transfer function.
step(Gfu, 10), grid on
Note: The following Block diagram in Simulink should produce the same outputs as demonstrated in MATLAB:
  2 Comments
Mikel
Mikel on 24 Jul 2022
thank you! I have another question, is it possible using the feedback function to acces to the values of the PID output? or for that should I build a PID manually doing all the calculations by myself?
Sam Chak
Sam Chak on 24 Jul 2022
You are welcome @Mikel. I have edited my Answer to show you how to obtain the PID output as well.
If you find the explanations, MATLAB code, and block diagram are helpful, please consider accepting ✔ and voting 👍 the Answer. Thanks!

Sign in to comment.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!