|
140 | 140 | plot!(plt2, t, Pmax, label=raw"$P_\mathrm{max}$", linestyle=:dot, linewidth=1.5) |
141 | 141 | return plot(plt1, plt2, layout=(2,1)) |
142 | 142 | end |
143 | | -plotWithPower(res3_ry, Pmax)</code></pre><p><img src="../plot7_NonLinMPC.svg" alt="plot7_NonLinMPC"/></p><p>The controller is able to find a solution that does not violate the torque and power constraints.</p><h2 id="Model-Linearization"><a class="docs-heading-anchor" href="#Model-Linearization">Model Linearization</a><a id="Model-Linearization-1"></a><a class="docs-heading-anchor-permalink" href="#Model-Linearization" title="Permalink"></a></h2><p>Nonlinear MPC is more computationally expensive than <a href="../../public/predictive_control/#LinMPC"><code>LinMPC</code></a>. Solving the problem should always be faster than the sampling time <span>$T_s = 0.1$</span> s for real-time operation. This requirement is sometimes hard to meet on electronics or mechanical systems because of the fast dynamics. To ease the design and comparison with <a href="../../public/predictive_control/#LinMPC"><code>LinMPC</code></a>, the <a href="../../public/sim_model/#ModelPredictiveControl.linearize"><code>linearize</code></a> function allows automatic linearization of <a href="../../public/sim_model/#NonLinModel"><code>NonLinModel</code></a> based on <a href="https://juliadiff.org/ForwardDiff.jl/stable/#ForwardDiff"><code>ForwardDiff</code></a>. We first linearize <code>model</code> at the point <span>$θ = π$</span> rad and <span>$ω = τ = 0$</span> (inverted position):</p><pre><code class="language-julia hljs">linmodel = linearize(model, x=[π, 0], u=[0])</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">LinModel with a sample time Ts = 0.1 s: |
| 143 | +plotWithPower(res3_ry, Pmax)</code></pre><p><img src="../plot7_NonLinMPC.svg" alt="plot7_NonLinMPC"/></p><p>The controller is able to find a solution that does not violate the torque and power constraints.</p><h2 id="Model-Linearization"><a class="docs-heading-anchor" href="#Model-Linearization">Model Linearization</a><a id="Model-Linearization-1"></a><a class="docs-heading-anchor-permalink" href="#Model-Linearization" title="Permalink"></a></h2><p>Nonlinear MPC is more computationally expensive than <a href="../../public/predictive_control/#LinMPC"><code>LinMPC</code></a>. Solving the problem should always be faster than the sampling time <span>$T_s = 0.1$</span> s for real-time operation. This requirement is sometimes hard to meet on electronics or mechanical systems because of the fast dynamics. To ease the design and comparison with <a href="../../public/predictive_control/#LinMPC"><code>LinMPC</code></a>, the <a href="../../public/sim_model/#ModelPredictiveControl.linearize"><code>linearize</code></a> function allows automatic linearization of <a href="../../public/sim_model/#NonLinModel"><code>NonLinModel</code></a> defaulting to <a href="https://juliadiff.org/ForwardDiff.jl/stable/#ForwardDiff"><code>ForwardDiff</code></a>. We first linearize <code>model</code> at the point <span>$θ = π$</span> rad and <span>$ω = τ = 0$</span> (inverted position):</p><pre><code class="language-julia hljs">linmodel = linearize(model, x=[π, 0], u=[0])</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">LinModel with a sample time Ts = 0.1 s: |
144 | 144 | └ dimensions: |
145 | 145 | ├ 1 manipulated inputs u |
146 | 146 | ├ 2 states x |
|
233 | 233 | res_slin = sim_adapt!(mpc3, model, N, ry, plant, x_0, x̂_0) |
234 | 234 | plot(res_slin)</code></pre><p><img src="../plot12_NonLinMPC.svg" alt="plot12_NonLinMPC"/></p><p>and the 10° step disturbance:</p><pre><code class="language-julia hljs">x_0 = [π, 0]; x̂_0 = [π, 0, 0]; y_step = [10] |
235 | 235 | res_slin = sim_adapt!(mpc3, model, N, ry, plant, x_0, x̂_0, y_step) |
236 | | -plot(res_slin)</code></pre><p><img src="../plot13_NonLinMPC.svg" alt="plot13_NonLinMPC"/></p><p>The computations of the successive linearization MPC are about 75 times faster than the nonlinear MPC on average, an impressive gain for similar closed-loop performances!</p><section class="footnotes is-size-7"><ul><li class="footnote" id="footnote-1"><a class="tag is-link" href="#citeref-1">1</a>Arnström, D., Bemporad, A., and Axehill, D. (2022). A dual active-set solver for embedded quadratic programming using recursive LDLᵀ updates. IEEE Trans. Autom. Contr., 67(8). <a href="https://doi.org/doi:10.1109/TAC.2022.3176430">https://doi.org/doi:10.1109/TAC.2022.3176430</a>.</li></ul></section></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../linmpc/">« Linear Design</a><a class="docs-footer-nextpage" href="../mtk/">ModelingToolkit »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="catppuccin-latte">catppuccin-latte</option><option value="catppuccin-frappe">catppuccin-frappe</option><option value="catppuccin-macchiato">catppuccin-macchiato</option><option value="catppuccin-mocha">catppuccin-mocha</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.14.1 on <span class="colophon-date" title="Monday 22 September 2025 20:47">Monday 22 September 2025</span>. Using Julia version 1.11.7.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html> |
| 236 | +plot(res_slin)</code></pre><p><img src="../plot13_NonLinMPC.svg" alt="plot13_NonLinMPC"/></p><p>The computations of the successive linearization MPC are about 75 times faster than the nonlinear MPC on average, an impressive gain for similar closed-loop performances!</p><section class="footnotes is-size-7"><ul><li class="footnote" id="footnote-1"><a class="tag is-link" href="#citeref-1">1</a>Arnström, D., Bemporad, A., and Axehill, D. (2022). A dual active-set solver for embedded quadratic programming using recursive LDLᵀ updates. IEEE Trans. Autom. Contr., 67(8). <a href="https://doi.org/doi:10.1109/TAC.2022.3176430">https://doi.org/doi:10.1109/TAC.2022.3176430</a>.</li></ul></section></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../linmpc/">« Linear Design</a><a class="docs-footer-nextpage" href="../mtk/">ModelingToolkit »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="catppuccin-latte">catppuccin-latte</option><option value="catppuccin-frappe">catppuccin-frappe</option><option value="catppuccin-macchiato">catppuccin-macchiato</option><option value="catppuccin-mocha">catppuccin-mocha</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.14.1 on <span class="colophon-date" title="Tuesday 23 September 2025 20:57">Tuesday 23 September 2025</span>. Using Julia version 1.11.7.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html> |
0 commit comments