I read the section 5.1.2 and 5.1.3 of the documentation and realize the only way to update the userparam is to initialize the grampc at each time step. I can not use the function grampc_setparam_real_vector because userparam does not belong to the GRAMPC parameter structure. Doing initialization of GRAMPC in each time step seems time-consuming. Do I miss something important in the documentation? Looking forward to your reply.
Thank you.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
from reading sections 5.1.2 and 5.1.3 in the documentation, I infer that your are using GRAMPC directly in C. In this case, note that the grampc structure only stores a pointer to userparam, which is then passed on to each of the problem functions (ffct, dfdx_vec, dfdu_vec, lfct, ...). The user is responsible for memory allocation and deallocation of whatever is behind userparam, for example an array of doubles or a struct with multiple fields. This means that you can simply modify and update the indiviual entries of userparam (even within the problem functions) without having to call a grampc_set...-function or calling grampc_init again.
Please ask if you need further help.
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:
At the very beginning, I was trying to generate C code from simulink models. The problem is that my system tlc does not support non-inlined S-functions. So I leave data ports in simulink models, and directly use GRAMPC after code generation. And then I will learn to write the tlc file to inline the S-functions.
Best regards,
Kexian
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I read the section 5.1.2 and 5.1.3 of the documentation and realize the only way to update the userparam is to initialize the grampc at each time step. I can not use the function grampc_setparam_real_vector because userparam does not belong to the GRAMPC parameter structure. Doing initialization of GRAMPC in each time step seems time-consuming. Do I miss something important in the documentation? Looking forward to your reply.
Thank you.
Dear Kexianshen,
from reading sections 5.1.2 and 5.1.3 in the documentation, I infer that your are using GRAMPC directly in C. In this case, note that the grampc structure only stores a pointer to userparam, which is then passed on to each of the problem functions (ffct, dfdx_vec, dfdu_vec, lfct, ...). The user is responsible for memory allocation and deallocation of whatever is behind userparam, for example an array of doubles or a struct with multiple fields. This means that you can simply modify and update the indiviual entries of userparam (even within the problem functions) without having to call a grampc_set...-function or calling grampc_init again.
Please ask if you need further help.
Best regards,
Andreas Völz
Thanks Andreas, I get it.
At the very beginning, I was trying to generate C code from simulink models. The problem is that my system tlc does not support non-inlined S-functions. So I leave data ports in simulink models, and directly use GRAMPC after code generation. And then I will learn to write the tlc file to inline the S-functions.
Best regards,
Kexian