Skip to content
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

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
Copy link
Member

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/

// 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}"
}
]
}
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/Mechanical/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions src/Mechanical/Mechanical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Mechanical
using ModelingToolkit

include("Rotational/Rotational.jl")
include("Translational/Translational.jl")

end

21 changes: 21 additions & 0 deletions src/Mechanical/Translational/Translational.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
Library to model 1-dimensional, translational mechanical systems
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Library to model 1-dimensional, translational mechanical systems
Library to model 1-dimensional, translational mechanical components.

"""
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
99 changes: 99 additions & 0 deletions src/Mechanical/Translational/components.jl
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
12 changes: 12 additions & 0 deletions src/Mechanical/Translational/sources.jl
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
154 changes: 154 additions & 0 deletions src/Mechanical/Translational/utils.jl
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1-dim. translational flange of a shaft.
1-dim. translational flange.


# States:
- `s`: [m] Absolute position of flange
- `f`: [N] Cut force in the flange
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `f`: [N] Cut force in the flange
- `f`: [N] Cut force into the flange

""" 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Support/housing of a 1-dim. translational shaft
Support/housing 1-dim. translational flange.


# States:
- `s`: [m] Absolute position of the support/housing
- `f`: [N] Reaction force in the support/housing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `f`: [N] Reaction force in the support/housing
- `f`: [N] Cut force into the flange

""" 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Partial model for the compliant connection of two translational 1-dim. shaft flanges.
Partial model for the compliant connection of two translational 1-dim. flanges.


# Parameters:
- `s_rel_start`: [m] Initial relative distance
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `s_rel_start`: [m] Initial relative distance
- `s_rel_start`: [m] Initial relative distance between the flanges

- `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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Partial model for the compliant connection of two translational 1-dim. shaft flanges where the relative position and speed are used as preferred states
Partial model for the compliant connection of two translational 1-dim. flanges.


# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Partial model for a component with two translational 1-dim. shaft flanges and a support used for textual modeling, i.e., for elementary models
Partial model for a component with two translational 1-dim. flanges 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 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
Binary file added test/.DS_Store
Binary file not shown.
Binary file added test/Mechanical/.DS_Store
Binary file not shown.
Loading