Acados sampling time setting

Dear all,

I am running the minimal_example_closed_loop.py (pendulum example).
I would like to set a sampling time of 10ms and a prediction horizon of 50 steps.

Time-swise, I am able to set following parameters:
ocp.dims.N
and
ocp.solver_options.tf

The online manual (for python API) at
https://l.facebook.com/l.php?u=https%3A%2F%2Fdocs.acados.org%2Finterfaces%2Findex.html%3Ffbclid%3DIwAR3fZrrAdCnNrYTvHjv1dvl_rUT2V9aiRxsrDApjAGfoBIVEJTruAKS5AUQ%23module-acados_template.acados_ocp&h=AT0Kziu42WLLhgfobXYBwEUEDO1TYcHxJ9GGr5w78-9wmXFyzOIVLvURnoSsiYrT-zuEUAUOZgW8A-J03QwoO3jPz2FQRJ_D7qsqXUIaqG9qfxOXCo51Y02lzqTia5J2_cno6A
states “N - prediction horizon” and “tf - prediction horizon”, which is weird.
From the code it seems that “tf” is the total simulation time.

As indicated above, I would like to log the data (states, input, execution times) in 10ms sampling instances, for a total simulation time of 10 seconds.
Can anyone kindly advise me how to configure the example adequately?

Thank you very much in advance,

Dominik

1 Like

Hi Dominik,

Let me summarize.
You want:

  • N = 50
  • ts = 10ms
  • Tsim = 10 s

In acados you set the total horizon time with ocp.solver_options.tf, as you noticed. Therefore:

  • N = 50
  • ts = tf/N --> tf = N x ts = 50 x 10ms = 0.5
  • Tsim = Nsim x ts --> Nsim = Tsim / ts = 10s / 10 ms = 1000

So, you’ll have to change N and ts, to get your specified horizon and sampling time. Additionally, on line 119 you’ll have to replace N with Nsim, to increase the simulation length to your specified 10 s. For this to work, you’ll also have to replace N with Nsim, where simX and simU is defined. These arrays correspond to your logged data. For the execution times, you can have a look at how they do it for the race_cars example.

Cheers,
Christian

Thank you for your help @Christian, it indeed did the job.

However, another - a very weird problem arised. In the pendulum example simulation using the minimal_example_closed_loop.py script, I found out that the computational time increases with smaller horizon lengths, which is the exact opposite as I expected.

I used the HPIPM solver. Also tried qpOASES, in that case it was even worse.

Does anyone have any idea what may cause this, please?

I would appreciate your help.

PS: @FreyJo @giaf
Dominik

Hey Dominik,

I guess you mean N here and in general, you are right, more shooting nodes should result in longer computation times.
Measuring timings is not trivial and there are a few things to take into account, e.g.:

  • you should always perform multiple executions and take the minimum of the computation times
  • number of iterations might change - time per iteration might be more stable to measure
  • if you fix T and vary N, lower values for N result in more nonlinearity on each shooting node which can might require more iterations.

Maybe you can describe what you did more precisely in a new topic and also show the results.

Cheers,
Jonathan

Thank you @FreyJo ,

yes, I meant N as prediction horizon.
Please, what do you mean by T, sampling time?
Also, can you please clarify if acados natively implements one SQP iteration (as proposed in RTI scheme) or does a full SQP step? Is there a way to set this up in the code?

Dominik

I meant total time that is between the initial and final shooting node, it is called tf in Python.

You can set nlp_solver_type to either SQP, which does solve the OCP up to the tolerances set (respectively it terminates earlier if maximum iteration number is reached or an infeasible QP occurs), or SQP_RTI, which does exactly one SQP iteration.