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?
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.
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 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.
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?
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.