How can I limit the PID controller output to a constraint of 0 to 1 for genetic algorithm?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
My real system (buck converter) can only take an input of 0 to 1 (duty ratio) from the PID controller output for the circuit due to it simulating reality (can't have negative or above 1 duty ratio in reality).
How can I constrain the PID controller output so that the genetic algorithm only looks at a controller output of 0 to 1 instead of -inf to inf?
--------------------------------------Start of genetic algorithm------------------------------------
clear all, close all, clc
dt = 0.000001; % this is 10^-6
PopSize = 50 % was 500
MaxGenerations = 15; %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);
--------------------------------------Start of next tab of 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); % line to potenially change for different TFs
Q = [1];
R = 0.00005; % 00000 change these to effect rise, overshoot, settling time?
J = dt*sum(Q*(1-y(:)).^2 + R*u(:).^2)
step(5*ClosedLoop,t)
h = findobj(gcf,'type','line');
set(h,'linewidth',2);
drawnow
--------------------------------------Start of next tab of live script-----------------------------------
function [state, options,optchanged] = myfun(options,state,flag)
persistent history
persistent cost
optchanged = false;
switch flag
case 'init'
history(:,:,1) = state.Population;
cost(:,1) = state.Score;
case {'iter','interrupt'}
ss = size(history,3);
history(:,:,ss+1) = state.Population;
cost(:,ss+1) = state.Score;
case 'done'
ss = size(history,3);
history(:,:,ss+1) = state.Population;
cost(:,ss+1) = state.Score;
save history.mat history cost
end
--------------------------------------end of scripts---------------------------------------------------
0 Kommentare
Antworten (0)
Communitys
Weitere Antworten in Power Electronics Control
Siehe auch
Kategorien
Mehr zu Genetic Algorithm finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!