# Linear parameter varying control (LPV control)

**URL:** <https://discourse.julialang.org/t/linear-parameter-varying-control-lpv-control/121840>\
**Category:** Modelling & Simulations\
**Tags:** question, control, aerospace\
**Created:** [October 27, 2024, 7:21pm UTC](https://discourse.julialang.org/t/linear-parameter-varying-control-lpv-control/121840 "2024-10-27T19:21:25Z")\
**Posts on this page:** 9\
**Page:** 1

<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 27, 2024, 7:21pm UTC](https://discourse.julialang.org/t/linear-parameter-varying-control-lpv-control/121840/1 "2024-10-27T19:21:25Z")

</div>

I am trying to implement an LPV controller based on [GitHub - JuliaControl/DiscretePIDs.jl: Discrete-time PID controllers in Julia](https://github.com/JuliaControl/DiscretePIDs.jl)

The idea is easy: Use a controller for heading/ course with an inner and an outer loop. The inner loop controls the turn rate, the outer loop heading or course. The scheduling parameter is the apparent wind speed. Based on the scheduling parameter the gains of the inner and outer controller are varied accordingly.

Less obvious:

- how to determine the lookup-table with the controller parameters?
- how to determine if the system is stable, and what the stability margin is

Are there any other packages/ Julia resources regarding this topic?

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [October 27, 2024, 7:29pm UTC](https://discourse.julialang.org/t/linear-parameter-varying-control-lpv-control/121840/2 "2024-10-27T19:29:14Z")

</div>

Here are two suggestions of related (and potentially useful) packages

- [GitHub - baggepinnen/LTVModels.jl: Tools to estimate Linear Time-Varying models in Julia](https://github.com/baggepinnen/LTVModels.jl)
- [Plant Models · ModelPredictiveControl.jl](https://juliacontrol.github.io/ModelPredictiveControl.jl/stable/public/sim_model/#ModelPredictiveControl.NonLinModel), especially given this comment about gain scheduling [[ANN] ModelPredictiveControl.jl - #16 by franckgaga](https://discourse.julialang.org/t/ann-modelpredictivecontrol-jl/100147/16)
- [Batch linearization and gain scheduling · ControlSystemsMTK Documentation](https://juliacontrol.github.io/ControlSystemsMTK.jl/dev/batch_linearization/)

---

<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 27, 2024, 7:35pm UTC](https://discourse.julialang.org/t/linear-parameter-varying-control-lpv-control/121840/3 "2024-10-27T19:35:24Z")

</div>

Thanks a lot!

But I think there is a slight difference between LPV systems and LTV systems. The wind speed is a parameter that can be measured (or estimated), but the future wind speed is not known, and as far as I know LTV systems assume that the time dependency is known.

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [October 27, 2024, 8:24pm UTC](https://discourse.julialang.org/t/linear-parameter-varying-control-lpv-control/121840/4 "2024-10-27T20:24:53Z")

</div>

You’re welcome, LPV and LTV are different, but I assume (without certainty though) that @baggepinnen has built-in tools to handle LPV).  
You should have a look at the [_gain scheduling_](https://en.wikipedia.org/wiki/Gain_scheduling) and [_batch linearization_](https://juliacontrol.github.io/ControlSystemsMTK.jl/dev/batch_linearization/) terms that are LPV model building technique.  
Maybe also have a look at [Home · RobustAndOptimalControl Documentation](https://juliacontrol.github.io/RobustAndOptimalControl.jl/dev/) if not already, since parameter variations can be also overcome (depdendy on how much the parameter changes) through robust control.

---

<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 27, 2024, 8:27pm UTC](https://discourse.julialang.org/t/linear-parameter-varying-control-lpv-control/121840/5 "2024-10-27T20:27:53Z")

</div>

> [@BambOoxX](#):
>
> depdendy on how much the parameter changes

Not really. The force depends on the square of the wind speed, and if I want my controller to work in the range of 5 to 30 m/s wind, then the forces vary by a factor of 36, and the system gains are (in first approximation) proportional to the aerodynamic forces.

Gain scheduling I already did in my PhD thesis 10 years ago, but now I want to improve based on this foundation. Batch linearization looks very interesting. Unluckily I don’t have an MTK model yet that I could easily linearize.

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [October 27, 2024, 8:45pm UTC](https://discourse.julialang.org/t/linear-parameter-varying-control-lpv-control/121840/6 "2024-10-27T20:45:26Z")

</div>

Yes, for wind speed a robust controller won’t be enough, although gain scheduling works very well in such cases. Regarding your non-MTK model, you could [`modelintoolkitize`](https://docs.sciml.ai/ModelingToolkit/stable/tutorials/modelingtoolkitize/) it, couldn’t you ?

---

<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 27, 2024, 8:50pm UTC](https://discourse.julialang.org/t/linear-parameter-varying-control-lpv-control/121840/7 "2024-10-27T20:50:08Z")

</div>

This will most likely not work, because my [code](https://github.com/ufechner7/KiteModels.jl/blob/main/src/KPS4.jl) is not compatible with auto-differentiation, it has many if statements and loops. I could re-write it myself, or find a student to do it.

---

<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 28, 2024, 5:56am UTC](https://discourse.julialang.org/t/linear-parameter-varying-control-lpv-control/121840/8 "2024-10-28T05:56:12Z")

</div>

> - how to determine if the system is stable, and what the stability margin is

There are [some tools to compute the structured singular value for systems with uncertainty varying with time here](https://help.juliahub.com/juliasimcontrol/dev/api/#JuliaSimControl.mussv_tv-Union%7BTuple%7BAbstractArray%7BT,%203%7D%7D,%20Tuple%7BT%7D%7D%20where%20T). They tend to be very conservative in an LPV setting though. You can also compute a common Lyapunov function for all systems by solving an LMI, but this is also conservative.

If you can express your LVP model as a polynomial system, you may be able to use Sum-of-squares programming to find a Lyapunov function, [here’s an example](https://jump.dev/SumOfSquares.jl/stable/generated/Systems%20and%20Control/lyapunov_function_search/).

If the system is arbitrarily nonlinear, the only rigorous computational method I know of is [ReachabilityAnalysis](https://juliareach.github.io/ReachabilityAnalysis.jl/dev/), which tends to be expensive as the dimension of the state space grows large. Large-scale Monte-Carlo simulation tends to be the standard method though.

> how to determine the lookup-table with the controller parameters?

The simplest approach is to take the procedure you have for tuning a controller in _one_ operating point and then replicating this for all operating points you want to include in you gain schedule. The [gain-scheduling example](https://juliacontrol.github.io/ControlSystemsMTK.jl/dev/batch_linearization/#Controller-tuning) linked above contains an example of this.

If you can express your LPV system as an LFT, you may be able to use methods from one of the references below by solving convex optimization problems

- [http://pierre.apkarian.free.fr/papers/NonConvexSpectral2017.pdf](http://pierre.apkarian.free.fr/papers/NonConvexSpectral2017.pdf)
- “On the LPV Control Design and Its Applications to Some Classes of Dynamical Systems”, Franco Blanchini, Daniele Casagrande, Giulia Giordano and Stefano Miani

---

<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 28, 2024, 9:14am UTC](https://discourse.julialang.org/t/linear-parameter-varying-control-lpv-control/121840/9 "2024-10-28T09:14:30Z")

</div>

Thank you very much for the detailed response!
