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.
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!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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!
Hi Sophie,
I don't see anything wrong with your approach. If I modify the grampc_run_Sfct.c
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
it results in Simulink crashing because of an access violation.
Felix
Hello Felix,
thank you very much for your fast response. My primary problem really stems from the worng dimension of p. Thanks!