Change model parameters

Hello,
I am using the Matlab interface.
Once I’ve generated C code, can I change model parameters in the C interface?
In my case, I’ve created a simple quadrotor model. In order to use my MPC controller for more than one quadrotor. I want to change some parameters like the mass directly in the C interface. Thus, I don’t have to regenerate C code from Matlab interface.
Can I do that?
Thanks in advance

In the generated C code, there is the function:
int <model_name>_acados_update_params(nlp_solver_capsule * capsule, int stage, double *p, int np)
which is there exactly for this purpose.

Cheers!

Hi All,

I am little bit confused about the way one can use
int <model_name>_acados_update_params(nlp_solver_capsule * capsule, int stage, double *p, int np)

I have a very simple discrete dynamics:
x[t+1]=x[t]+delta_t*u

where x is the state of the system, u is the control input and delta_t is the time step. I want to change delta_t in the generated c++ code… Can one use this function?
I have seen that this parameter is also needed to be updated in <model_name>_dyn_disc_phi_fun_jac and <model_name>__dyn_disc_phi_fun and <model_name>_dyn_disc_phi_fun_jac_hess… But, does all of these can be updated automatically by using <model_name>_acados_update_params?

Thanks a lot :slight_smile:

Hi @sina

Yes, <model_name>_acados_update_params is meant to update the parameters for all external functions. Specifically, for the ones for discrete dynamics, it is done here:

Thank you very much for your reply. So, if I understood it correctly, I need to re-implement the discr_dyn_phi_fun_jac_ut_xt_hess, discr_dyn_phi_fun and discr_dyn_phi_fun_jac_ut_xt functions myself and pass it to the system and there is no way to update the already generated functions in C++?

Best Regards,
Sina

If you use delta_t as parameter p, you can use the _acados_update_params function to update these values.

HI FreyJo,

I would also like to change my system dynamics during solving. I’m using nonlinear least square with continuous system, and I aim to simply add an offset that comes from the outside (calculated before each time updating MPC). The offset will be specifically added to the first stage of MPC, so I guess I need to use <model_name>_acados_update_params. However, I cannot find the document of how to using it. Is there any detailed instructions?