Skip to content

Commit f03388b

Browse files
Refactor Prismatic
1 parent 8a41225 commit f03388b

2 files changed

Lines changed: 27 additions & 38 deletions

File tree

src/Mechanical/PlanarMechanics/joints.jl

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,17 @@ end
7878
A prismatic joint
7979
8080
# parameters
81-
- `rx`: [m] x-direction of the rod wrt. body system at phi=0
82-
- `ry`: [m] y-direction of the rod wrt. body system at phi=0
83-
- `ex`: [m] x-component of unit vector in direction of r
84-
- `ey`: [m] y-component of unit vector in direction of r
85-
- `f`: [N] Force in direction of elongation
86-
- `s`: [m] Elongation of the joint"
81+
- `x`: [m] x-direction of the rod wrt. body system at phi=0
82+
- `y`: [m] y-direction of the rod wrt. body system at phi=0
83+
- `constant_f`: [N] Constant force in direction of elongation
84+
- `constant_s`: [m] Constant elongation of the joint"
8785
- `use_flange=false`: If `true`, a force flange is enabled, otherwise implicitly grounded"
8886
8987
# states
9088
- `s(t)`: [m] Elongation of the joint
9189
- `v(t)`: [m/s] Velocity of elongation
9290
- `a(t)`: [m/s²] Acceleration of elongation
93-
- `e0x(t)`: [m] x-component of unit vector resolved w.r.t inertial frame
94-
- `e0y(t)`: [m] y-component of unit vector resolved w.r.t inertial frame
95-
- `r0x(t)`: [m] x-component of the rod resolved w.r.t to inertal frame
96-
- `r0y(t)`: [m] y-length of the rod resolved w.r.t to inertal frame
97-
- `cos_phi(t)`: [degree] cos(phi)
98-
- `sin_phi(t)`: [degree] sin(phi)
99-
91+
- `f(t)`: [N] Force in direction of elongation
10092
10193
# Connectors
10294
- `frame_a` [Frame](@ref)
@@ -105,14 +97,20 @@ A prismatic joint
10597
- `flange_a` [Flange](@ref) if `use_flange == true`
10698
- `support` [Support](@ref) if `use_flange == true`
10799
"""
108-
@component function Prismatic(; name, rx, ry, ex, ey, f = 0, s = 0, use_flange = false)
100+
@component function Prismatic(;
101+
name,
102+
x,
103+
y,
104+
constant_f = 0,
105+
constant_s = 0,
106+
use_flange = false)
109107
@named partial_frames = PartialTwoFrames()
110108
@unpack frame_a, frame_b = partial_frames
111109
@named fixed = TranslationalModelica.Support()
112110
systems = [frame_a, frame_b, fixed]
113111

114112
if use_flange
115-
@named flange_a = TranslationalModelica.Flange(; f, s)
113+
@named flange_a = TranslationalModelica.Flange(; f = constant_f, constant_s)
116114
push!(systems, flange_a)
117115
@named support = TranslationalModelica.Support()
118116
push!(systems, support)
@@ -122,40 +120,34 @@ A prismatic joint
122120
s(t) = 0.0
123121
v(t) = 0.0
124122
a(t) = 0.0
125-
e0x(t)
126-
e0y(t)
127-
r0x(t)
128-
r0y(t)
129-
cos_phi(t)
130-
sin_phi(t)
123+
f(t) = 0.0
131124
end
132125

126+
R = [cos(frame_a.phi) -sin(frame_a.phi);
127+
sin(frame_a.phi) cos(frame_a.phi)]
128+
e0 = R * [x, y]
129+
r0 = e0 * s
130+
133131
eqs = [
132+
ifelse(constant_s === nothing, s ~ s, s ~ constant_s),
133+
ifelse(constant_f === nothing, f ~ f, f ~ constant_f),
134134
v ~ D(s),
135135
a ~ D(v),
136136
# rigidly connect positions
137-
frame_a.x + rx ~ frame_b.x,
138-
frame_a.y + ry ~ frame_b.y,
137+
frame_a.x + r0[1] ~ frame_b.x,
138+
frame_a.y + r0[2] ~ frame_b.y,
139139
frame_a.phi ~ frame_b.phi,
140-
# balance forces
141140
frame_a.fx + frame_b.fx ~ 0,
142141
frame_a.fy + frame_b.fy ~ 0,
143-
# balance torques
144-
cos_phi ~ cos(frame_a.phi),
145-
sin_phi ~ sin(frame_a.phi),
146-
e0x ~ cos_phi * ex - sin_phi * ey,
147-
e0y ~ sin_phi * ex + cos_phi * ey,
148-
r0x ~ e0x * s,
149-
r0y ~ e0y * s,
150-
frame_a.j + frame_b.j + r0x * (frame_b.fy - frame_a.fy) - r0y * (frame_b.fx - frame_a.fx) ~ 0,
151-
frame_a.fx * e0y - frame_a.fy * e0x ~ f,
142+
frame_a.j + frame_b.j + r0[1] * frame_b.fy - r0[2] * frame_b.fx ~ 0,
143+
e0[1] * frame_a.fx + e0[2] * frame_a.fy ~ f,
152144
]
153145

154146
if use_flange
155147
push!(eqs, connect(fixed.flange, support))
156148
else
157149
# actutation torque
158-
push!(eqs, f ~ 0)
150+
push!(eqs, constant_f ~ 0)
159151
end
160152

161153
pars = []

test/Mechanical/planar_mechanics.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,8 @@ end
5353
end
5454

5555
@testset "Prismatic" begin
56-
r = [1.0, 0.0]
57-
e = r / sqrt(r' * r)
58-
@named prismatic = Prismatic(rx = r[1], ry = r[2], ex = e[1], ey = e[2])
5956
# just testing instantiation
60-
@test true
57+
@test_nowarn @named prismatic = Prismatic(x = 1.0, y = 0.0)
6158
end
6259

6360
@testset "AbsoluteAccCentrifugal" begin

0 commit comments

Comments
 (0)