How can I autotune some parameters based on a Simulink model?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
Target: Tune a PI controller (Kp and Ki parameters) based on a desired behaviour (y_desired). Problem: The tuned parameters differ too much from the desired ones. The number of iterations is way lower than the one 'MaxIter'.
Working files: 1. simulation_model.mdl 2. autotune.m
The simulation model has a "To File" block in order to compare with the autotune file. This "To File" block saves data as "simulation_datafile.mat" and the used variable name is "simulation_data".
File: autotune.m function [Kp,Ki] = autotune
% Desired plant. PI tuning is done to achieve this behavoiur.
ghi = 1/sqrt(2);
wn = 4/1;
G_ideal = tf(wn^2,[1 2*ghi*wn wn^2]);
[y_desired,t_desired]=step(G_ideal,0:0.1:15);
% Configure lsqcurvefit
i=0; % Iteration counter
pi0 = [100 100]; % Set initial values for the PI controller
options = optimset('Display','off','MaxIter',1e3); %lsqcurvefit
lower_boundary = [0 0]; % PI values have to be positive values
upper_boundary = [1 1].*1e10;
pi = lsqcurvefit(@model, pi0,t_desired, y_desired, lower_boundary ,upper_boundary , options);
Kp = pi(1);
Ki = pi(2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function F = model(pi, t_desired) % Why does t_desired need to be here?
Kp = pi(1);
Ki = pi(2);
i=i+1;
sim('simulation_model','SrcWorkspace','Current'); % Run model
load simulation_datafile.mat;
t_sim = simulation_data(1,:);
y_sim = simulation_data(2,:);
% Plot result - Show evolution
figure (1);
clf;
hold on;
grid on;
title (['iter: ', num2str(i), ' Kp: ', num2str(Kp), ' Ki: ', num2str(Ki)]);
plot(t_sim,y_sim,'-b',t_desired,y_desired,'-r')
F = y_desired- y_sim'; % Target function
end
end
Thanks in advance.
Jon Kepa
댓글 수: 0
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!