|
602 | 602 | @testitem "NonLinMPC moves and getinfo" setup=[SetupMPCtests] begin
|
603 | 603 | using .SetupMPCtests, ControlSystemsBase, LinearAlgebra, ForwardDiff
|
604 | 604 | linmodel = setop!(LinModel(tf(5, [2000, 1]), 3000.0), yop=[10])
|
605 |
| - Hp = 1000 |
| 605 | + Hp = 100 |
606 | 606 | nmpc_lin = NonLinMPC(linmodel, Nwt=[0], Hp=Hp, Hc=1)
|
607 | 607 | ry, ru = [15], [4]
|
608 | 608 | preparestate!(nmpc_lin, [10])
|
|
635 | 635 | f = (x,u,d,_) -> linmodel2.A*x + linmodel2.Bu*u + linmodel2.Bd*d
|
636 | 636 | h = (x,d,_) -> linmodel2.C*x + linmodel2.Dd*d
|
637 | 637 | nonlinmodel = NonLinModel(f, h, 3000.0, 1, 2, 1, 1, solver=nothing)
|
638 |
| - nmpc2 = NonLinMPC(nonlinmodel, Nwt=[0], Hp=1000, Hc=1) |
| 638 | + nmpc2 = NonLinMPC(nonlinmodel, Nwt=[0], Hp=100, Hc=1) |
639 | 639 | # if d=[0.1], the output will eventually reach 7*0.1=0.7, no action needed (u=0):
|
640 | 640 | d = [0.1]
|
641 | 641 | preparestate!(nmpc2, [0], d)
|
|
646 | 646 | info = getinfo(nmpc2)
|
647 | 647 | @test info[:u] ≈ u
|
648 | 648 | @test info[:Ŷ][end] ≈ 7d[1] atol=5e-2
|
649 |
| - nmpc3 = NonLinMPC(nonlinmodel, Nwt=[0], Cwt=Inf, Hp=1000, Hc=1) |
| 649 | + nmpc3 = NonLinMPC(nonlinmodel, Nwt=[0], Cwt=Inf, Hp=100, Hc=1) |
650 | 650 | preparestate!(nmpc3, [0], [0])
|
651 | 651 | u = moveinput!(nmpc3, 7d, d)
|
652 | 652 | @test u ≈ [0] atol=5e-2
|
|
670 | 670 | nonlinmodel2.h!(y, Float32[0,0], Float32[0], Float32[])
|
671 | 671 | preparestate!(nmpc7, [0], [0])
|
672 | 672 | @test moveinput!(nmpc7, [0], [0]) ≈ [0.0]
|
| 673 | + nmpc8 = NonLinMPC(nonlinmodel, Nwt=[0], Hp=100, Hc=1, transcription=MultipleShooting()) |
| 674 | + preparestate!(nmpc8, [0], [0]) |
| 675 | + u = moveinput!(nmpc8, [10], [0]) |
| 676 | + @test u ≈ [2] atol=5e-2 |
| 677 | + info = getinfo(nmpc8) |
| 678 | + @test info[:u] ≈ u |
| 679 | + @test info[:Ŷ][end] ≈ 10 atol=5e-2 |
| 680 | + nmpc9 = NonLinMPC(linmodel, Nwt=[0], Hp=100, Hc=1, transcription=MultipleShooting()) |
| 681 | + preparestate!(nmpc9, [0]) |
| 682 | + u = moveinput!(nmpc9, [15]) |
| 683 | + @test u ≈ [3] atol=5e-2 |
| 684 | + info = getinfo(nmpc9) |
| 685 | + @test info[:u] ≈ u |
| 686 | + @test info[:Ŷ][end] ≈ 15 atol=5e-2 |
673 | 687 | @test_nowarn ModelPredictiveControl.info2debugstr(info)
|
674 | 688 | end
|
675 | 689 |
|
|
0 commit comments