Skip to content

Commit 38407e7

Browse files
committed
switch torque variable to tau for consistency
1 parent 4c312f7 commit 38407e7

File tree

6 files changed

+43
-36
lines changed

6 files changed

+43
-36
lines changed

src/PlanarMechanics/PlanarMechanics.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ module PlanarMechanics
66

77
import ModelingToolkitStandardLibrary.Mechanical.Rotational
88
import ModelingToolkitStandardLibrary.Mechanical.TranslationalModelica
9+
import ModelingToolkitStandardLibrary.Blocks
910
using ModelingToolkit: t_nounits as t, D_nounits as D
1011
using ModelingToolkit
1112
using ...Blocks: RealInput, RealOutput
1213
import ...@symcheck
1314
import ..Multibody
1415

15-
export Frame, FrameResolve, PartialTwoFrames, ZeroPosition
16+
export Frame, FrameResolve, PartialTwoFrames, ZeroPosition, ori_2d
1617
include("utils.jl")
1718

1819
export Fixed, Body, FixedTranslation, Spring, Damper, SpringDamper

src/PlanarMechanics/components.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Body component with mass and inertia
4040
4141
# Parameters:
4242
- `m`: [kg] mass of the body
43-
- `j`: [kg.m²] inertia of the body with respect to the origin of `frame` along the z-axis of `frame`
43+
- `I`: [kg.m²] inertia of the body with respect to the origin of `frame` along the z-axis of `frame`
4444
- `r`: [m, m] Translational position x,y-position
4545
- `gy`: [m/s²] gravity field acting on the mass in the y-direction, positive value acts in the positive direction defaults to -9.807
4646
- `radius`: [m] Radius of the body in animations
@@ -71,13 +71,13 @@ Body component with mass and inertia
7171
end
7272

7373
vars = @variables begin
74-
f(t)[1:2]
75-
r(t)[1:2] = r
76-
v(t)[1:2]
77-
a(t)[1:2]
78-
phi(t) = phi
79-
ω(t)
80-
α(t)
74+
f(t)[1:2], [description = "Force"]
75+
(r(t)[1:2] = r), [description = "x,y position"]
76+
v(t)[1:2], [description = "x,y velocity"]
77+
a(t)[1:2], [description = "x,y acceleration"]
78+
(phi(t) = phi), [description = "Rotation angle"]
79+
ω(t), [description = "Angular velocity"]
80+
α(t), [description = "Angular acceleration"]
8181
end
8282

8383
eqs = [
@@ -92,7 +92,7 @@ Body component with mass and inertia
9292
# newton's law
9393
f .~ [frame.fx, frame.fy]
9494
f + [0, m*gy] .~ m*a#ifelse(gy !== nothing, fy / m + gy, fy / m),
95-
I * α ~ frame.j
95+
I * α ~ frame.tau
9696
]
9797

9898
return compose(ODESystem(eqs, t, vars, pars; name),
@@ -183,7 +183,7 @@ A fixed translation between two components (rigid rod)
183183
# balancing force including lever principle
184184
frame_a.fx + frame_b.fx ~ 0
185185
frame_a.fy + frame_b.fy ~ 0
186-
frame_a.j + frame_b.j + r0' * [frame_b.fy, -frame_b.fx] ~ 0
186+
frame_a.tau + frame_b.tau + r0' * [frame_b.fy, -frame_b.fx] ~ 0
187187
end
188188
end
189189

@@ -248,8 +248,8 @@ Linear 2D translational spring
248248

249249
@equations begin
250250
phi_rel ~ frame_b.phi - frame_a.phi
251-
frame_a.j ~ 0
252-
frame_b.j ~ 0
251+
frame_a.tau ~ 0
252+
frame_b.tau ~ 0
253253
s_relx ~ frame_b.x - frame_a.x
254254
s_rely ~ frame_b.y - frame_a.y
255255
f_x ~ c_x * (s_relx - s_relx0)
@@ -313,10 +313,10 @@ Linear (velocity dependent) damper
313313
d0y ~ ifelse(l < s_small, r0[2], r0[2] / l)
314314
frame_a.fx ~ d0x * f
315315
frame_a.fy ~ d0y * f
316-
frame_a.j ~ 0
316+
frame_a.tau ~ 0
317317
frame_a.fx + frame_b.fx ~ 0
318318
frame_a.fy + frame_b.fy ~ 0
319-
frame_a.j + frame_b.j ~ 0
319+
frame_a.tau + frame_b.tau ~ 0
320320

321321
# lossPower ~ -f * v
322322
end
@@ -382,7 +382,7 @@ Linear 2D translational spring damper model
382382
phi_rel(t) = 0
383383
f_x(t)
384384
f_y(t)
385-
j(t)
385+
tau(t)
386386
end
387387

388388
begin
@@ -399,9 +399,9 @@ Linear 2D translational spring damper model
399399
v_rely ~ D(s_rely)
400400
ω_rel ~ D(phi_rel)
401401

402-
j ~ c_phi * (phi_rel - phi_rel0) + d_phi * ω_rel
403-
frame_a.j ~ -j
404-
frame_b.j ~ j
402+
tau ~ c_phi * (phi_rel - phi_rel0) + d_phi * ω_rel
403+
frame_a.tau ~ -tau
404+
frame_b.tau ~ tau
405405
f_x ~ c_x * (s_relx - s_relx0) + d_x * v_relx
406406
f_y ~ c_y * (s_rely - s_rely0) + d_y * v_rely
407407
frame_a.fx ~ -f_x

src/PlanarMechanics/joints.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b70839146
3333
(phi(t) = 0.0), [state_priority=10]
3434
(ω(t) = 0.0), [state_priority=10]
3535
α(t)
36-
j(t)
36+
tau(t)
3737
end
3838

3939
pars = @parameters begin
@@ -53,8 +53,8 @@ https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b70839146
5353
frame_a.fx + frame_b.fx ~ 0,
5454
frame_a.fy + frame_b.fy ~ 0,
5555
# balance torques
56-
frame_a.j + frame_b.j ~ 0,
57-
frame_a.j ~ j
56+
frame_a.tau + frame_b.tau ~ 0,
57+
frame_a.tau ~ tau
5858
]
5959

6060
if use_flange
@@ -67,7 +67,7 @@ https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b70839146
6767
push!(eqs, connect(fixed.flange, support))
6868
else
6969
# actutation torque
70-
push!(eqs, j ~ 0)
70+
push!(eqs, tau ~ 0)
7171
end
7272

7373

@@ -143,7 +143,7 @@ https://github.com/dzimmer/PlanarMechanics/blob/743462f58858a808202be93b70839146
143143
frame_a.phi ~ frame_b.phi,
144144
frame_a.fx + frame_b.fx ~ 0,
145145
frame_a.fy + frame_b.fy ~ 0,
146-
frame_a.j + frame_b.j + r0[1] * frame_b.fy - r0[2] * frame_b.fx ~ 0,
146+
frame_a.tau + frame_b.tau + r0[1] * frame_b.fy - r0[2] * frame_b.fx ~ 0,
147147
e0[1] * frame_a.fx + e0[2] * frame_a.fy ~ f
148148
]
149149

src/PlanarMechanics/sensors.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ Partial absolute sensor models for sensors defined by equations (frame_resolve m
5050
# https://github.com/dzimmer/PlanarMechanics/blob/443b007bcc1522bb172f13012e2d7a8ecc3f7a9b/PlanarMechanics/Sensors/Internal/PartialAbsoluteBaseSensor.mo#L20-L21
5151
frame_a.fx ~ 0
5252
frame_a.fy ~ 0
53-
frame_a.j ~ 0
53+
frame_a.tau ~ 0
5454
frame_resolve.fx ~ 0
5555
frame_resolve.fy ~ 0
56-
frame_resolve.j ~ 0
56+
frame_resolve.tau ~ 0
5757
end
5858
end
5959

@@ -79,13 +79,13 @@ Partial relative sensor models for sensors defined by equations (frame_resolve m
7979

8080
frame_a.fx ~ 0
8181
frame_a.fy ~ 0
82-
frame_a.j ~ 0
82+
frame_a.tau ~ 0
8383
frame_b.fx ~ 0
8484
frame_b.fy ~ 0
85-
frame_b.j ~ 0
85+
frame_b.tau ~ 0
8686
frame_resolve.fx ~ 0
8787
frame_resolve.fy ~ 0
88-
frame_resolve.j ~ 0
88+
frame_resolve.tau ~ 0
8989
end
9090
end
9191

@@ -140,7 +140,7 @@ Measure absolute position and orientation (same as Sensors.AbsolutePosition, but
140140
phi.u ~ r[3],
141141
frame_a.fx ~ 0,
142142
frame_a.fy ~ 0,
143-
frame_a.j ~ 0
143+
frame_a.tau ~ 0
144144
]
145145

146146
return compose(ODESystem(eqs, t, [], []; name = name),
@@ -249,10 +249,10 @@ Measure relative position and orientation between the origins of two frame conne
249249
rel_phi.u ~ r[3],
250250
frame_a.fx ~ 0,
251251
frame_a.fy ~ 0,
252-
frame_a.j ~ 0,
252+
frame_a.tau ~ 0,
253253
frame_b.fx ~ 0,
254254
frame_b.fy ~ 0,
255-
frame_b.j ~ 0
255+
frame_b.tau ~ 0
256256
]
257257

258258
return compose(ODESystem(eqs, t, [], []; name = name),
@@ -330,10 +330,10 @@ end
330330
# https://github.com/dzimmer/PlanarMechanics/blob/443b007bcc1522bb172f13012e2d7a8ecc3f7a9b/PlanarMechanics/Sensors/Internal/BasicTransformAbsoluteVector.mo#L42-L43
331331
frame_a.fx ~ 0,
332332
frame_a.fy ~ 0,
333-
frame_a.j ~ 0,
333+
frame_a.tau ~ 0,
334334
frame_resolve.fx ~ 0,
335335
frame_resolve.fy ~ 0,
336-
frame_resolve.j ~ 0
336+
frame_resolve.tau ~ 0
337337
]
338338

339339
r_temp = Vector{Float64}(undef, 3)

src/PlanarMechanics/utils.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
phi(t), [state_priority=2, description = "rotation angle (counterclockwise)"]
55
fx(t), [connect = Flow, description = "force in the x direction"]
66
fy(t), [connect = Flow, description = "force in the y direction"]
7-
j(t), [connect = Flow, description = "torque (clockwise)"]
7+
tau(t), [connect = Flow, description = "torque (clockwise)"]
88
end
99
Base.@doc """
1010
Frame(;name)
@@ -17,9 +17,14 @@ Coordinate system (2-dim.) fixed to the component with one cut-force and cut-tor
1717
- `phi`: [rad] rotation angle (counterclockwise)
1818
- `fx`: [N] force in the x direction
1919
- `fy`: [N] force in the y direction
20-
- `j`: [N.m] torque (clockwise)
20+
- `tau`: [N.m] torque (clockwise)
2121
""" Frame
2222

23+
function ori_2d(frame)
24+
phi = frame.phi
25+
return [cos(phi) -sin(phi); sin(phi) cos(phi)]
26+
end
27+
2328
# extends Frame with just styling
2429
# https://github.com/dzimmer/PlanarMechanics/blob/master/PlanarMechanics/Interfaces/Frame_resolve.mo
2530
FrameResolve = Frame

test/test_PlanarMechanics.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# using Plots
33
using ModelingToolkit, OrdinaryDiffEq, Test
44
using ModelingToolkit: t_nounits as t, D_nounits as D
5+
import ModelingToolkitStandardLibrary.Blocks
56
import Multibody.PlanarMechanics as Pl
67
using JuliaSimCompiler
78

0 commit comments

Comments
 (0)