Azzera filtri
Azzera filtri

How can I autotune some parameters based on a Simulink model?

3 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

Ryan G
Ryan G il 16 Ott 2012
Modificato: Ryan G il 16 Ott 2012
Simulink already has a PID Autotuning capability. Since it looks like you are tuning to a step this should be easy.
You can use simulink design optimization to input the signal and have it tune the gains to match.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by