Menu

Online userparam update

giulio
2019-01-16
2019-02-08
  • giulio

    giulio - 2019-01-16

    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

     
  • Tobias Englert

    Tobias Englert - 2019-01-16

    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

     
  • giulio

    giulio - 2019-01-17

    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 !!!

     
  • Tobias Englert

    Tobias Englert - 2019-01-17

    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

     
  • Andrea Bonanzinga

    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

     
  • Andreas Völz

    Andreas Völz - 2019-02-08

    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

     
    👍
    2
  • Andrea Bonanzinga

    Hi Andreas,
    it worked! Thank you so much

    Regards,
    Andrea

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.