Skip to content

Commit b7ef276

Browse files
Add Prismatic
1 parent a4fba77 commit b7ef276

File tree

5 files changed

+110
-11
lines changed

5 files changed

+110
-11
lines changed

src/Mechanical/PlanarMechanics/PlanarMechanics.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ Library to model planar mechanical multi-body systems inspired by https://github
44

55
module PlanarMechanics
66

7+
import ModelingToolkitStandardLibrary.Mechanical.Rotational
8+
import ModelingToolkitStandardLibrary.Mechanical.TranslationalModelica
79
using ModelingToolkit, Symbolics, IfElse
810
using ...Blocks: RealInput, RealOutput
911
import ...@symcheck
10-
import ModelingToolkitStandardLibrary.Mechanical.Rotational
1112

1213
@parameters t
1314
D = Differential(t)
@@ -18,6 +19,6 @@ include("utils.jl")
1819
export Fixed, Body, FixedTranslation
1920
include("components.jl")
2021

21-
export Revolute
22+
export Revolute, Prismatic
2223
include("joints.jl")
2324
end

src/Mechanical/PlanarMechanics/components.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,6 @@ A fixed translation between two components (rigid rod)
138138
]
139139
end
140140

141-
# begin
142-
# l = norm([rx, ry])
143-
# end
144-
145141
@variables begin
146142
r0x(t), [description = "x-length of the rod resolved w.r.t to inertal frame"]
147143
r0y(t), [description = "y-length of the rod resolved w.r.t to inertal frame"]

src/Mechanical/PlanarMechanics/joints.jl

Lines changed: 98 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ A revolute joint
2525
@named partial_frames = PartialTwoFrames()
2626
@unpack frame_a, frame_b = partial_frames
2727
@named fixed = Rotational.Fixed()
28+
systems = [frame_a, frame_b, fixed]
2829

2930
if use_flange
30-
@named flange_a = Rotational.Flange(phi, tau)
31+
@named flange_a = Rotational.Flange(; phi, tau)
32+
push!(systems, flange_a)
3133
@named support = Rotational.Support()
34+
push!(systems, support)
3235
end
3336

3437
vars = @variables begin
@@ -41,7 +44,7 @@ A revolute joint
4144
eqs = [
4245
ω ~ D(phi),
4346
α ~ D(ω),
44-
# rigidly connect position
47+
# rigidly connect positions
4548
frame_a.x ~ frame_b.x,
4649
frame_a.y ~ frame_b.y,
4750
frame_a.phi + phi ~ frame_b.phi,
@@ -54,14 +57,105 @@ A revolute joint
5457
]
5558

5659
if use_flange
60+
push!(eqs, connect(fixed.flange, support))
61+
else
5762
# actutation torque
63+
push!(eqs, j ~ 0)
64+
end
65+
66+
pars = []
67+
68+
return compose(ODESystem(eqs, t, vars, pars; name = name),
69+
systems...)
70+
end
71+
72+
"""
73+
Prismatic(; name, rx, ry, f, s = 0, use_flange = false)
74+
A prismatic joint
75+
76+
# parameters
77+
- `rx`: [m] x-direction of the rod wrt. body system at phi=0
78+
- `ry`: [m] y-direction of the rod wrt. body system at phi=0
79+
- `ex`: [m] x-component of unit vector in direction of r
80+
- `ey`: [m] y-component of unit vector in direction of r
81+
- `f`: [N] Force in direction of elongation
82+
- `s`: [m] Elongation of the joint"
83+
- `use_flange=false`: If `true`, a force flange is enabled, otherwise implicitly grounded"
84+
85+
# states
86+
- `s(t)`: [m] Elongation of the joint
87+
- `v(t)`: [m/s] Velocity of elongation
88+
- `a(t)`: [m/s²] Acceleration of elongation
89+
- `e0x(t)`: [m] x-component of unit vector resolved w.r.t inertial frame
90+
- `e0y(t)`: [m] y-component of unit vector resolved w.r.t inertial frame
91+
- `r0x(t)`: [m] x-component of the rod resolved w.r.t to inertal frame
92+
- `r0y(t)`: [m] y-length of the rod resolved w.r.t to inertal frame
93+
- `cos_phi(t)`: [degree] cos(phi)
94+
- `sin_phi(t)`: [degree] sin(phi)
95+
96+
97+
# Connectors
98+
- `frame_a` [Frame](@ref)
99+
- `frame_b` [Frame](@ref)
100+
- `fixed` [Fixed](@ref) if `use_flange == false`
101+
- `flange_a` [Flange](@ref) if `use_flange == true`
102+
- `support` [Support](@ref) if `use_flange == true`
103+
"""
104+
@component function Prismatic(; name, rx, ry, ex, ey, f = 0, s = 0, use_flange = false)
105+
@named partial_frames = PartialTwoFrames()
106+
@unpack frame_a, frame_b = partial_frames
107+
@named fixed = TranslationalModelica.Support()
108+
systems = [frame_a, frame_b, fixed]
109+
110+
if use_flange
111+
@named flange_a = TranslationalModelica.Flange(; f, s)
112+
push!(systems, flange_a)
113+
@named support = TranslationalModelica.Support()
114+
push!(systems, support)
115+
end
116+
117+
vars = @variables begin
118+
s(t) = 0.0
119+
v(t) = 0.0
120+
a(t) = 0.0
121+
e0x(t)
122+
e0y(t)
123+
r0x(t)
124+
r0y(t)
125+
cos_phi(t)
126+
sin_phi(t)
127+
end
128+
129+
eqs = [
130+
v ~ D(s),
131+
a ~ D(v),
132+
# rigidly connect positions
133+
frame_a.x + rx ~ frame_b.x,
134+
frame_a.y + ry ~ frame_b.y,
135+
frame_a.phi ~ frame_b.phi,
136+
# balance forces
137+
frame_a.fx + frame_b.fx ~ 0,
138+
frame_a.fy + frame_b.fy ~ 0,
139+
# balance torques
140+
cos_phi ~ cos(frame_a.phi),
141+
sin_phi ~ sin(frame_a.phi),
142+
e0x ~ cos_phi * ex - sin_phi * ey,
143+
e0y ~ sin_phi * ex + cos_phi * ey,
144+
r0x ~ e0x * s,
145+
r0y ~ e0y * s,
146+
frame_a.j + frame_b.j + r0x * (frame_b.fy - frame_a.fy) - r0y * (frame_b.fx - frame_a.fx) ~ 0,
147+
frame_a.fx * e0y - frame_a.fy * e0x ~ f,
148+
]
149+
150+
if use_flange
58151
push!(eqs, connect(fixed.flange, support))
59152
else
60-
push!(eqs, j ~ phi)
153+
# actutation torque
154+
push!(eqs, f ~ 0)
61155
end
62156

63157
pars = []
64158

65159
return compose(ODESystem(eqs, t, vars, pars; name = name),
66-
frame_a, frame_b, fixed)
160+
systems...)
67161
end

src/Mechanical/TranslationalModelica/TranslationalModelica.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using ...Blocks: RealInput, RealOutput
99
@parameters t
1010
D = Differential(t)
1111

12-
export Flange
12+
export Flange, Support
1313
include("utils.jl")
1414

1515
export Fixed, Mass, Spring, Damper

test/Mechanical/planar_mechanics.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,11 @@ D = Differential(t)
2929
# phi and omega for the pendulum body
3030
@test length(states(sys)) == 2
3131
end
32+
33+
@testset "Prismatic" begin
34+
r = [1.0, 0.0]
35+
e = r / sqrt(r' * r)
36+
@named prismatic = Prismatic(rx = r[1], ry = r[2], ex = e[1], ey = e[2])
37+
# just testing instantiation
38+
@test true
39+
end

0 commit comments

Comments
 (0)