Hi
I am implementing a MPC tracking controller for an hexarotor drone using acados Python interface.
For the moment I tested simple (but dynamically unfeasible) trajectories such as steps in position and the control works fine.
The state is in R^13 (position, attitude in quaternions, linear and angular velocities) while the input is in R^6 (six rotor thrusts). I am using the RTI and NONLINEAR_LS cost.
The reference signal to track is sampled at 100 Hz. The prediction horizon is 1 second with 20 shooting nodes, hence at each control iteration the reference at the current sample is read to compute the tracking error and its next 1 second is downsampled at 20 Hz to fill the prediction horizon reference (I use parameters for this).
I run a Gazebo simulation to which I feed the inputs computed by the MPC, so I don’t use acados to integrate the dynamics to simulate the system (this is done by gazebo) and the software framework I am using implements also state estimation and other components.
When the simulation ends I plot the statistics obtained with ocp_solver.get_stats('time_tot')
for both preparation and feedback phases. An example of the total execution time (preparation+feedback) is as follows
There are some spikes > 7 ms, but the average time is lower (around 2 ms).
What I am doing now to manage the control frequency is (in pseudo code):
Given control period T = 10 ms
for i in range(sim):
solve_mpc()
t_elapsed = get_time_stats()
diff_t = T - t_elapsed
sleep(diff_t)
Since the period T = 10 ms is very conservative, in order to improve the control frequency I could stop the solver after a certain amount of time (say, 5 ms): if it has been able to converge in less time no problem, otherwise some works in literature suggest to use u_k = u_1,k-1.
The questions are:
- How to check if after a certain time the solver has converged and stop it if not?
- Are there better ways to guarantee a fixed (non conservative) frequency for the MPC? Are there better ways to manage deadline miss?
Thanks for replies and suggestions,
Lorenzo