-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add translational library #85
Changes from 3 commits
f43ff5e
28bbdb8
9b58673
f48821d
d4020e1
2f6bb42
68a81ab
4fbee98
c8c29a2
ae11458
6f4bd5a
02e3a6b
9476eba
af6e08f
f7f188e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "julia", | ||
"request": "launch", | ||
"name": "Run active Julia file", | ||
"program": "${file}", | ||
"stopOnEntry": false, | ||
"cwd": "${workspaceFolder}", | ||
"juliaEnv": "${command:activeJuliaEnvironment}" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,21 @@ | ||||||
""" | ||||||
Library to model 1-dimensional, translational mechanical systems | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
""" | ||||||
module Translational | ||||||
|
||||||
using ModelingToolkit, Symbolics, IfElse, OrdinaryDiffEq | ||||||
using ...Blocks: RealInput, RealOutput | ||||||
|
||||||
@parameters t | ||||||
D = Differential(t) | ||||||
|
||||||
export Flange | ||||||
include("utils.jl") | ||||||
|
||||||
export Fixed, Mass, Spring, Damper, IdealGear | ||||||
include("components.jl") | ||||||
|
||||||
export Force | ||||||
include("sources.jl") | ||||||
|
||||||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
""" | ||
Fixed(;name, s0=0.0) | ||
|
||
Flange fixed in housing at a given position. | ||
|
||
# Parameters: | ||
- `s0`: [m] Fixed offset position of housing | ||
""" | ||
function Fixed(;name, s0=0.0) | ||
@named flange = Flange() | ||
@parameters s0=s0 | ||
eqs = [flange.s ~ s0] | ||
return compose(ODESystem(eqs, t, [], [s0]; name=name), flange) | ||
end | ||
|
||
""" | ||
Mass(;name, m, s_start=0.0, v_start=0.0, a_start=0.0) | ||
|
||
Sliding mass with inertia | ||
|
||
# Parameters: | ||
- `m`: [kg] Mass of sliding mass | ||
- `s_start`: [m] Initial value of absolute position of sliding mass | ||
- `v_start`: [m/s] Initial value of absolute linear velocity of sliding mass | ||
- `a_start`: [m/s²] Initial value of absolute linear acceleration of sliding mass | ||
|
||
# States: | ||
- `s`: [m] Absolute position of sliding mass | ||
- `v`: [m/s] Absolute linear velocity of sliding mass (= der(s)) | ||
- `a`: [m/s²] Absolute linear acceleration of sliding mass (= der(v)) | ||
""" | ||
function Mass(;name, m, s_start=0.0, v_start=0.0, a_start=0.0) | ||
@named flange_a = Flange() | ||
@named flange_b = Flange() | ||
@parameters m=m | ||
sts = @variables begin | ||
s(t)=s_start | ||
v(t)=v_start | ||
a(t)=a_start | ||
end | ||
eqs = [ | ||
s ~ flange_a.s | ||
s ~ flange_b.s | ||
D(s) ~ v | ||
D(v) ~ a | ||
m*a ~ flange_a.f + flange_b.f | ||
] | ||
return compose(ODESystem(eqs, t, sts, [m]; name=name), flange_a, flange_b) | ||
end | ||
|
||
""" | ||
Spring(;name, c, s_rel0=0.0) | ||
|
||
Linear 1D translational spring | ||
|
||
# Parameters: | ||
- `c`: [N/m] Spring constant | ||
- `s_rel0`: Unstretched spring length | ||
""" | ||
function Spring(;name, c, s_rel0=0.0) | ||
@named partial_comp = PartialCompliant() | ||
@unpack s_rel, f = partial_comp | ||
pars = @parameters begin | ||
c=c | ||
s_rel0=s_rel0 | ||
end | ||
eqs = [f ~ c*(s_rel - s_rel0)] | ||
extend(ODESystem(eqs, t, [], pars; name=name), partial_comp) | ||
end | ||
|
||
""" | ||
Damper(;name, d) | ||
|
||
Linear 1D translational damper | ||
|
||
# Parameters: | ||
- `d`: [N.s/m] Damping constant | ||
""" | ||
function Damper(;name, d) | ||
@named partial_comp = PartialCompliantWithRelativeStates() | ||
@unpack v_rel, f = partial_comp | ||
pars = @parameters d=d | ||
eqs = [f ~ d*v_rel] | ||
extend(ODESystem(eqs, t, [], pars; name=name), partial_comp) | ||
end | ||
|
||
# function IdealGear(; name, ratio, use_support=false) | ||
# @named partial_element = PartialElementaryTwoFlangesAndSupport2(use_support=use_support) | ||
# @unpack s_support, flange_a, flange_b = partial_element | ||
# @parameters ratio = ratio | ||
# sts = @variables s_a(t) = 0.0 s_b(t) = 0.0 | ||
# eqs = [ | ||
# s_a ~ flange_a.s - s_support | ||
# s_b ~ flange_b.s - s_support | ||
# s_a ~ ratio * s_b | ||
# 0 ~ ratio * flange_a.f + flange_b.f | ||
# ] | ||
# extend(ODESystem(eqs, t, sts, [ratio]; name=name), partial_element) | ||
# end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
""" | ||
Force(;name) | ||
|
||
Input signal acting as external force on a flange | ||
""" | ||
function Force(;name, use_support=false) | ||
@named partial_element = PartialElementaryOneFlangeAndSupport2(use_support=use_support) | ||
@unpack flange = partial_element | ||
@named f = RealInput() # Accelerating force acting at flange (= -flange.tau) | ||
eqs = [flange.f ~ -f.u] | ||
return extend(ODESystem(eqs, t, [], []; name=name, systems=[f]), partial_element) | ||
end |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,154 @@ | ||||||
@connector function Flange(;name) | ||||||
sts = @variables begin | ||||||
s(t) | ||||||
f(t), [connect=Flow] | ||||||
end | ||||||
ODESystem(Equation[], t, sts, [], name=name, defaults=Dict(s=>0.0, f=>0.0)) | ||||||
end | ||||||
Base.@doc """ | ||||||
Flange(;name) | ||||||
|
||||||
1-dim. translational flange of a shaft. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
# States: | ||||||
- `s`: [m] Absolute position of flange | ||||||
- `f`: [N] Cut force in the flange | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
""" Flange | ||||||
|
||||||
@connector function Support(;name) | ||||||
sts = @variables begin | ||||||
s(t) | ||||||
f(t), [connect=Flow] | ||||||
end | ||||||
ODESystem(Equation[], t, sts, [], name=name, defaults=Dict(s=>0.0, f=>0.0)) | ||||||
end | ||||||
Base.@doc """ | ||||||
Support(;name) | ||||||
|
||||||
Support/housing of a 1-dim. translational shaft | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
# States: | ||||||
- `s`: [m] Absolute position of the support/housing | ||||||
- `f`: [N] Reaction force in the support/housing | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
""" Support | ||||||
|
||||||
""" | ||||||
PartialCompliant(;name, s_rel_start=0.0, f_start=0.0) | ||||||
|
||||||
Partial model for the compliant connection of two translational 1-dim. shaft flanges. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
# Parameters: | ||||||
- `s_rel_start`: [m] Initial relative distance | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
- `f_start`: [N] Initial force between flanges | ||||||
|
||||||
# States: | ||||||
- `s_rel`: [m] Relative distance (= flange_b.s - flange_a.s) | ||||||
- `f`: [N] Force between flanges (= flange_b.f) | ||||||
""" | ||||||
function PartialCompliant(;name, s_rel_start=0.0, f_start=0.0) | ||||||
@named flange_a = Flange() | ||||||
@named flange_b = Flange() | ||||||
sts = @variables begin | ||||||
s_rel(t)=s_rel_start | ||||||
f(t)=f_start | ||||||
end | ||||||
eqs = [ | ||||||
s_rel ~ flange_b.s - flange_a.s | ||||||
flange_b.f ~ f | ||||||
flange_a.f ~ -f | ||||||
] | ||||||
return compose(ODESystem(eqs, t, sts, []; name=name), flange_a, flange_b) | ||||||
end | ||||||
|
||||||
""" | ||||||
PartialCompliantWithRelativeStates(;name, s_rel_start=0.0, v_rel_start=0.0, a_rel_start=0.0, f_start=0.0) | ||||||
|
||||||
Partial model for the compliant connection of two translational 1-dim. shaft flanges where the relative position and speed are used as preferred states | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
# Parameters: | ||||||
- `s_rel_start`: [m] Initial relative distance | ||||||
- `v_rel_start`: [m/s] Initial relative linear velocity (= der(s_rel)) | ||||||
- `a_rel_start`: [m/s²] Initial relative linear acceleration (= der(v_rel)) | ||||||
- `f_start`: [N] Initial force between flanges | ||||||
|
||||||
# States: | ||||||
- `s_rel`: [m] Relative distance (= flange_b.phi - flange_a.phi) | ||||||
- `v_rel`: [m/s] Relative linear velocity (= der(s_rel)) | ||||||
- `a_rel`: [m/s²] Relative linear acceleration (= der(v_rel)) | ||||||
- `f`: [N] Force between flanges (= flange_b.f) | ||||||
""" | ||||||
function PartialCompliantWithRelativeStates(;name, s_rel_start=0.0, v_rel_start=0.0, a_rel_start=0.0, f_start=0.0) | ||||||
@named flange_a = Flange() | ||||||
@named flange_b = Flange() | ||||||
sts = @variables begin | ||||||
s_rel(t)=s_rel_start | ||||||
v_rel(t)=v_rel_start | ||||||
a_rel(t)=a_rel_start | ||||||
f(t)=f_start | ||||||
end | ||||||
eqs = [ | ||||||
s_rel ~ flange_b.s - flange_a.s | ||||||
D(s_rel) ~ v_rel | ||||||
D(v_rel) ~ a_rel | ||||||
flange_b.f ~ f | ||||||
flange_a.f ~ -f | ||||||
] | ||||||
return compose(ODESystem(eqs, t, sts, []; name=name), flange_a, flange_b) | ||||||
end | ||||||
|
||||||
""" | ||||||
PartialElementaryOneFlangeAndSupport2(;name, use_support=false) | ||||||
|
||||||
Partial model for a component with one translational 1-dim. shaft flange and a support used for textual modeling, i.e., for elementary models | ||||||
|
||||||
# Parameters: | ||||||
- `use_support`: If support flange enabled, otherwise implicitly grounded | ||||||
|
||||||
# States: | ||||||
- `s_support`: [m] Absolute position of support flange" | ||||||
""" | ||||||
function PartialElementaryOneFlangeAndSupport2(;name, use_support=false) | ||||||
@named flange = Flange() | ||||||
sys = [flange] | ||||||
@variables s_support(t) | ||||||
if use_support | ||||||
@named support = Support() | ||||||
eqs = [ | ||||||
support.s ~ s_support | ||||||
support.f ~ -flange.f | ||||||
] | ||||||
push!(sys, support) | ||||||
else | ||||||
eqs = [s_support ~ 0] | ||||||
end | ||||||
return compose(ODESystem(eqs, t, [s_support], []; name=name), sys) | ||||||
end | ||||||
|
||||||
""" | ||||||
PartialElementaryTwoFlangesAndSupport2(;name, use_support=false) | ||||||
|
||||||
Partial model for a component with two translational 1-dim. shaft flanges and a support used for textual modeling, i.e., for elementary models | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
# Parameters: | ||||||
- `use_support`: If support flange enabled, otherwise implicitly grounded | ||||||
|
||||||
# States: | ||||||
- `s_support`: [m] Absolute position of support flange" | ||||||
""" | ||||||
function PartialElementaryTwoFlangesAndSupport2(;name, use_support=false) | ||||||
@named flange_a = Flange() | ||||||
@named flange_b = Flange() | ||||||
sys = [flange_a, flange_b] | ||||||
@variables s_support(t)=0.0 | ||||||
if use_support | ||||||
@named support = Support() | ||||||
eqs = [ | ||||||
support.s ~ s_support | ||||||
support.f ~ -flange_a.f - flange_b.f | ||||||
] | ||||||
push!(sys, support) | ||||||
else | ||||||
eqs = [s_support ~ 0] | ||||||
end | ||||||
return compose(ODESystem(eqs, t, [s_support], []; name=name), sys) | ||||||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add
.vscode
and.DS_Store
in global git ignore setting. Check out https://sebastiandedeyne.com/setting-up-a-global-gitignore-file/