# How fast does a model has to be for NMPC

**URL:** <https://discourse.julialang.org/t/how-fast-does-a-model-has-to-be-for-nmpc/120694>\
**Category:** Modelling & Simulations\
**Tags:** question, package, modelpredictivecontr\
**Created:** [September 29, 2024, 7:43pm UTC](https://discourse.julialang.org/t/how-fast-does-a-model-has-to-be-for-nmpc/120694 "2024-09-29T19:43:35Z")\
**Posts on this page:** 5\
**Page:** 4

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [October 13, 2024, 6:09pm UTC](https://discourse.julialang.org/t/how-fast-does-a-model-has-to-be-for-nmpc/120694/62 "2024-10-13T18:09:43Z")

</div>

With this approach you do linearization followed by discretization which is generally less accurate than discretization followed by linearization. When you are integrating the linear approximation instead of the original nonlinear dynamics, the error in the linearization will grow with the sample interval. In this situation, the assumption is that linearized MPC is good enough over a time horizon T\_s N, which if true means that the error incurred due to linearization over the horizon T\_s only should be relatively small, so you might be fine.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [October 29, 2024, 10:35am UTC](https://discourse.julialang.org/t/how-fast-does-a-model-has-to-be-for-nmpc/120694/63 "2024-10-29T10:35:45Z")

</div>

Small update: I am now using a dual-loop controller, the inner loop controls the turn rate. This gives already a much better performance:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/f/0/f0cdd41f46f664aeab07aa62b38ffd2a19008fa5.png)

Better disturbance rejection, better damping, much easier to tune and works over a much larger range of wind speeds. Just a dual PI controller. So for this part of the control problem NMPC is not really needed, but there are other parts, in particular the winch control where it still might be useful.

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [October 29, 2024, 1:56pm UTC](https://discourse.julialang.org/t/how-fast-does-a-model-has-to-be-for-nmpc/120694/64 "2024-10-29T13:56:37Z")

</div>

Nice, cascade control is used for motion control in most industrial robot control systems also. Are you sure you need an integrator in both controllers? It’s typically only required in the inner controller. The outer controller will automatically benefit from the integration in the inner controller without having an integrator itself.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [October 29, 2024, 2:17pm UTC](https://discourse.julialang.org/t/how-fast-does-a-model-has-to-be-for-nmpc/120694/65 "2024-10-29T14:17:40Z")

</div>

> [@baggepinnen](#):
>
> Are you sure you need an integrator in both controllers? It’s typically only required in the inner controller.

You are right, disabling the outer integrator even gives a slightly improved response:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/5/d/5dc1692a52a4773521f4cf1ca18358a89a47135e.png)

---

<div class="post-metadata">

**Author:** ![Bart\_van\_de\_Lint](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bart_van_de_lint/32/212161_2.png) [@Bart\_van\_de\_Lint](https://discourse.julialang.org/u/Bart_van_de_Lint)\
**Post date:** [December 19, 2024, 8:13am UTC](https://discourse.julialang.org/t/how-fast-does-a-model-has-to-be-for-nmpc/120694/66 "2024-12-19T08:13:11Z")

</div>

Update: this has actually been done before, and yes, NMPC is feasable for quite slow nonlinear problems (my guess is around 20 times realtime), as long as the MPC is implemented in a smart way.  
[This](https://www.researchgate.net/publication/220258692_A_Real-Time_Iteration_Scheme_for_Nonlinear_Optimization_in_Optimal_Feedback_Control) paper and [this](https://scholar.google.no/citations?view_op=view_citation&hl=en&user=38fYqeYAAAAJ&citation_for_view=38fYqeYAAAAJ:RYcK_YlVTxYC) paper both have an implementation.

[Previous page](https://discourse.julialang.org/t/how-fast-does-a-model-has-to-be-for-nmpc/120694.md?page=3)
