How to include a model (created by me at Simulink) in Matlab script?
5 次查看(过去 30 天)
显示 更早的评论
so I have model predictive controller with a plant model, and I created the plant model using blogs, I couldn't use the state space representation because I have a disturbance acting on the system, so the only way to include it is by making the model with a blocks,
so anyway now i am writing a code for custom state estimation in script, and I need to mention the plant model I have used in this script, but when I write the name of the plant model or the name of the plant model with MPC, an error appears as
"error using mpc, the first input argument of the mpc command must be an LTI object or a structure of models and offsets"
so my question is how to include the model (I have created using block ) into my script?
% Custom State Estimation
ts=0.1;
mpcobj=mpc('plantmodel',ts)
setEstimator(mpcobj,'custom');
xmpc = mpcstate(mpcobj);
A=[1 0;0 1];
B=[0.0936 0.0936 0;0 0.0752 0];
C=[1 0;0 1];
Nc=2;
SOCpbref=75; % (en pourcentage)
SOCliref=85; % (en pourcentage)
t=25; % en seconds
Cmaxpb=22020; % As (Ampersecond)
Cmaxli=6000; % As (Ampersecond)
Ipb=[60 65 70 75 65 60 55 50 50 50 55 60 65 70 75 75 75 75 70 60 60 55 65 60 50]; % en Ampere
Ili=[70 75 80 85 75 70 65 60 60 60 65 70 75 80 85 85 85 85 80 70 70 65 75 70 60]; % en Ampere
Cpb= sum(Ipb)/t;
Cli= sum(Ili)/t;
SOCpb=(Cpb/Cmaxpb);
SOCli=(Cli/Cmaxli);
for t = 0:Nc
y = sys.C*xsys; % plant equations: output
YY(t+1) = y;
xmpc.Plant = [SOCpb, SOCli]; % state estimation
u = mpcmove(mpcobj,xmpc,[],[SOCpbref, SOCliref]); % y is not needed
UU(t+1) = u;
xsys = sys.A*xsys + sys.B*u; % plant equations: next state
end
command window:
Error using mpc
The first input argument of the "mpc" command must be an LTI object or a structure of models and offsets.
Error in customstateestimation (line 3)
mpcobj=mpc('model',ts)
0 个评论
采纳的回答
Paul
2023-5-20
Hi jana,
Can you clarify this statement: "I couldn't use the state space representation because I have a disturbance acting on the system,"
The state space ss object can include all inputs to the system, i.e., control, disturbance, noise, etc.
10 个评论
更多回答(1 个)
Emmanouil Tzorakoleftherakis
2023-5-23
Hi,
Currently you cannot use a Simulink model as prediction model for MPC design. This is something we are working towards for a future release. Since it seems you are designing a linear MPC controller, you could linearize your Simulink model at the desired operating point to get a linear representation, or you could use system identification as well if you are fine with a data-driven model. Here are a couple of examples:
Hope this helps
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Plant Specification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!