alexliniger / MPCC

Model Predictive Contouring Controller (MPCC) for Autonomous Racing
Apache License 2.0
1.29k stars 364 forks source link

discrete model #44

Closed DreamonZhu closed 3 years ago

DreamonZhu commented 3 years ago

Hi, everyone, When discretizing the dynamic model of the car in code of C++ version, Tayloy series expansion had first been applied to get the linearized equation \dot (x) = A x + B u + g. This is the way we often see to linearize the non-linear funnction. Then in some books, "\dot x = [x(k+1) - x(k)] / T" was used to get disctretize the model, which was obviously different from what had been done in C++ code .So I am confuzed about why the matrix exponetial of A, B and g was obtained to get the discretized model? So could anyone explain how to derive it. https://github.com/alexliniger/MPCC/blob/3ec7805e7a176c57250c1a414a6d2b871e472d74/C%2B%2B/Model/model.cpp#L291 Thank you.

alexliniger commented 3 years ago

I am afraid that this goes a bit beyond what I can explain here.

Generally I used an approach that is more common in linear MPC, first you linearize the system and second you discretize it. There are different ways to discretize continuous dynamics, normally the involve integrators, the simplest is euler forward x_k+1 = x_k + Ts*(A x_k + B u_k). You can to better than that by using better integrators, for linear systems the best thing you can do is the matrix exponential which is the exact integration of the linear model over one time step.

There is also the more standard NMPC approach where your first discretize (for example with an euler forward or RK4 integrator) and then you find a linear approximation of this constraint. This is similar to what I did in the fullsized branch.

Best, Alex