Skip to content

Move blocking patterns are not correctly handled for LinModel #300

@franckgaga

Description

@franckgaga

Following discussions at darnstrom/LinearMPC.jl#55, it seems that custom move blocking patterns are not correctly handled for LinModel. Here's a MRE:

using ModelPredictiveControl, ControlSystemsBase
using Plots

G = tf( 10, [400,  1])
Ts = 100.0
model = LinModel(G, Ts)
f(x, u, _, p) = p.A * x + p.Bu * u
h(x, _, p)    = p.C * x
nonlinmodel = NonLinModel(f, h, Ts, 1, 1, 1, p=model, solver=nothing)

mpc1 = LinMPC(model; Mwt=[1], Nwt=[0], Hp=30, Hc=[2, 2, 2, 24], transcription=SingleShooting())
mpc2 = LinMPC(model; Mwt=[1], Nwt=[0], Hp=30, Hc=[2, 2, 2, 24], transcription=MultipleShooting())
mpc3 = NonLinMPC(model; Mwt=[1], Nwt=[0], Hp=30, Hc=[2, 2, 2, 24], transcription=SingleShooting())
mpc4 = NonLinMPC(model; Mwt=[1], Nwt=[0], Hp=30, Hc=[2, 2, 2, 24], transcription=MultipleShooting())
mpc5 = NonLinMPC(nonlinmodel; Mwt=[1], Nwt=[0], Hp=30, Hc=[2, 2, 2, 24], transcription=SingleShooting())
mpc6 = NonLinMPC(nonlinmodel; Mwt=[1], Nwt=[0], Hp=30, Hc=[2, 2, 2, 24], transcription=MultipleShooting())

sim!(mpc1, 50, [5], x_0=zeros(mpc1.estim.model.nx), x̂_0=zeros(mpc1.estim.nx̂)) |> plot |> display
sim!(mpc2, 50, [5], x_0=zeros(mpc2.estim.model.nx), x̂_0=zeros(mpc2.estim.nx̂)) |> plot |> display
sim!(mpc3, 50, [5], x_0=zeros(mpc3.estim.model.nx), x̂_0=zeros(mpc3.estim.nx̂)) |> plot |> display
sim!(mpc4, 50, [5], x_0=zeros(mpc4.estim.model.nx), x̂_0=zeros(mpc4.estim.nx̂)) |> plot |> display
sim!(mpc5, 50, [5], x_0=zeros(mpc5.estim.model.nx), x̂_0=zeros(mpc5.estim.nx̂)) |> plot |> display
sim!(mpc6, 50, [5], x_0=zeros(mpc6.estim.model.nx), x̂_0=zeros(mpc6.estim.nx̂)) |> plot |> display

that should all lead to identical results, but it is not the cases for all the controllers based on a LinModel. There is clearly a bug in init_predmat and init_defectmat methods for LinModel. I will add a test that do this comparison once debugged.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions