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