@@ -8,80 +8,70 @@ using Test
8
8
@parameters t
9
9
10
10
@named link1 = Link (; m = 1 , l = 10 , I = 84 , g = - 9.807 )
11
- @named link2 = Link (; m = 1 , l = 10 , I = 84 , g = - 9.807 , x1_0= 10 )
11
+ @named link2 = Link (; m = 1 , l = 10 , I = 84 , g = - 9.807 , x1_0 = 10 )
12
12
@named cart = Mass (; m = 1 , s_0 = 0 )
13
13
# @named force = SineForce(;amp=3e3, freq=15)
14
14
@named fixed = Fixed ()
15
15
# @named m1 = Mass(;m=0.5)
16
16
# @named m2 = Mass(;m=0.5)
17
17
18
- eqs = [
19
- connect (link1. TX1, cart. flange) # , force.flange)
20
- connect (link1. TY1, fixed. flange)
21
- connect (link1. TX2, link2. TX1)
22
- connect (link1. TY2, link2. TY1)
23
- ]
18
+ eqs = [connect (link1. TX1, cart. flange) # , force.flange)
19
+ connect (link1. TY1, fixed. flange)
20
+ connect (link1. TX2, link2. TX1)
21
+ connect (link1. TY2, link2. TY1)]
24
22
25
23
@named model = ODESystem (eqs, t, [], []; systems = [link1, link2, cart, fixed])
26
24
27
- # TODO : This gives an error
28
25
sys = structural_simplify (model)
29
26
30
27
# The below code does work...
31
28
#=
32
- sys = expand_connections(model)
33
- @set! sys.eqs = [(typeof(eq.lhs) != ModelingToolkit.Connection) & !ModelingToolkit._iszero(eq.lhs) & !ModelingToolkit.isdifferential(eq.lhs) ? 0 ~ eq.rhs - eq.lhs : eq for eq in sys.eqs]
34
-
35
- prob = ODEProblem(sys, [], (0.0, 20), []; jac = true)
36
- NEWTON = NLNewton(check_div = false, always_new = true, max_iter = 100, relax = 4 // 10)
37
- sol = solve(prob, ImplicitEuler(nlsolve = NEWTON), dt = 0.001, adaptive = false)
29
+ unset_vars = setdiff(states(sys), keys(ModelingToolkit.defaults(sys)))
30
+ prob = ODEProblem(sys, unset_vars .=> 0.0, (0.0, 20), []; jac = true)
31
+ sol = solve(prob, Rodas5P())
38
32
39
33
@test sol[cart.s][end] ≈ 4.767 atol=1e-3
40
34
41
35
plot(sol, idxs = [cart.s])
42
36
=#
43
37
44
-
45
38
#=
46
39
using CairoMakie
47
40
f = Figure()
48
41
a = Axis(f[1,1],xlabel="time [s]", ylabel="cart x pos. [m]")
49
42
lines!(a, sol.t, sol[cart.s])
50
43
f
51
44
52
-
53
-
54
45
function plot_link(sol, sys, tmax)
55
46
tm = Observable(0.0)
56
47
idx = Dict(reverse.(enumerate(states(sys))))
57
48
58
49
fig = Figure()
59
50
a = Axis(fig[1,1], aspect=DataAspect(), )
60
51
hidedecorations!(a)
61
- s = @lift(sol($tm))
52
+ s = @lift(sol($tm, idxs=[link1.x1, link1.x2, link2.x1, link2.x2, link1.y1, link1.y2, link2.y1, link2.y2] ))
62
53
63
- m1x1 = @lift($s[idx[link1.x1] ])
64
- m1x2 = @lift($s[idx[link1.x2] ])
65
- m2x1 = @lift($s[idx[link2.x1] ])
66
- m2x2 = @lift($s[idx[link2.x2] ])
54
+ m1x1 = @lift($s[1 ])
55
+ m1x2 = @lift($s[2 ])
56
+ m2x1 = @lift($s[3 ])
57
+ m2x2 = @lift($s[4 ])
67
58
68
- m1y1 = @lift($s[idx[link1.y1] ])
69
- m1y2 = @lift($s[idx[link1.y2] ])
70
- m2y1 = @lift($s[idx[link2.y1] ])
71
- m2y2 = @lift($s[idx[link2.y2] ])
59
+ m1y1 = @lift($s[5 ])
60
+ m1y2 = @lift($s[6 ])
61
+ m2y1 = @lift($s[7 ])
62
+ m2y2 = @lift($s[8 ])
72
63
73
64
sz1 = 0.5
74
65
# lines!(a, [-sz1, sz1, sz1, -sz1, -sz1], @lift([$m1x1, $m1x1, $m1x1+sz1*2, $m1x1+sz1*2, $m1x1]))
75
66
76
-
77
67
lines!(a, @lift([$m1x1, $m1x2]), @lift([$m1y1, $m1y2]), linewidth=10, color=:blue)
78
68
lines!(a, @lift([$m2x1, $m2x2]), @lift([$m2y1, $m2y2]), linewidth=10, color=:red)
79
-
69
+
80
70
CairoMakie.ylims!(a, -40, 20)
81
71
CairoMakie.xlims!(a, -20, 40)
82
72
83
73
# a = Axis(fig[1, 1], xlabel="time [s]", ylabel="position [m]")
84
- # lines!(a, sol.t, sol[2,:])
74
+ # lines!(a, sol.t, sol[2,:])
85
75
# lines!(a, sol.t, sol[4,:])
86
76
87
77
# scatter!(a, tm, m1x)
@@ -91,12 +81,11 @@ function plot_link(sol, sys, tmax)
91
81
framerate = 30
92
82
timestamps = range(0, tmax, step=1/framerate)
93
83
94
-
95
84
record(fig, "links.mp4", timestamps;
96
85
framerate = framerate) do t
97
86
tm[] = t
98
87
end
99
-
88
+
100
89
#=
101
90
CairoMakie.Makie.Record(fig, timestamps; framerate=framerate) do t
102
91
tm[] = t
108
97
109
98
plot_link(sol, sys, 20)
110
99
111
- =#
100
+ =#
0 commit comments