Thank you so much for your response! I am trying to implement a gaussian process MPC (GPMPC) for a 2D quadrotor (vertical plane). This has 6 states, with 2 inputs, with input and state constraints. It works, but its just really slow. Generally, I have been limiting myself to a control frequency of 10 Hz with a horizon of 1 second (10 steps), but even this takes over a second to compute each step, which is nowhere close to realtime. I’ve noticed now this is mostly due to the large number of kernel points I have been using. I don’t require realtime, but it would be nice if it wasn’t so slow, and additionally the fact that its so slow makes me think I am doing something wrong.
For just nonlinear MPC on the quadrotor (no gaussian process) on a stabilization task (moving from rest at one point to a hover at another), changing the integration from using a casadi integrator (cvodes or rk) into just a custom RK gave me a 10-20x speed up (still multiple shooting formulation)! I essentially discretized my CT dynamics using
X = cs.SX.sym('X', n)
U = cs.SX.sym('U', m)
# Runge-Kutta 4 integration
k1 = f(X, U)
k2 = f(X+dt/2*k1, U)
k3 = f(X+dt/2*k2, U)
k4 = f(X+dt*k3, U)
x_next = X + dt/6*(k1+2*k2+2*k3+k4)
rk_dyn = cs.Function('rk_f', [X, U], [x_next], ['x0', 'p'], ['xf'])
which is similar to what is done in the multiple_shooting link you sent.
Unfortunately, this doesn't really help my GPMPC application. Upon further exploration, I think the problem lives in just evaluating the hessian and jacobians of the GP. Using anything more than say 50 kernel points seems to result in long (very not real time) computation times, and the approximations I have been trying to use of the GP result in poor performance due to the sensitivity of the state to the inputs (the quad we are simulating has a very small inertia, so small input differences lead to pretty large angular accelerations). I’m not really sure how to debug casadi and understand what is causing the hessian and jacobian calculations to be so slow. Do you know how I might be able to debug this further? I know it uses autodiff, but maybe if I supplied analytical expressions for them it could be faster?
Next, I tried implementing a direct collocation method for the nonlinear mpc. I chose to implement both a Hermite-simpson Collocation (compressed and separated forms). I used the following resources (for others looking into this):
Rawlings et al. Model Predictive Control. Sec 8.5.3
Biegler. Nonlinear Programming: Concepts, Algorithms, and Applications to Chemical Processes. Ch. 10.2
Betts. (2010). Practical Methods for optimal Control and Estimation using nonlinear programming. Sec 3.5 and 4.6
Kelly. (2017). An introduction to Trajectory Optimization https://epubs.siam.org/doi/pdf/10.1137/16M1062569
Rao. A SURVEY OF NUMERICAL METHODS FOR OPTIMAL CONTROL. http://vdol.mae.ufl.edu/ConferencePublications/trajectorySurveyAAS.pdf
Tedrakes book http://underactuated.mit.edu/trajopt.html
Good course notes https://mec560sbu.github.io/2016/09/30/direct_collocation/
Casadi’s Example Pack https://github.com/casadi/casadi/blob/master/docs/examples/python/direct_collocation.py
I found Bett's book to be the most understandable. Also, for others seeing this who don't know anything about direct collocation (like me), I had trouble understanding exactly how the direct_collocation.py casadi example worked. Essentially, they are interpolating using lagrange polynomials at Legendre-Gauss interpolation points (See the Biegler book, table 10.1). This is a special form of polynomial interpolation using orthogonal polynomials. This selection of interpolation allows for more accurate, and potentially exact, approximation, without adding too much complexity. I chose to use the hermite-simpson method because its simpler.
However, when I implemented this, I found the solutions to go unstable really quickly, and I could only get half decent results if I increased my control frequency to higher values (like 100 Hz or more, still with a 1sec+ time horizon), but would take a second or longer to solve each iteration. Is this something people see often, or is there some major issue in my direct collocation scheme? The quadrotor we are considering has a very small inertia, and thus tiny differences in the inputs create large angular accelerations (highly unstable).
For my current application, generating C code is a bit overkill, and although ACADOS looks helpful, I don't think we can use it at the moment.
Thanks again!--
Sent from CasADi's user forum at http://forum.casadi.org.
---
You received this message because you are subscribed to the Google Groups "CasADi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to casadi-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/casadi-users/4af0e107-a31f-438f-8c10-3e2625d5dbbcn%40googlegroups.com.