How to include a model (created by me at Simulink) in Matlab script?

5 vues (au cours des 30 derniers jours)
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)

Réponse acceptée

Paul
Paul le 20 Mai 2023
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 commentaires
jana nassereddine
jana nassereddine le 21 Mai 2023
okay that's great, but the ouput of this is it the same picture I showed it to you? or maybe I should try and see, what do you think?
Paul
Paul le 21 Mai 2023
Modifié(e) : Paul le 22 Mai 2023
Well, the picture showed did not define the output of the system, so I can't say.
I suggest reading the documentation and examples for the MPC toolbox and try to apply that material to the problem of interest.

Connectez-vous pour commenter.

Plus de réponses (1)

Emmanouil Tzorakoleftherakis
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

Catégories

En savoir plus sur Linear Plant Specification dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by