Skip to content

Commit e63b7a9

Browse files
committed
debug test
1 parent 355dd50 commit e63b7a9

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/model/linmodel.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ and `:zoh` for manipulated inputs, and `:tustin`, for measured disturbances. Las
6767
`sys` is discrete and the provided argument `Ts ≠ sys.Ts`, the system is resampled by using
6868
the aforementioned discretization methods.
6969
70-
The constructor transforms the system to a more practical form (``\mathbf{D_u=0}`` because
71-
of the zero-order hold):
70+
Note that the constructor transforms the system to its minimal realization using [`minreal`](https://juliacontrol.github.io/ControlSystems.jl/stable/lib/constructors/#ControlSystemsBase.minreal)
71+
to favor observability. As a consequence, the final state-space representation may be
72+
different from the one provided in `sys`. It is also converted into a more practical form
73+
(``\mathbf{D_u=0}`` because of the zero-order hold):
7274
```math
7375
\begin{aligned}
7476
\mathbf{x}(k+1) &= \mathbf{A x}(k) + \mathbf{B_u u}(k) + \mathbf{B_d d}(k) \\
@@ -117,7 +119,8 @@ function LinModel(
117119
sysd_dis = sysd
118120
end
119121
end
120-
sys_dis = minreal([sysu_dis sysd_dis]) # merge common poles if possible
122+
# minreal to merge common poles if possible and ensure observability
123+
sys_dis = minreal([sysu_dis sysd_dis])
121124
nx = size(sys_dis.A,1)
122125
nu = length(i_u)
123126
ny = size(sys_dis,1)
@@ -150,8 +153,7 @@ Discrete-time linear model with a sample time Ts = 0.5 s and:
150153
```
151154
"""
152155
function LinModel(sys::TransferFunction, Ts::Union{Real,Nothing} = nothing; kwargs...)
153-
sys_min = minreal(ss(sys)) # remove useless states with pole-zero cancellation
154-
return LinModel(sys_min, Ts; kwargs...)
156+
return LinModel(ss(sys), Ts; kwargs...) # minreal is called later in the constructor
155157
end
156158

157159

@@ -173,8 +175,8 @@ Discrete-time linear model with a sample time Ts = 0.5 s and:
173175
```
174176
"""
175177
function LinModel(sys::DelayLtiSystem, Ts::Real; kwargs...)
176-
sys_dis = minreal(c2d(sys, Ts, :zoh)) # c2d only supports :zoh for DelayLtiSystem
177-
return LinModel(sys_dis, Ts; kwargs...)
178+
# c2d only supports :zoh for DelayLtiSystem
179+
return LinModel(c2d(sys, Ts, :zoh), Ts; kwargs...)
178180
end
179181

180182

src/state_estim.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,11 @@ find a good steady-state to initialize `estim.x̂` estimate.
296296
```jldoctest
297297
julia> estim = SteadyKalmanFilter(LinModel(tf(3, [10, 1]), 0.5), nint_ym=[2]);
298298
299-
julia> u = [1]; ym = [3 - 0.1]; x̂ = initstate!(estim, u, ym)
299+
julia> u = [1]; ym = [3 - 0.1]; x̂ = round.(initstate!(estim, u, ym), digits=3)
300300
3-element Vector{Float64}:
301-
5.0000000000000115
301+
5.0
302302
0.0
303-
-0.10000000000000675
303+
-0.1
304304
305305
julia> x̂ ≈ updatestate!(estim, u, ym)
306306
true

test/test_predictive_control.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ end
257257
h(x,_) = linmodel.C*x
258258
nonlinmodel = NonLinModel(f, h, Ts, 2, 2, 2)
259259
nmpc1 = NonLinMPC(nonlinmodel)
260-
@test initstate!(nmpc1, [10, 50], [20, 25]) [zeros(2); [20, 25]]
260+
@test initstate!(nmpc1, [10, 50], [20, 25]) zeros(4)
261261
setstate!(nmpc1, [1,2,3,4])
262262
@test nmpc1.estim. [1,2,3,4]
263263
setstate!(nmpc1, [0,0,0,0])

0 commit comments

Comments
 (0)