How to constrain genetic algorithm input u?
2 次查看(过去 30 天)
显示 更早的评论
My real system (buck converter) can only take an input of 0 to 1 (duty ratio) and I need to constrain the system so the controller action does not go past this. How can I do this?
The code for the project is below, it is steve bruntons genetic algorithm coding. https://youtu.be/S5C_z1nVaSg?t=470
I assume the u variable is the duty ratio but I am not sure.
---------------------------------------------------- First live script with Ga cmd in it-------------------------------------
clear all, close all, clc
dt = 0.000001; % this is 10^-6
PopSize = 30 % was 500
MaxGenerations = 10; %was 1000
s = tf('s');
G = (1439928003.68621)/(s*s+5333.33333333333*s+95995200.2457475) % got this by doing feedback cmd
options = optimoptions(@ga,'PopulationSize',PopSize,'MaxGenerations',MaxGenerations,'OutputFcn',@myfun);
[x,fval] = ga(@(K)pidtest(G,dt,K),3,-eye(3),zeros(3,1),[],[],[],[],[],options);
-----------------------------------------------in adjacent live script------------------------------------------------
function J = pidtest(G,dt,parms)
s = tf('s');
K = parms(1)+ parms(2)/s + parms(3)*s/(1+0.000001*s)% this is 10^-6
Loop = series(K,G);
ClosedLoop = feedback(Loop,1);
t = 0:dt:0.05; % this indicates length of time to show
[y,t] = step(ClosedLoop,t);
CTRLtf = K/(1+K*G);
u = lsim(K,1-y,t); % not sure if this is what I should change
Q = [1]; % Q weighting (couldn't get it so it looked at inductor current also) effecfts response of system?
R = 0.005; % R weighting effects controller action
J = dt*sum(Q*(1-y(:)).^2 + R*u(:).^2) % LQR is my cost function
step(5*ClosedLoop,t)
h = findobj(gcf,'type','line');
set(h,'linewidth',2);
drawnow
---------------------------------------------------------------------------------------------------------------------------------
Thanks in advance, if anymore information is desired please ask away.
The PID controller h
7 个评论
Walter Roberson
2021-3-11
Sorry, I have no idea how the output desired is intended to connect to your code. You do have a K in your code but it is
K = parms(1)+ parms(2)/s + parms(3)*s/(1+0.000001*s)% this is 10^-6
and it is not returned. It is a transfer function, but transfer functions are not any particular value: transfer functions describe a relationship between inputs and outputs. You can talk about the value of a transfer function evaluated at a particular frequency, or the maximum value over a range of frequencies or such things, but not about a transfer function having a definite value.
If the point is just that the transfer function must be between 0 and 1 over a particular range of frequencies, then if we assume that the parameters are non-negative, you get
K = ((P1 + 1000000*P3)*s^2 + (1000000*P1 + P2)*s + 1000000*P2)/(s^2 + 1000000*s)
and for non-negative P1, P2, P3, then the numerator is always positive, and restricting it to the range 0 to 1 can be done by requring that the numerator <= denominator. Solving for equality we get
((P1 + 1000000*P3)*s^2 + (1000000*P1 + P2)*s + 1000000*P2) == (s^2 + 1000000*s)
((P1 + 1000000*P3)*s^2 + (1000000*P1 + P2)*s + 1000000*P2) - (s^2 + 1000000*s)
(P1 + 1000000*P3 - 1)*s^2 + (1000000*P1 + P2 - 1000000)*s + 1000000*P2
Really this is <= 0 rather than a == 0 .
Maximize:
syms P1 P2 P3 s
eqn = (P1 + 1000000*P3 - 1)*s^2 + (1000000*P1 + P2 - 1000000)*s + 1000000*P2
scrit = solve(diff(eqn,s), s)
scurl = subs(diff(eqn,s,s),s,scrit)
which gives
2*P1 + 2000000*P3 - 2
and that needs to be negative for scrit to be discussing a maxima, and the boundary for that is P3 = (1-P1)/1000000. This pretty much tells you that the s^2 coefficient here needs to be negative for the K to be guaranteed bounded to the proper range for all s.
However... if you are only operating over a particular range of s values then you might be able to achieve the desired limits even if the limit would not hold for a wider range of s values.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!