Skip to content

Commit 7051dbe

Browse files
a bit of tidying
1 parent 3094ba3 commit 7051dbe

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

src/Mechanical/PlanarMechanics/components.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Frame fixed in the planar world frame at a given position and orientation
1212
# Connectors:
1313
1414
- `frame: 2-dim. Coordinate system
15+
16+
https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b708391461cbe2523/PlanarMechanics/Parts/Fixed.mo
1517
"""
1618
@mtkmodel Fixed begin
1719
@parameters begin
@@ -58,12 +60,14 @@ Body component with mass and inertia
5860
# Connectors:
5961
6062
- `frame`: 2-dim. Coordinate system
63+
64+
https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b708391461cbe2523/PlanarMechanics/Parts/Body.mo
6165
"""
62-
@component function Body(; name, m, j, rx = 0, ry = 0, gy = -9.807)
66+
@component function Body(; name, m, I, rx = 0, ry = 0, gy = -9.807)
6367
@named frame = Frame()
6468
pars = @parameters begin
6569
m = m
66-
j = j
70+
I = I
6771
gy = gy
6872
end
6973

@@ -98,7 +102,7 @@ Body component with mass and inertia
98102
fy ~ frame.fy,
99103
ax ~ fx / m,
100104
ay ~ ifelse(gy !== nothing, fy / m + gy, fy / m),
101-
j * α ~ frame.j,
105+
I * α ~ frame.j,
102106
]
103107

104108
return compose(ODESystem(eqs, t, vars, pars; name = name),
@@ -119,6 +123,8 @@ A fixed translation between two components (rigid rod)
119123
120124
- `frame_a` [Frame](@ref) Coordinate system fixed to the component with one cut-force and cut-torque
121125
- `frame_b` [Frame](@ref) Coordinate system fixed to the component with one cut-force and cut-torque
126+
127+
https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b708391461cbe2523/PlanarMechanics/Parts/FixedTranslation.mo
122128
"""
123129
@mtkmodel FixedTranslation begin
124130
@extend frame_a, frame_b = partial_frames = PartialTwoFrames()
@@ -148,7 +154,7 @@ A fixed translation between two components (rigid rod)
148154
# balancing force including lever principle
149155
frame_a.fx + frame_b.fx ~ 0
150156
frame_a.fy + frame_b.fy ~ 0
151-
frame_a.j + frame_b.j + r0[1] * frame_b.fy - r0[2] * frame_b.fx ~ 0
157+
frame_a.j + frame_b.j + r0' * [frame_b.fy, -frame_b.fx] ~ 0
152158
end
153159
end
154160

src/Mechanical/PlanarMechanics/joints.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ A revolute joint
2020
- `flange_a` [Flange](@ref) if `use_flange == true`
2121
- `support` [Support](@ref) if `use_flange == true`
2222
23+
https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b708391461cbe2523/PlanarMechanics/Joints/Revolute.mo
2324
"""
2425
@component function Revolute(;
2526
name,
@@ -96,6 +97,8 @@ A prismatic joint
9697
- `fixed` [Fixed](@ref) if `use_flange == false`
9798
- `flange_a` [Flange](@ref) if `use_flange == true`
9899
- `support` [Support](@ref) if `use_flange == true`
100+
101+
https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b708391461cbe2523/PlanarMechanics/Joints/Prismatic.mo
99102
"""
100103
@component function Prismatic(;
101104
name,

test/Mechanical/planar_mechanics.jl

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# using Revise
2+
# using Plots
13
using ModelingToolkit, OrdinaryDiffEq, Test
24
using ModelingToolkitStandardLibrary.Mechanical.PlanarMechanics
35

@@ -9,8 +11,8 @@ g = -9.807
911
@testset "Free body" begin
1012
# https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b708391461cbe2523/PlanarMechanics/Examples/FreeBody.mo
1113
m = 2
12-
j = 1
13-
@named body = Body(; m, j)
14+
I = 1
15+
@named body = Body(; m, I)
1416
@named model = ODESystem(Equation[],
1517
t,
1618
[],
@@ -34,7 +36,7 @@ end
3436
# https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b708391461cbe2523/PlanarMechanics/Examples/Pendulum.mo
3537
@named ceiling = Fixed()
3638
@named rod = FixedTranslation(rx = 1.0, ry = 0.0)
37-
@named body = Body(m = 1, j = 0.1)
39+
@named body = Body(m = 1, I = 0.1)
3840
@named revolute = Revolute()
3941

4042
connections = [
@@ -50,7 +52,12 @@ end
5052
systems = [body, revolute, rod, ceiling])
5153
sys = structural_simplify(model)
5254

53-
@test length(states(sys)) == 7
55+
@test_broken length(states(sys)) == 2
56+
unset_vars = setdiff(states(sys), keys(ModelingToolkit.defaults(sys)))
57+
prob = ODEProblem(sys, unset_vars .=> 0.0, tspan, []; jac = true)
58+
59+
sol = solve(prob, Rodas5P())
60+
@test_broken SciMLBase.successful_retcode(sol)
5461
end
5562

5663
@testset "Prismatic" begin
@@ -61,12 +68,12 @@ end
6168
@testset "AbsoluteAccCentrifugal" begin
6269
# https://github.com/dzimmer/PlanarMechanics/blob/443b007bcc1522bb172f13012e2d7a8ecc3f7a9b/PlanarMechanicsTest/Sensors.mo#L221-L332
6370
m = 1
64-
j = 0.1
71+
I = 0.1
6572
ω = 10
6673
resolve_in_frame = :world
6774

6875
# components
69-
@named body = Body(; m, j, gy = 0.0)
76+
@named body = Body(; m, I, gy = 0.0)
7077
@named fixed_translation = FixedTranslation(; rx = 10.0, ry = 0.0)
7178
@named fixed = Fixed()
7279
@named revolute = Revolute(constant_ω = ω)
@@ -114,11 +121,11 @@ end
114121

115122
@testset "Sensors (two free falling bodies)" begin
116123
m = 1
117-
j = 1
124+
I = 1
118125
resolve_in_frame = :world
119126

120-
@named body1 = Body(; m, j)
121-
@named body2 = Body(; m, j)
127+
@named body1 = Body(; m, I)
128+
@named body2 = Body(; m, I)
122129
@named base = Fixed()
123130

124131
@named abs_pos_sensor = AbsolutePosition(; resolve_in_frame)
@@ -209,10 +216,10 @@ end
209216

210217
@testset "Measure Demo" begin
211218
# https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b708391461cbe2523/PlanarMechanics/Examples/MeasureDemo.mo
212-
@named body = Body(; m = 1, j = 0.1)
219+
@named body = Body(; m = 1, I = 0.1)
213220
@named fixed_translation = FixedTranslation(; rx = 1, ry = 0)
214221
@named fixed = Fixed()
215-
@named body1 = Body(; m = 0.4, j = 0.02)
222+
@named body1 = Body(; m = 0.4, I = 0.02)
216223
@named fixed_translation1 = FixedTranslation(; rx = 0.4, ry = 0)
217224
@named abs_pos_sensor = AbsolutePosition(; resolve_in_frame = :world)
218225
@named rel_pos_sensor = RelativePosition(; resolve_in_frame = :world)
@@ -274,7 +281,7 @@ end
274281
c_x = 5,
275282
d_x = 1,
276283
c_phi = 0)
277-
@named body = Body(; j = 0.1, m = 0.5, rx = 1, ry = 1)
284+
@named body = Body(; I = 0.1, m = 0.5, rx = 1, ry = 1)
278285
@named fixed = Fixed()
279286
@named fixed_translation = FixedTranslation(; rx = -1, ry = 0)
280287

@@ -302,7 +309,7 @@ end
302309

303310
@testset "Spring and damper demo" begin
304311
# https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b708391461cbe2523/PlanarMechanics/Examples/SpringDemo.mo
305-
@named body = Body(; m = 0.5, j = 0.1)
312+
@named body = Body(; m = 0.5, I = 0.1)
306313
@named fixed = Fixed()
307314
@named spring = Spring(; c_y = 10, s_rely0 = -0.5, c_x = 1, c_phi = 1e5)
308315
@named damper = Damper(d = 1)

0 commit comments

Comments
 (0)