PID controller and PID tuner for a SIMO system
Show older comments
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
More Answers (0)
Categories
Find more on PID Controller Tuning in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

