I want to add external measured disturbances to my model (MATLAB/Simulink interface) in the form of discrete points over a period of time in the predicted horizon. So, I made the following modifications to the ffct in probfct.c.
/** System function f(t,x,u,p,userparam) ------------------------------------ **/voidffct(typeRNum*out,ctypeRNumt,ctypeRNum*x,ctypeRNum*u,ctypeRNum*p,typeUSERPARAM*userparam){ctypeRNum*Sys=(ctypeRNum*)userparam;/***omission part***/ctypeRNumt0=Sys[32];typeRNum*Wf=&Sys[33];typeIntindex=(int)floor((t-t0)/0.02+0.00001);typeRNumFw=Wf[index];/***omission part***/}
I understand that the GRAMPC already passes t0+t to the ffct , so I made the modifications above, and it indeed works well. But I have a few points of confusion.
(1) I understand that GRAMPC formulates the Optimal Control Problem as a Two-Point Boundary Value Problem, and solves it accordingly. In the process of integrating the dynamic equations in forward time, the sampling time is set to Thor/(Nhor-1). So, I'm wondering why is "typeInt index = (int)floor( (t-t0) / dt + 0.00001)" but not "typeInt index = (int)floor( (t-t0) / (Thor/(Nhor-1)) + 0.00001)" ?
(2) The magnitude of the inputs for the dynamical equation is 10^6, but the output is just 10. I haven't done anything extra, yet the results seem reasonable. Should I be doing anything more about this?
Best regards,
Ethan.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
(1): I would expect Thor/(Nhor-1) but you have programmed it. What are the specific values of Thor, Nhor and dt in your case? The MHE example in GRAMPC chooses them in such a way that the sampling time along the prediction horizon corresponds to the sampling time of the controller. This definitely simplifies such tasks where you want to take predicted values into account. Otherwise, setting the values in userparam before calling grampc_run is just a little bit more complex.
(2): You can try the scaling options of GRAMPC to see whether it accelerates the convergence. However, if all control variables are in this order of magnitude, it may also work well without specific scaling. You should also check whether the step sizes of the line search are typically between LineSearchMin and LineSearchMax and not always at one of the bounds. Adapting these limits could then be an alternative to scaling.
Best regards,
Andreas Völz
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Dear Andreas Völz
I feel so sorry for the delayed response as I have been occupied with other work recently.
(1) I don't understand "The MHE example in GRAMPC chooses them in such a way that the sampling time along the prediction horizon corresponds to the sampling time of the controller. " Because, in the MHE example, it seems like "typeInt index" is also set to be " (int)floor( (t-t0) / dt + 0.00001)" . That's why I use "typeInt index = (int)floor( (t-t0) / dt + 0.00001)" in my model first. In my model, Thor=6, Nhor=61, dt=0.02, and the disturbance along the prediction horizon are passd via userparam to the problem functions at each time step .
(2) As for the scaling problem, I seem to have no experience with it. Could you please provide me with relevant tutorials or examples so I can quickly understand this method?
Best regards,
Ethan.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In this case GRAMPC discretizes the horizon Thor=6 with Nhor=61 sampling points, which means they have a spacing of 6/(61-1) = 0.1, that is, grampc.rws.t is the vector
[0, 0.1, 0.2, 0.3, ..., 5.7, 5.8, 5.9, 6.0]
Now, it would be sufficient to pass the predicted disturbances at these 61 sampling points to GRAMPC, in which case you would need (t-t0)/0.1 to compute the index into the userparam array. On the other hand, your MPC is running with the sampling time dt=0.02, meaning that every 0.02 the problem is solved and the first part of the optimal control is executed. If you predict the disturbances with the same sampling time along the horizon, your userparam array would have 6/0.02+1=301 elements and you would need (t-t0)/0.02 to compute the respective index.
(2) As for the scaling problem, I seem to have no experience with it. Could you please provide me with relevant tutorials or examples so I can quickly understand this method?
If you are satisfied with the performance of the MPC, there is no need to investigate scaling. But if convergence is slow and you need a lot of iterations, then scaling could be one of the options to test. It is described in Section 4.6 of the manual and used in the Reactor_CSTR example, see Section 6.3 and particularly equation (6.17) in the manual.
Best regards,
Andreas Völz
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi everyone,
I want to add external measured disturbances to my model (MATLAB/Simulink interface) in the form of discrete points over a period of time in the predicted horizon. So, I made the following modifications to the ffct in probfct.c.
I understand that the GRAMPC already passes t0+t to the ffct , so I made the modifications above, and it indeed works well. But I have a few points of confusion.
(1) I understand that GRAMPC formulates the Optimal Control Problem as a Two-Point Boundary Value Problem, and solves it accordingly. In the process of integrating the dynamic equations in forward time, the sampling time is set to Thor/(Nhor-1). So, I'm wondering why is "typeInt index = (int)floor( (t-t0) / dt + 0.00001)" but not "typeInt index = (int)floor( (t-t0) / (Thor/(Nhor-1)) + 0.00001)" ?
(2) The magnitude of the inputs for the dynamical equation is 10^6, but the output is just 10. I haven't done anything extra, yet the results seem reasonable. Should I be doing anything more about this?
Best regards,
Ethan.
Dear Ethan,
(1): I would expect Thor/(Nhor-1) but you have programmed it. What are the specific values of Thor, Nhor and dt in your case? The MHE example in GRAMPC chooses them in such a way that the sampling time along the prediction horizon corresponds to the sampling time of the controller. This definitely simplifies such tasks where you want to take predicted values into account. Otherwise, setting the values in userparam before calling grampc_run is just a little bit more complex.
(2): You can try the scaling options of GRAMPC to see whether it accelerates the convergence. However, if all control variables are in this order of magnitude, it may also work well without specific scaling. You should also check whether the step sizes of the line search are typically between LineSearchMin and LineSearchMax and not always at one of the bounds. Adapting these limits could then be an alternative to scaling.
Best regards,
Andreas Völz
Dear Andreas Völz
I feel so sorry for the delayed response as I have been occupied with other work recently.
(1) I don't understand "The MHE example in GRAMPC chooses them in such a way that the sampling time along the prediction horizon corresponds to the sampling time of the controller. " Because, in the MHE example, it seems like "typeInt index" is also set to be " (int)floor( (t-t0) / dt + 0.00001)" . That's why I use "typeInt index = (int)floor( (t-t0) / dt + 0.00001)" in my model first. In my model, Thor=6, Nhor=61, dt=0.02, and the disturbance along the prediction horizon are passd via userparam to the problem functions at each time step .
(2) As for the scaling problem, I seem to have no experience with it. Could you please provide me with relevant tutorials or examples so I can quickly understand this method?
Best regards,
Ethan.
Dear Ethan,
In this case GRAMPC discretizes the horizon Thor=6 with Nhor=61 sampling points, which means they have a spacing of 6/(61-1) = 0.1, that is, grampc.rws.t is the vector
Now, it would be sufficient to pass the predicted disturbances at these 61 sampling points to GRAMPC, in which case you would need (t-t0)/0.1 to compute the index into the userparam array. On the other hand, your MPC is running with the sampling time dt=0.02, meaning that every 0.02 the problem is solved and the first part of the optimal control is executed. If you predict the disturbances with the same sampling time along the horizon, your userparam array would have 6/0.02+1=301 elements and you would need (t-t0)/0.02 to compute the respective index.
If you are satisfied with the performance of the MPC, there is no need to investigate scaling. But if convergence is slow and you need a lot of iterations, then scaling could be one of the options to test. It is described in Section 4.6 of the manual and used in the Reactor_CSTR example, see Section 6.3 and particularly equation (6.17) in the manual.
Best regards,
Andreas Völz