MPCmove with function and pscad

조회 수: 1 (최근 30일)
영민 공
영민 공 2023년 7월 22일
답변: Shushant 2023년 8월 1일
I want mpc with pscad, so i want make mpcmove function
function [u,y] = mpcmove_test(r,y)
num=[1 1];
den=[1 1 2];
[A,B,C,D] = tf2ss(num,den);
sys = ss(A,B,C,D);
Ts = 0.05;
p = 10;
m = 10;
% r = 1;
% y = 0;
mpc_contrller = mpc(sys,Ts,p,m);
state = mpcstate(mpc_contrller);
% for i = 1:100
[u] = mpcmove(mpc_contrller,state,y,r);
y = C*state.plant;
% y_p(i,1) = y;
% end
% plot(y_p)
this is my function code, but when i run this fuction with pscad, It can't follow the reference. This means that the value will continue to rise and never stop. I think pscad run this function.
But when i run this code with loop, It works well, why first code works different?
num=[1 1];
den=[1 1 2];
[A,B,C,D] = tf2ss(num,den);
sys = ss(A,B,C,D);
Ts = 0.05;
p = 10;
m = 10;
r = 1;
y = 0;
mpc_contrller = mpc(sys,Ts,p,m);
state = mpcstate(mpc_contrller);
for i = 1:100
[u] = mpcmove(mpc_contrller,state,y,r);
y = C*state.plant;
y_p(i,1) = y;
end
plot(y_p)

답변 (1개)

Shushant
Shushant 2023년 8월 1일
I understand that when you try to execute two identical pieces of code, one using a regular loop and the other utilizing a function and using “pscad” but there is disparity in outputs. The difference in outputs is due to the function "mpcmove".
Kindly refer to the following thread to get a better understanding of the issue and possible workaround.
Thank you,
Shushant

카테고리

Help CenterFile Exchange에서 Model Predictive Control Toolbox에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by