|
48 | 48 | [], |
49 | 49 | systems = [body, revolute, rod, ceiling]) |
50 | 50 | sys = structural_simplify(model) |
51 | | - unset_vars = setdiff(states(sys), keys(ModelingToolkit.defaults(sys))) |
52 | | - prob = ODEProblem(sys, unset_vars .=> 0.0, tspan, []; jac = true) |
53 | | - sol = solve(prob, Rodas5P()) |
54 | 51 |
|
55 | | - # phi and omega for the pendulum body |
56 | | - @test length(states(sys)) == 2 |
| 52 | + @test length(states(sys)) == 7 |
57 | 53 | end |
58 | 54 |
|
59 | 55 | @testset "Prismatic" begin |
|
64 | 60 | @test true |
65 | 61 | end |
66 | 62 |
|
| 63 | +@testset "AbsoluteAccCentrifugal" begin |
| 64 | + # https://github.com/dzimmer/PlanarMechanics/blob/443b007bcc1522bb172f13012e2d7a8ecc3f7a9b/PlanarMechanicsTest/Sensors.mo#L221-L332 |
| 65 | + m = 1 |
| 66 | + j = 0.1 |
| 67 | + ω = 10 |
| 68 | + resolve_in_frame = :world |
| 69 | + |
| 70 | + # components |
| 71 | + @named body = Body(; m, j, gy = 0.0) |
| 72 | + @named fixed_translation = FixedTranslation(; rx = 10.0, ry = 0.0) |
| 73 | + @named fixed = Fixed() |
| 74 | + @named revolute = Revolute(ω = ω) |
| 75 | + |
| 76 | + eqs = [ |
| 77 | + connect(fixed_translation.frame_b, body.frame), |
| 78 | + connect(fixed.frame, revolute.frame_a), |
| 79 | + connect(revolute.frame_b, fixed_translation.frame_a), |
| 80 | + ] |
| 81 | + |
| 82 | + @named model = ODESystem(eqs, |
| 83 | + t, |
| 84 | + [], |
| 85 | + [], |
| 86 | + systems = [ |
| 87 | + body, |
| 88 | + fixed_translation, |
| 89 | + fixed, |
| 90 | + revolute, |
| 91 | + ]) |
| 92 | + sys = structural_simplify(model) |
| 93 | + prob = ODEProblem(sys, [0.0, 10.0, 0.0], tspan, []; jac = true) |
| 94 | + sol = solve(prob, Rodas5P()) |
| 95 | + |
| 96 | + # phi |
| 97 | + @test sol[body.phi][end] ≈ tspan[end] * ω |
| 98 | + @test all(sol[body.ω] .≈ ω) |
| 99 | + |
| 100 | + test_points = [i / ω for i in 0:0.1:10] |
| 101 | + # instantaneous linear velocity |
| 102 | + v_singal(t) = -ω^2 * sin.(ω .* t) |
| 103 | + @test all(v_singal.(test_points) .≈ sol.(test_points; idxs = body.vx)) |
| 104 | + |
| 105 | + # instantaneous linear acceleration |
| 106 | + a_singal(t) = -ω^3 * cos.(ω .* t) |
| 107 | + @test all(a_singal.(test_points) .≈ sol.(test_points; idxs = body.ax)) |
| 108 | +end |
| 109 | + |
67 | 110 | @testset "Sensors (two free falling bodies)" begin |
68 | 111 | m = 1 |
69 | 112 | j = 1 |
|
0 commit comments