How to obtain PID controller co-effs as a function of time and o/p

3 Ansichten (letzte 30 Tage)
Shilp Dixit
Shilp Dixit am 30 Okt. 2012
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

Antworten (3)

Sachin Ganjare
Sachin Ganjare am 30 Okt. 2012
  4 Kommentare
Shilp Dixit
Shilp Dixit am 30 Okt. 2012
Hi Sachin,
Thanks for your quick response. These links though useful do not tell me how to create Kp as a function of time. They have taken Kp as a constant.
If it is not possible to create a PID controller where Kp, Kd and Ki are functions of time and model output can you please guide me with the process of creating a manual feedback algorithm (create a custom transfer function).
Thanks again.
Sachin Ganjare
Sachin Ganjare am 31 Okt. 2012
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'.

Melden Sie sich an, um zu kommentieren.


Arkadiy Turevskiy
Arkadiy Turevskiy am 30 Okt. 2012
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 Kommentare
Shilp Dixit
Shilp Dixit am 31 Okt. 2012
Hi,
Thanks for your answer. I will try to write a for loop as you have explained. Hopefully it works.
I have another idea. Want to know if that can work
Can't I create my own custom feedback transfer function and use it as feedback. Something like:
if true
% Input
u1;
u2;
% output
Fb = 0;
% Constants
G; a;
% logic for function output
if (u1*(u1-u2) > 0)
if (-1*u2(u1-u2) > 0)
Fb = G(a*u1 + (1-a)*u2))
else
Fb = G*a*u1;
end
else
if (-1*u2(u1-u2) > 0)
Fb = G*(1-a)*u2);
end
end
end
But i dont know how to code for this logic and create a transfer function out of it.
Jonathan Epperl
Jonathan Epperl am 31 Okt. 2012
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.

Melden Sie sich an, um zu kommentieren.


Jonathan Epperl
Jonathan Epperl am 31 Okt. 2012
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.
  1 Kommentar
Shilp Dixit
Shilp Dixit am 31 Okt. 2012
Hi,
Thank for your answer. I am pretty new to the environment and dont have any experience working with ode's. Your solution seems great. I will try to scale it for my problem and see how it goes. Thanks once again...
My problem is as follows:
if true
G = suspension_setting_selection; % Gain function based on suspension setting
[fs] = repmat(G,[m,n]); % hybrid damper force function
A = [0 1 0 -1; -1*ks/Ms -1*bs/Ms 0 bs/Ms; 0 0 0 -1; ks/Mu bs/Mu kt -1*bs];
B = [0 0; 0 1/Ms; 1 0; 0 -1];
C = eye(4);
D = zeros(4,2);
states = {'susp deform', 'Ms velocity', 'tire deform', 'Mu velocity'};
inputs = {'Road velocity', 'Semi-active damper force'};
outputs = {'susp deform', 'Ms velocity','tyre deform', 'Mu velocity'};
sys_mimo = ss(A, B, C, D, 'statename',states,...
'inputname',inputs,...
'outputname',outputs); % state space model
size(sys_mimo) % Gives information of the MIMO state space model
sys_mimo_tf = tf(sys_mimo); % convert state space model to transfer function
%{
Feedback strategies
***********REFERENCE******************************************************
sys_mimo_tf(1,1) % TF i/p Road velocity to o/p Suspension Deformation
sys_mimo_tf(1,2) % TF i/p SA Damper Force to o/p Suspension Deformation
sys_mimo_tf(2,1) % TF i/p Road Velocity to o/p Ms Velocity
sys_mimo_tf(2,2) % TF i/p SA Damper Force to o/p Ms Velocity
sys_mimo_tf(3,1) % TF i/p Road velocity to o/p tyre deformation
sys_mimo_tf(3,2) % TF i/p SA Damper Force to o/p tyre deformation
sys_mimo_tf(4,1) % TF i/p Road Velocity to o/p Mu velocity
sys_mimo_tf(4,2) % TF i/p SA Damper Force to o/p Mu velocity
-------------------------------------------------------------------------
%}
% PID control for sys_mimo_tf(1,2)
Kp=0;
if y(2)*[y(2)-y(4)] > 0
Kp = G*alpha*y(2) % y(2) = velocity at that instant
end
H = pid(Kp);
sys_mimo_tf(1,2) = feedback(sys_mimo_tf(1,2),H);
% PID control for sys_mimo_tf(3,2)
Kp=0;
if -1 * y(4)*[y(2)-y(4)] > 0
Kp = G*alpha*y(4) % y(4) = velocity at that instant
end
H = pid(Kp);
sys_mimo_tf(3,2) = feedback(sys_mimo_tf(3,2),H);
end
The if block has syntactical errors but what I want to achieve is this:
1. Kp should be a dynamic value which depends on the instantaneous values of y2 and y4.
How do I create the Kp from the PID controller as a function of y2 and y4 from the output vector.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by