Menu

Updating the entries of grampc.rws in grampc_run_Sfct

2020-05-12
2020-05-14
  • Sophie Grammatikopoulos

    I am trying to implement a MHE in SIMULINK. I have trouble manipulating the entries of grampc.rws in the the code of the s-function grampc_run_Sfct. I understand that this change might not be originally intended, but it would be very beneficial to understand how to update the entries. I already read the thread on updating userparam online and tried a similar primitive attempt for grampc.rws.

    ((typeRNum*) grampc->rws->p)[0] = p0;
    ((typeRNum*) grampc->rws->u)[0] = U0;

    I underand that this atempt is way to simple and I already tried some different approaches, but eventually it all leads to SIMULINK crashing. For the implementation of the MHE I need to be able to update the entries of grampc.rws.u and grampc.rws.p before executing grampc_run(grampc). I would really appreciate some line of code to update the entries. Thank you very much!

     
  • Felix Mesmer

    Felix Mesmer - 2020-05-13

    Hi Sophie,

    I don't see anything wrong with your approach. If I modify the grampc_run_Sfct.c

        ((typeRNum*) grampc->rws->u)[0] = -1.0;
    
        /* run mpc */
        grampc_run(grampc);
    

    this works fine for me. Could you maybe provide the message shown by Simulink on crashing?
    You can also check, that you don't change any values in u and p that are out of bounds.
    I can produce a crash with your code by using an expample without parameters, i.e. dim(p)=0.
    If you then try to change some parameter value

      ((typeRNum*) grampc->rws->p)[0] = -1.0;
    

    it results in Simulink crashing because of an access violation.

    Felix

     
  • Sophie Grammatikopoulos

    Hello Felix,

    thank you very much for your fast response. My primary problem really stems from the worng dimension of p. Thanks!

     

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.