Generating Code and updating parameters

Hello everyone,

being new in Acados, I have a two questions concerning the code generation:
I implemented a Tube MPC, where a parameter M for the shape of the Tube at every stage along the prediction horizon is used. Since the AcadosOcpSolver class has a set method, I am updating this parameter with numerical values and then regenerate the code with the updated shape of the tube. Code looks like this:

    # create instance of the AcadosOcpSolver, generates automatically
    acados_ocp_solver = AcadosOcpSolver(ocp, json_file = f"{ocp.code_export_directory}/acados_ocp_{}.json")
    for i in range(1,N+1):
        param_i = M_vec_i  # flattened, numerical parameter M at stage i
        acados_ocp_solver.set(i, "p", param_i) 

    # generate and compile code again
    acados_ocp_solver.generate(ocp, json_file = f"{ocp.code_export_directory}/acados_ocp_{}.json")

I am searching for the values of the parameter in the generated code to verify if they have been implemented correctly, but I am not able to track where the parameter has been placed, especially for each stage individually. Any hint how to find it in the generated code (if my approach is actually ok)?

Also, any new code generation removes the last generated code (if placed at the same location), so that previous changes to the c-code get lost. How would the workflow look like to minimize this during development?

Thanks for any help

Hi Daniel,

I think there is some confusion.
The acados_ocp_solver is generated purely based on the information given in acados_ocp.
The acados_ocp_solver.set() function is only meant to be used to interact with the solver, not with acados_ocp.
You can only set stage wise parameter values in an existing solver currently. which you are doing correctly though in your snippet.

Also, .generate() and .build() are classmethods and supposed to be used like here: acados/ at master · acados/acados · GitHub

I hope this clarifies it!

1 Like