MPC Controller Implementation

1,238 views
Skip to first unread message

Guido Sanchez

unread,
Oct 9, 2015, 3:01:36 PM10/9/15
to CasADi
Hi. I am trying to develop a MPC controller for a Quadcopter model.

I started using an example provided by the mpc-tools-casadi package [1], which develosp a pure casadi MPC controller for a Van der Pol oscillator. I modified that example in order to include setpoints and use the ODE of the quadcopter model. Some strange things happened:

1) If the initial guess on controls u is 0, then the optimal solution is always 0.
2) If I change the horizon of the controller or the Delta discretization parameter, the value where the setpoint stabilizes changes.

The code for the controller is available on [2].

Is there anything wrong with the way I am trying to program this? Any help or advice would be appreciated.

Thanks in advance,

Guido Sanchez

[1] https://hg.cae.wisc.edu/hg/mpc-tools-casadi
[2] https://gist.github.com/gmsanchez/33a594e00fd348b7ed11

Joel Andersson

unread,
Oct 10, 2015, 5:56:08 AM10/10/15
to Guido Sanchez, CasADi

Hi Guido!

Please contract the authors of that package. While I do know the people behind it, I don't know the code in detail.

Joel

--
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/4512bc66-c886-49e0-b79d-51a03028949c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Guido Sanchez

unread,
Oct 10, 2015, 8:28:17 AM10/10/15
to CasADi, sanche...@gmail.com
Joel,

Thanks for the reply. I write to this group because the code is using a pure CasADi implementation, it is similar to the mhe_spring_damper.py example.

When I tried to control simple systems it worked, but when I tried to use a 9 states system or this 12 states system, I started to have problems with the optimization results. For example, if the initial control actions are set to 0, the optimization solution is always 0. But if I change it to around 212, it finds some other solutions.

Thanks in advance,

Guido

Guido Sanchez

unread,
Oct 13, 2015, 4:15:23 PM10/13/15
to CasADi, sanche...@gmail.com
 Joel,

I managed to create two examples using the vdp_multiple_shooting.py example with a very simple ODE where the optimization behaves in a similar way to the example I sent before.

Example 1: Nonlinear controls, the solution is always u=0

https://gist.github.com/gmsanchez/a7bd8cb2a2b14417e043

Example 2: linear controls, the solution is different than 0 and the states reach the setpoints.

https://gist.github.com/gmsanchez/e6d9a3e8dccce18b6fc4

It also works if you set

ode = vertcat([x[1], u*u*u + u, x[0]*x[0] + x[1]*x[1] + u*u])

Is that normal or expected behaviour?


Joel Andersson

unread,
Oct 18, 2015, 7:16:22 AM10/18/15
to CasADi, sanche...@gmail.com
Hi Guido,

I'm sorry but I am not able to answer these questions. It's important that you understand the scope of CasADi: We try to provide tools that simplify the process of solving optimization problems, but it's still the user's responsibility to analyze whether the outputs make sense and to come up with a mathematically sound formulation.

In general, a good starting point for working on this would be to get hold of a book on the topic. I would recommend for example Biegler's Nonlinear Programming (http://epubs.siam.org/doi/book/10.1137/1.9780898719383).

Best regards,
Joel
Reply all
Reply to author
Forward
0 new messages