OCP solver must be called several times to reach a good solution

Hi :wave:

I’m using the acados python wrapper to generate a trajectory for a quadrotor. I’m only interested in reaching a certain end state, so previously when I was using ACADO I used a linear running cost function only for the y axis and the angular velocities (to keep them near 0) and a linear end cost function for the full final requested state.

Now I’m transitioning to acados and I’m trying to do the same thing. I have already managed to get a very similar trajectory, but to do it I had to call “ocp_solver.solve()” at least 3 times to get a good solution. If only called once, the solution is almost not moving from the initial state. If called twice, the solution becomes 90% closer to the good one. After the third call the solutioin is converged.

While this behavior is something I can cope with, I am wondering why is this happening. Is there any variable that I can set for requesting a minimum convergence when calling the solver?

PS: If I try a different running cost that affects all the states and not only the y axis and the angular rates, the system is able to converge with only one run.

Thanks for the help! :pray:


are you using the SQP or SQP_RTI solver?
SQP_RTI latter just does one SQP iteration, so this behavior is expected.
SQP solves the OCP up to a certain tolerance, that can be changed.

Maybe check these options: https://docs.acados.org/python_api/index.html#acados_template.acados_ocp.AcadosOcpOptions

and print the solver stats: https://docs.acados.org/python_api/index.html#acados_template.acados_ocp_solver.AcadosOcpSolver.print_statistics


After finding this question, I realized that the ‘SQP_RTI’ solver I was using is set to do only one iteration by definition. Changing to the ‘SQP’ solver fixes this issue and ensures convergence in my case. My bad to not fully read the paper before using the toolkit :sweat_smile:

Hi Jonathan,

I think you answered just at the same time as I found the problem. Thanks for the help!