Skip to content

Commit 574b72c

Browse files
fix test
1 parent 145de89 commit 574b72c

File tree

1 file changed

+49
-8
lines changed

1 file changed

+49
-8
lines changed

test/Electrical/dc_motor.jl

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,30 @@ using ModelingToolkit, OrdinaryDiffEq, Test
4141

4242
@named model = ODESystem(connections, t, systems=[ground, voltage_step, source, R1, L1, emf, fixed, load, load_step, inertia, friction])
4343
sys = structural_simplify(model)
44-
prob = ODAEProblem(sys, Pair[], (0, 6.0))
45-
sol = solve(prob, Rodas4())
4644

45+
@test_broken prob = ODAEProblem(sys, Pair[], (0, 6.0))
46+
@test_skip begin
47+
sol = solve(prob, Rodas4())
48+
@test sol.retcode == :Success
49+
# EMF equations
50+
@test -0.5 .* sol[emf.i] == sol[emf.flange.tau]
51+
@test sol[emf.v] == 0.5 .* sol[emf.w]
52+
# test steady-state values
53+
dc_gain = [f/(k^2 + f*R) k/(k^2 + f*R); k/(k^2 + f*R) -R/(k^2+f*R)]
54+
idx_t = findfirst(sol.t .> 2.5)
55+
@test sol[inertia.w][idx_t] (dc_gain*[V_step; 0])[2]
56+
@test sol[emf.i][idx_t] (dc_gain*[V_step; 0])[1]
57+
idx_t = findfirst(sol.t .> 5.5)
58+
@test sol[inertia.w][idx_t] (dc_gain*[V_step; -tau_L_step])[2]
59+
@test sol[emf.i][idx_t] (dc_gain*[V_step; -tau_L_step])[1]
60+
end
61+
62+
prob = DAEProblem(sys, D.(states(sys)) .=> 0.0, Pair[], (0, 6.0))
63+
sol = solve(prob, DFBDF())
4764
@test sol.retcode == :Success
4865
# EMF equations
4966
@test -0.5 .* sol[emf.i] == sol[emf.flange.tau]
5067
@test sol[emf.v] == 0.5 .* sol[emf.w]
51-
5268
# test steady-state values
5369
dc_gain = [f/(k^2 + f*R) k/(k^2 + f*R); k/(k^2 + f*R) -R/(k^2+f*R)]
5470
idx_t = findfirst(sol.t .> 2.5)
@@ -57,7 +73,7 @@ using ModelingToolkit, OrdinaryDiffEq, Test
5773
idx_t = findfirst(sol.t .> 5.5)
5874
@test sol[inertia.w][idx_t] (dc_gain*[V_step; -tau_L_step])[2]
5975
@test sol[emf.i][idx_t] (dc_gain*[V_step; -tau_L_step])[1]
60-
76+
6177
# p1 = Plots.plot(sol, vars=[inertia.w], ylabel="Angular Vel. in rad/s", label="")
6278
# p2 = Plots.plot(sol, vars=[emf.i], ylabel="Current in A", label="")
6379
# Plots.plot(p1, p2, layout=(2,1))
@@ -100,8 +116,8 @@ end
100116

101117
@named model = ODESystem(connections, t, systems=[ground, voltage_step, source, R1, L1, emf, fixed, load, load_step, inertia, friction, speed_sensor])
102118
sys = structural_simplify(model)
103-
@test_broken prob = ODAEProblem(sys, Pair[], (0, 6.0)) # KeyError: key 17 not found
104119

120+
@test_broken prob = ODAEProblem(sys, Pair[], (0, 6.0)) # KeyError: key 17 not found
105121
@test_skip begin
106122
sol = solve(prob, Rodas4())
107123

@@ -122,6 +138,25 @@ end
122138
#
123139
@test sol[inertia.w] == sol[speed_sensor.w]
124140
end
141+
142+
prob = DAEProblem(sys, D.(states(sys)) .=> 0.0, Pair[], (0, 6.0))
143+
sol = solve(prob, DFBDF())
144+
145+
@test sol.retcode == :Success
146+
# EMF equations
147+
@test -0.5 .* sol[emf.i] == sol[emf.flange.tau]
148+
@test sol[emf.v] == 0.5 .* sol[emf.w]
149+
# test steady-state values
150+
dc_gain = [f/(k^2 + f*R) k/(k^2 + f*R); k/(k^2 + f*R) -R/(k^2+f*R)]
151+
idx_t = findfirst(sol.t .> 2.5)
152+
@test sol[inertia.w][idx_t] (dc_gain*[V_step; 0])[2]
153+
@test sol[emf.i][idx_t] (dc_gain*[V_step; 0])[1]
154+
idx_t = findfirst(sol.t .> 5.5)
155+
@test sol[inertia.w][idx_t] (dc_gain*[V_step; -tau_L_step])[2]
156+
@test sol[emf.i][idx_t] (dc_gain*[V_step; -tau_L_step])[1]
157+
#
158+
@test sol[inertia.w] == sol[speed_sensor.w]
159+
125160
end
126161

127162
@testset "DC-motor with PI controller" begin
@@ -160,17 +195,23 @@ end
160195

161196
@named model = ODESystem(connections, t, systems=[ground, ref, pi_controller, feedback, source, R1, L1, emf, fixed, load, load_step, inertia, friction, speed_sensor, fixed2])
162197
sys = structural_simplify(model)
163-
prob = ODAEProblem(sys, Pair[], (0, 6.0))
164-
198+
199+
@test_broken prob = ODAEProblem(sys, Pair[], (0, 6.0))
165200
@test_skip begin
166201
sol = solve(prob, Rodas4())
167-
168202
@test sol.retcode == :Success
169203
@test -0.5 .* sol[emf.i] == sol[emf.flange.tau]
170204
@test sol[emf.v] == 0.5 .* sol[emf.w]
171205
@test sol[speed_sensor.w_rel.u][end] == 1 # zero control error
172206
end
173207

208+
prob = DAEProblem(sys, D.(states(sys)) .=> 0.0, Pair[], (0, 6.0))
209+
sol = solve(prob, DFBDF())
210+
@test sol.retcode == :Success
211+
@test -0.5 .* sol[emf.i] == sol[emf.flange.tau]
212+
@test sol[emf.v] == 0.5 .* sol[emf.w]
213+
@test sol[speed_sensor.w_rel.u][end] == 1 # zero control error
214+
174215
# p1 = Plots.plot(sol, vars=[inertia.w], ylabel="Angular Vel. in rad/s", label="")
175216
# p2 = Plots.plot(sol, vars=[emf.i], ylabel="Current in A", label="")
176217
# Plots.plot(p1, p2, layout=(2,1))

0 commit comments

Comments
 (0)