Hello. This Script allows me to simulate a PI control system but it should do it automatically, it is not doing it, I have to go to the Simulink diagram and change the PI values. In this Matlab script what do I have wrong? It doesn't change the PI values automatically. Thanks.
tg = xpc;
tg_P = getparamid(tg, 'PI Controller', 'P')
tg_I = getparamid(tg, 'PI Controller', 'I')
y = []; s = []; e = []; flag = 0; p=[1,0.5,0.1]; i=[0.01,0.05,0.1];
for k = 1 : 1 : 3
P=p(k);
setparam(tg,tg_P,P); % Set damping factor (Gain1/Gain)
for j = 1 : 1 : 3 % Loop over damping factor z
I=i(j);
setparam(tg,tg_I,I); % Set damping factor (Gain1/Gain)
start(tg); % Start model execution
pause(1.1*tg.StopTime);
outp = tg.OutputLog; % Upload output and
y = [y, outp(:, 1)]; % store in a matrix
s = [s, outp(:, 2)];
e = [e, outp(:, 3)];
t = tg.time; % Upload time vector
consigna=outp(:, 1);
posicion=outp(:, 2);
error=outp(:, 3);
SumErr=sum(abs(error));
save (['Control PI_',num2str(P),'_',num2str(I),'.mat'],'consigna','posicion','error','P','I','SumErr');
plot(t, outp(:, 1),'b',t, outp(:,2),'r'); % Plot data for current run
set(gca, 'XLim', [t(1), t(end)], 'YLim', [-50, 400]);
title(['DC Motor: Proportional Gain = ', num2str(P),' Integral Gain =',num2str(I)]);
xlabel('Time'); ylabel('Output');
drawnow;
saveas(gcf, ['P=', num2str(P),'_I=',num2str(I),'.fig'], 'fig') % Guarda las figuras
end
end
save Total.mat

댓글 수: 1

Walter Roberson
Walter Roberson 2022년 3월 3일
Doesn't setparam require that you set to character vectors, not numeric values?

댓글을 달려면 로그인하십시오.

답변 (1개)

Ruben Dario Ramirez Serna
Ruben Dario Ramirez Serna 2022년 3월 3일
편집: Ruben Dario Ramirez Serna 2022년 3월 3일

0 개 추천

I'm sorry but I don't understand your question, you ask me if Setparam is ok?

댓글 수: 3

Walter Roberson
Walter Roberson 2022년 3월 3일
I was getting confused between two functions with similar names.
You are using xpc which is Simulink Real-Time. For that product, using setparam is the correct way to set tunable parameters.
I was thinking about Simulink models not being used for real-time. When xpc is not being used, then set_param is the function used, and that function requires text values instead of numeric values. Very similar function name, different calling sequence.
I work in the control of a DC motor in real time by Simulink Real Time (Host-Target), the Script that I propose must make the automatic change of the PI control: P=1,I=0.01 after P=1,P=0.05 until P=0.1,I=0.1 but it is not doing it
Walter Roberson
Walter Roberson 2022년 3월 3일
Unfortunately, I do not have experience with Simulink Real-Time.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Multicore Processor Targets에 대해 자세히 알아보기

댓글:

2022년 3월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by