Skip to content

Commit

Permalink
don't test cont. time
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Jul 13, 2023
1 parent 07c63a4 commit 92010a5
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions lib/ControlSystemsBase/test/test_discrete.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,26 +184,26 @@ Qd3, Rd3 = c2d(sysd, Qc, Rc; opt=:c) # Discrete system as input


# NOTE: these tests are not run due to OrdinaryDiffEq latency, they should pass
using OrdinaryDiffEq
L = lqr(sysc, Qc, Rc)
dynamics = function (xc, p, t)
x = xc[1:sysc.nx]
u = -L*x
dx = sysc.A*x + sysc.B*u
dc = dot(x, Qc, x) + dot(u, Rc, u)
return [dx; dc]
end
prob = ODEProblem(dynamics, [x0; 0], (0.0, 10.0))
sol = solve(prob, Tsit5(), reltol=1e-8, abstol=1e-8)
cc = sol.u[end][end]
Ld = lqr(sysd, Qd, Rd)
sold = lsim(sysd, (x, t) -> -Ld*x, 0:Ts:10, x0 = x0)
function cost(x, u, Q, R)
dot(x, Q, x) + dot(u, R, u)
end
cd = cost(sold.x, sold.u, Qd, Rd)
@test cc cd rtol=0.01
@test abs(cc-cd) < 1.0001*0.005531389319983315
# using OrdinaryDiffEq
# L = lqr(sysc, Qc, Rc)
# dynamics = function (xc, p, t)
# x = xc[1:sysc.nx]
# u = -L*x
# dx = sysc.A*x + sysc.B*u
# dc = dot(x, Qc, x) + dot(u, Rc, u)
# return [dx; dc]
# end
# prob = ODEProblem(dynamics, [x0; 0], (0.0, 10.0))
# sol = solve(prob, Tsit5(), reltol=1e-8, abstol=1e-8)
# cc = sol.u[end][end]
# Ld = lqr(sysd, Qd, Rd)
# sold = lsim(sysd, (x, t) -> -Ld*x, 0:Ts:10, x0 = x0)
# function cost(x, u, Q, R)
# dot(x, Q, x) + dot(u, R, u)
# end
# cd = cost(sold.x, sold.u, Qd, Rd)
# @test cc ≈ cd rtol=0.01
# @test abs(cc-cd) < 1.0001*0.005531389319983315


# test case from paper
Expand Down

0 comments on commit 92010a5

Please sign in to comment.