Goodmorning to all,
i'm new with your NMPC solver. I'm working on avehicle longitudinal control and i would ask you if it is possibile to update the userparam variables (in which i stored the vehicle constraints) in runtime during a Simulink simulation.
If yes there already exist an S-function that i can use?
Thanks you for attention,
Giulio
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you want to change the userparam in Simulink at runtime, you need to add an additional input to the provided s-fuction grampc_run_Sfct.c. You can specify the dimensions of this input according to your needs. In the function mdlOutputs you can read the input data from the additional pin and overwrite the userparam data before calling the function grampc_run.
Regards,
Tobias
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Goodmorning Tobias,
thank you for your quick response. I tried your suggestion but I don't understand how i can overwrite the userparam in the mdlOutputs : i have to use some function ?
Howerver i would also ask you if you can clarify me , the difference and the usage of the patameters Thor, dt and Nhor.
thanks you !!!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello Giulio,
just use a for loop to copy the data form the input array into the userparam array. For this purpose, you can use a typecast to get a typeRNum pointer to the userparam memory as it is done in various problem functions in the example folder.
Thor is the prediction horizon, which is internally sampled by Nhor grid points. dt is the sampling time of the MPC. For more details, please refer to the GRAMPC documentation.
Regards,
Tobias
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Tobias,
I'm also trying to modify the userparam at runtime. As you suggested I added an input port but when I try to modify userparam, before grampc_run, using grampc->userparam = new_userparam but Matlab tells me that userparam is a only-read variable. What is wrong? Can you please guide me? Could you post the some line of code?
Thanks for your attention. I’m looking forward to your reply.
Regards,
Andrea
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I haven't worked with the s-functions yet. However, as I see it, you have two options: either you remove the const-qualifier in the line const typeGRAMPC *grampc = (typeGRAMPC *)ssGetPWorkValue(S, 0);
or you modify not the pointer grampc->userparam = ... but the content of it, i.e. something like ((typeRNum*)grampc->userparam)[0] = 2.0;
should work.
Regards,
Andreas
👍
2
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Goodmorning to all,
i'm new with your NMPC solver. I'm working on avehicle longitudinal control and i would ask you if it is possibile to update the userparam variables (in which i stored the vehicle constraints) in runtime during a Simulink simulation.
If yes there already exist an S-function that i can use?
Thanks you for attention,
Giulio
Hello Giulio,
If you want to change the userparam in Simulink at runtime, you need to add an additional input to the provided s-fuction grampc_run_Sfct.c. You can specify the dimensions of this input according to your needs. In the function mdlOutputs you can read the input data from the additional pin and overwrite the userparam data before calling the function grampc_run.
Regards,
Tobias
Goodmorning Tobias,
thank you for your quick response. I tried your suggestion but I don't understand how i can overwrite the userparam in the mdlOutputs : i have to use some function ?
Howerver i would also ask you if you can clarify me , the difference and the usage of the patameters Thor, dt and Nhor.
thanks you !!!
Hello Giulio,
just use a for loop to copy the data form the input array into the userparam array. For this purpose, you can use a typecast to get a typeRNum pointer to the userparam memory as it is done in various problem functions in the example folder.
Thor is the prediction horizon, which is internally sampled by Nhor grid points. dt is the sampling time of the MPC. For more details, please refer to the GRAMPC documentation.
Regards,
Tobias
Hi Tobias,
I'm also trying to modify the userparam at runtime. As you suggested I added an input port but when I try to modify userparam, before
grampc_run
, usinggrampc->userparam = new_userparam
but Matlab tells me that userparam is a only-read variable. What is wrong? Can you please guide me? Could you post the some line of code?Thanks for your attention. I’m looking forward to your reply.
Regards,
Andrea
Hello Andrea,
I haven't worked with the s-functions yet. However, as I see it, you have two options: either you remove the const-qualifier in the line
const typeGRAMPC *grampc = (typeGRAMPC *)ssGetPWorkValue(S, 0);
or you modify not the pointer grampc->userparam = ... but the content of it, i.e. something like
((typeRNum*)grampc->userparam)[0] = 2.0;
should work.
Regards,
Andreas
Hi Andreas,
it worked! Thank you so much
Regards,
Andrea