How to obtain PID controller co-effs as a function of time and o/p
3 次查看(过去 30 天)
显示 更早的评论
Hi,
I want to create a PID controller where the values of Kp, Kd and Ki are functions of time and model o/p. Is this possible?...
Thanks
Shilp
0 个评论
回答(3 个)
Sachin Ganjare
2012-10-30
4 个评论
Sachin Ganjare
2012-10-31
Well you can make Kp time varint, by giving it different values at different time instants. You can make use of 'From Workspace' block for driving different values of 'Kp'.
Arkadiy Turevskiy
2012-10-30
Of course, it is possible, but it would require some effort.
Most commands in Control System Toolbox are for working with LTI (linear time-invariant) systems. The system you are trying to design/simulate is a time-variant one.
So to do what you want in MATLAB, you would need to create a for loop. In this for loop you will be doing a simulation one step at a time, and using the output as initial condition for the next step. You will also use the output to calculate your PID gains. In other words, you cannot just use one call to lsim. You'll need to put lsim into a for loop, and in the body of the loop compute PID gains at each time step to form a new LTI system at each time step, and calculate its response just one time step ahead.
Hope this makes sense.
Of course, it would be much much easier to do Simulink where you could use look-up tables to schedule your PID gain with whatever you want.
Arkadiy
2 个评论
Jonathan Epperl
2012-10-31
You can only describe linear, time-invariant behaviors with transfer functions. The logic component of your algorithm is not linear, so no, you cannot make that into a transfer function.
Jonathan Epperl
2012-10-31
As said above, your PID controller is now time-variant and maybe even nonlinear (depending on whether the gains actually depend on the states/outputs). Thus I would abandon the control systems toolbox functions lsim etc., I don't think they will do you much good.
What I would suggest is: combine your plant and your controller into a closed system, then use ode23.
Lets say your system is ss(A,B,C,0), your controller is a dynamical system dcdt=F(c,y,t) and u=G(c,t). Then your closed system would be something like
[dxdt; dcdt] = [A*x+B*G(c,t); F(c,C*x,t)]
Here is a silly example, I hope you can extend it to your particular case. The main script looks like this:
% LTI system
G = tf([1 0],[1 2 3 1]);
S = ss(G);
% call to the ode solver
opts = odeset;
[t,x] = ode23(@silly_ode,[0 10],[1 -1 10],opts,S);
% Any additional arguments after the Options will be passed to the ode_fun
% Reconstruct the input u, since it is not accessible (afaik)
u = 0*t;
u(x(:,1)>0) = x( x(:,1)>0, :)* [-1 -1 -1]';
u(x(:,1)<=0) = x( x(:,1)<=0, :)* [-1 -1 -2]';
u = u + .5*exp(-t);
% plot
plot(t,x); hold on; plot(t,u,'x'); hold off;
legend([num2str((1:3)','x_%d');'u '],'Location','South')
The function silly_ode.m should be located in your Matlab path and in my case looks like this:
function dxdt = silly_ode(t,x,S)
dxdt = S.A*x + S.B*controller_nest(t,x);
%
function u = controller_nest(t,x)
if x(1)>0
u = [-1 -1 -1]*x + 0.5*exp(-t);
else
u = [-1 -1 -2]*x + 0.5*exp(-t);
end
end
%
end
So the controller here is static and linear, but time-variant and scheduled on x(1). It should be easy to adapt to the more complicated case you are dealing with.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Gain Scheduling 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!