Skip to content

Commit fcc3707

Browse files
Add AbsoluteAccCentrifugal test (w/o sensors)
1 parent 1393610 commit fcc3707

1 file changed

Lines changed: 48 additions & 5 deletions

File tree

test/Mechanical/planar_mechanics.jl

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,8 @@ end
4848
[],
4949
systems = [body, revolute, rod, ceiling])
5050
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())
5451

55-
# phi and omega for the pendulum body
56-
@test length(states(sys)) == 2
52+
@test length(states(sys)) == 7
5753
end
5854

5955
@testset "Prismatic" begin
@@ -64,6 +60,53 @@ end
6460
@test true
6561
end
6662

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+
67110
@testset "Sensors (two free falling bodies)" begin
68111
m = 1
69112
j = 1

0 commit comments

Comments
 (0)