How to pass external time-varying parameters to nonlinear MPC models?

I have now established a MIMO nonlinear mpc model using the mpc toolbox, and my state function requires external input of parameters, which are time-varying and known. I don't know how to pass external variable parameters to a state function ,What should I do?
As far as I know, 'options. Parameters' can only be transferred to a fixed value, like this:
...
demand = 2000;
supply = 1000;
nloptions = nlmpcmoveopt;
nloptions.Parameters = {demand, supply};
x0=[0;80;50;60;40;50;29;70;40];
u0=[80;80;80;80;80;80;80;80];
[~,~,Info] = nlmpcmove(nlobj,x0,u0,[],[],nloptions);
...
And if I have the following requirements, how should I achieve them?
The prediction time domain and control time domain are both 5, and within these 5 control intervals, the external parameter demands of the state function are [2000 3000 4000 3000 1000]
If you follow the above code, the incoming demand remains unchanged

 채택된 답변

Emmanouil Tzorakoleftherakis
Emmanouil Tzorakoleftherakis 2023년 5월 23일
편집: Emmanouil Tzorakoleftherakis 2023년 5월 24일

1 개 추천

Hello,
There are two ways of doing this:
1) With Nonlinear MPC, you can set your time-varying parameters as measured disturbances and provide them at runtime. See an example here. In your case, pay attention to the dimensions of the MD signal - you should provide the entire vector if you want 'previewing' meaning that each element in the vector will correspond to a specific time step
2) Use linear time-varying MPC and provide a sequence of A,B,C,D matrices for your entire horizon. Each set of matrices will be calculated based on the values you want. See a couple of examples here:
Hope this helps

댓글 수: 12

Thank you for your ideas, but I have some questions about the method you provided:
I understand that multi-level nonlinear MPC can achieve cost and constraint stage control, but I have not found a method to control the input parameters of my state model in stages. 'Stages' does not include' StateFcn '.
For my nonlinear MPC model, costs and constraints remain constant, while the state model is stage changing because the state model has an external input parameter that changes during the stage.
I really hope to receive your reply. It would be even better if you could provide a simple example.
Apologies, I misread your question - I updated my answer above.
c
c 2023년 5월 25일
편집: c 2023년 5월 25일
Sorry, I may have to take some more of your time.
For method 1, I understand that "measured disturbances" may only be for state x, but not for the external input parameters of the state model (I may have misunderstood).
For method 2, my state model is a complex nonlinear model (it is difficult to write A and B matrices), I don't know if linear time-varying mpc is applicable, and I see that the examples given above are all using simulink, I want to know if there is any example using pure code.
I will describe my state model again:
function xplus = FluidQueueStateFcn(x, u, D1, D2)
...
end
where x is the state variable and u is the control variable.
D1 and D2 are external input parameters, D1 is a phase change parameter, while D2 is a fixed value.
My problem now is that although I now know the value of the parameter D1 at some time in the future (eg at 5 time steps in the future D1=[2000 3000 4000 3000 1000]), I don't know how I should pass in that parameter so that it will change automatically at each stage.(Perhaps it can be interpreted as the state model changing at each stage? I'm not sure.)
(I probably shouldn't pass in the model parameters as above, just for the sake of description)
I hope my description is clear.
I hope to get your reply, thanks!
Measured disturbance is not for states only, it is primarily for 'input disturbances'. But inputs are something you can manipulate as you see fit in your application. So you can consider the parameters you want to pass as inputs and pass them in as disturbances. If you do that with "previewing", these parameters will change at each step/stage.
Also, for linear time varying MPC, the first example above uses just MATLAB implementation which is close to what you would need to do. You basically need to linearize your model and compute a sequence of A/B/C/D matrices for each step in your prediction horizon. That way you can use different parameter value for each A/B/C/D calculation as needed.
Hope this helps
I really appreciate you taking the time to explain these contents!
I think I understand what you mean and have implemented it, but since I am not very familiar with using the MPC toolbox, I cannot guarantee that my code will achieve the results I want. I also hope you can help me see if I should write this way:
I only showed the local parts of the main function and state function, The state function has three external input variables, one is stage changing (D1), and two are invariant (D2, S1)
% ...
% ...
% Establish nlmpc model
% 9 states, 9 outputs, 8 input variables, 1 input disturbance
nx = 9;
ny = 9;
nu = 8;
nlobj = nlmpc(nx,ny,'MV',[1 2 3 4 5 6 7 8],'MD',9);
% Set model parameters
Ts = 120;
p = 15;
nlobj.Ts = Ts;
nlobj.PredictionHorizon = p;
nlobj.ControlHorizon = p;
%%%%%%%%%
% The definitions of state function, cost function,
% and constraint function are omitted here
%%%%%%%%%
D1 = [5500 4900 4500 4500 4500 4300 4000 4000 3000 3500 3500 3700 4000 4000 3700];
D2 = 500;
S1 = 0.1;
params = {[D2,S1]};
nlobj.Model.NumberOfParameters = length(params);
% Initial state and feasible solution
x0 = [0;80;50;60;40;50;29;70;40];
u0 = [80;80;80;80;80;80;80;80];
validateFcns(nlobj,x0,u0,D1(1),params)
nloptions = nlmpcmoveopt;
nloptions.Parameters = params;
md = D1'; % md is the column vector
tic
[~,~,Info] = nlmpcmove(nlobj,x0,u0,[],md,nloptions);
toc
Here is my state function
function xplus = FluidQueueStateFcn(x,u,p)
vlim = u(1:8);
D1 = u(9); % external input time-varying variables
D2 = p(1);
S1 = p(2);
% ...
end
Once again, my thanks!
Looks good at first glance! Is the simulation running without errors?
No error reported, it can run normally and obtain results, but for different initial feasible solutions (u0 in the above code), the final results differ significantly. Is this normal?
MPC is optimization-based so this shouldn't come as a surprise. If you have a good initial guess, better use that as a starting point.
Okay, I understand. Thank you very much for all your replies in the past few days. Best wishes!
c
c 2023년 5월 27일
편집: c 2023년 5월 27일
Dear @Emmanouil Tzorakoleftherakis , I'm sorry to bother you again
Oops, I've run into two more tricky problems.
Problem 1. I got the optimal solution (Info) by the following code.
[~,~,Info] = nlmpcmove(nlobj,x0,u0,[],md,nloptions);
Then I got the optimal input (Info.MVopt) and the corresponding state (Info.Xopt). I tried to derive the state for some time in the future by the obtained Info.MVopt and my state function, but the result I derive is quite different from the result Info.Xopt outputted by MPC toolbox, I don't know what causes this.
Problem 2. For some given initial solution u0, I cannot get the correct result.
x0 = [0;80;50;60;40;50;29;70;40];
u0 = 90*ones(8, 1);
the result obtained is shown below (both input u and state x are always equal to the initial value), with 8 inputs on the left and 9 states on the right. I am not sure of the cause of this phenomenon.
(I checked Info.Iterations=1, which is obviously not reasonable)
Thanks in advance for your answer!
Can you please post these in a separate thread? That way they will be more discoverable is someone has similar questions. Also, please clarify what you mean when you say "I tried to derive the state for some time in the future by the obtained Info.MVopt and my state function". Do you mean you integrated your state function with, e.g., ode45 separately? Did you use the appropriate integration step?
Thanks
Okay, I'll do that.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Controller Creation에 대해 자세히 알아보기

제품

릴리스

R2018b

질문:

c
c
2023년 5월 19일

댓글:

c
c
2023년 5월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by