Skip to content

Commit 27887ac

Browse files
authored
Merge branch 'main' into analysis_points
2 parents cfb5aea + a8bb688 commit 27887ac

File tree

18 files changed

+512
-73
lines changed

18 files changed

+512
-73
lines changed

.github/workflows/Documentation.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@ jobs:
2121
env:
2222
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # For authentication with GitHub Actions token
2323
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # For authentication with SSH deploy key
24-
run: julia --project=docs/ docs/make.jl
24+
run: julia --project=docs/ --code-coverage=user docs/make.jl
25+
- uses: julia-actions/julia-processcoverage@v1
26+
- uses: codecov/codecov-action@v1
27+
with:
28+
file: lcov.info

.github/workflows/Invalidations.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Invalidations
2+
3+
on:
4+
pull_request:
5+
6+
concurrency:
7+
# Skip intermediate builds: always.
8+
# Cancel intermediate builds: always.
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
evaluate:
14+
# Only run on PRs to the default branch.
15+
# In the PR trigger above branches can be specified only explicitly whereas this check should work for master, main, or any other default branch
16+
if: github.base_ref == github.event.repository.default_branch
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: julia-actions/setup-julia@v1
20+
with:
21+
version: '1'
22+
- uses: actions/checkout@v3
23+
- uses: julia-actions/julia-buildpkg@v1
24+
- uses: julia-actions/julia-invalidations@v1
25+
id: invs_pr
26+
27+
- uses: actions/checkout@v3
28+
with:
29+
ref: ${{ github.event.repository.default_branch }}
30+
- uses: julia-actions/julia-buildpkg@v1
31+
- uses: julia-actions/julia-invalidations@v1
32+
id: invs_default
33+
34+
- name: Report invalidation counts
35+
run: |
36+
echo "Invalidations on default branch: ${{ steps.invs_default.outputs.total }} (${{ steps.invs_default.outputs.deps }} via deps)" >> $GITHUB_STEP_SUMMARY
37+
echo "This branch: ${{ steps.invs_pr.outputs.total }} (${{ steps.invs_pr.outputs.deps }} via deps)" >> $GITHUB_STEP_SUMMARY
38+
- name: Check if the PR does increase number of invalidations
39+
if: steps.invs_pr.outputs.total > steps.invs_default.outputs.total
40+
run: exit 1

Project.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,20 @@ version = "1.5.0"
77
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
88
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
99
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
10-
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
1110
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
1211

1312
[compat]
1413
IfElse = "0.1"
1514
ModelingToolkit = "8"
1615
OffsetArrays = "1"
17-
OrdinaryDiffEq = "5.56, 6"
18-
Symbolics = "0.1, 1, 2, 3, 4"
16+
Symbolics = "4.9"
1917
julia = "1.6"
2018

2119
[extras]
2220
ControlSystemsBase = "aaaaaaaa-a6ca-5380-bf3e-84a91bcd477e"
21+
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
2322
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
2423
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2524

2625
[targets]
27-
test = ["SafeTestsets", "Test", "ControlSystemsBase"]
26+
test = ["OrdinaryDiffEq", "SafeTestsets", "Test", "ControlSystemsBase"]

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# ModelingToolkitStandardLibrary.jl
22

3-
[![CI](https://github.com/SciML/ModelingToolkitStandardLibrary.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/SciML/ModelingToolkitStandardLibrary.jl/actions/workflows/CI.yml)
3+
[![Join the chat at https://julialang.zulipchat.com #sciml-bridged](https://img.shields.io/static/v1?label=Zulip&message=chat&color=9558b2&labelColor=389826)](https://julialang.zulipchat.com/#narrow/stream/279055-sciml-bridged)
44
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](http://mtkstdlib.sciml.ai/stable/)
5-
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](http://mtkstdlib.sciml.ai/dev/)
5+
[![Global Docs](https://img.shields.io/badge/docs-SciML-blue.svg)](https://docs.sciml.ai/dev/modules/ModelingToolkitStandardLibrary/)
6+
7+
[![codecov](https://codecov.io/gh/SciML/ModelingToolkitStandardLibrary.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/SciML/ModelingToolkitStandardLibrary.jl)
8+
[![Build Status](https://github.com/SciML/ModelingToolkitStandardLibrary.jl/workflows/CI/badge.svg)](https://github.com/SciML/ModelingToolkitStandardLibrary.jl/actions?query=workflow%3ACI)
9+
10+
[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac)
11+
[![SciML Code Style](https://img.shields.io/static/v1?label=code%20style&message=SciML&color=9558b2&labelColor=389826)](https://github.com/SciML/SciMLStyle)
612

713
The ModelingToolkit Standard Library is a standard library of components to model the world and beyond.
814

docs/src/API/mechanical.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,21 @@ Inertia
3434
Spring
3535
Damper
3636
IdealGear
37+
RotationalFriction
3738
```
3839

3940
### Rotational Sources
4041

4142
```@docs
4243
Torque
43-
```
44+
Speed
45+
```
46+
47+
### Rotational Sensors
48+
49+
```@docs
50+
AngleSensor
51+
SpeedSensor
52+
TorqueSensor
53+
RelSpeedSensor
54+
```

docs/src/tutorials/custom_component.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ connections = [
9999
connect(Ro.n, Gnd.g)
100100
]
101101
102-
@named model = ODESystem(connections, t, systems=[L, Ro, G, C1, C2, Nr])
102+
@named model = ODESystem(connections, t, systems=[L, Ro, G, C1, C2, Nr, Gnd])
103103
nothing # hide
104104
```
105105

src/Blocks/Blocks.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
The module `Blocks` contains common input-output components, referred to as blocks.
33
"""
44
module Blocks
5-
using ModelingToolkit, Symbolics, OrdinaryDiffEq
5+
using ModelingToolkit, Symbolics
66
using IfElse: ifelse
77

88
@parameters t

src/Blocks/continuous.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Critical damping corresponds to `d=1`, which yields the fastest step response wi
111111
112112
# Parameters:
113113
- `k`: Gain
114-
- `w`: Angular frequency
114+
- `w`: [`rad/s`] Angular frequency
115115
- `d`: Damping
116116
- `x_start`: Initial value of state (output)
117117
- `xd_start`: Initial value of derivative of state (output)
@@ -305,7 +305,7 @@ where the transfer function for the derivative includes additional filtering, se
305305
- `wd`: [0,1] Set-point weighting in the derivative part.
306306
- `Nd`: [1/s] Derivative limit, limits the derivative gain to Nd/Td. Reasonable values are ∈ [8, 20]. A higher value gives a better approximation of an ideal derivative at the expense of higher noise amplification.
307307
- `Ni`: `Ni*Ti` controls the time constant `Ta` of anti-windup tracking. A common (default) choice is `Ta = √(Ti*Td)` which is realized by `Ni = √(Td / Ti)`. Anti-windup can be effectively turned off by setting `Ni = Inf`.
308-
` `gains`: If `gains = true`, `Ti` and `Td` will be interpreted as gains with a fundamental PID transfer function on parallel form `ki=Ti, kd=Td, k + ki/s + kd*s`
308+
- `gains`: If `gains = true`, `Ti` and `Td` will be interpreted as gains with a fundamental PID transfer function on parallel form `ki=Ti, kd=Td, k + ki/s + kd*s`.
309309
310310
# Connectors:
311311
- `reference`
@@ -438,7 +438,7 @@ function StateSpace(; A, B, C, D = nothing, x_start = zeros(size(A, 1)), name)
438438
end
439439
@named input = RealInput(nin = nu)
440440
@named output = RealOutput(nout = ny)
441-
@variables x[1:nx](t) = x_start
441+
@variables x(t)[1:nx] = x_start
442442
# pars = @parameters A=A B=B C=C D=D # This is buggy
443443
eqs = [ # FIXME: if array equations work
444444
[Differential(t)(x[i]) ~ sum(A[i, k] * x[k] for k in 1:nx) +

src/Blocks/utils.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
if nin == 1
33
@variables u(t)=u_start [input = true]
44
else
5-
@variables u[1:nin](t)=u_start [input = true]
5+
@variables u(t)[1:nin]=u_start [input = true]
66
u = collect(u)
77
end
88
ODESystem(Equation[], t, [u...], []; name = name)
@@ -24,7 +24,7 @@ Connector with one input signal of type Real.
2424
if nout == 1
2525
@variables u(t)=u_start [output = true]
2626
else
27-
@variables u[1:nout](t)=u_start [output = true]
27+
@variables u(t)[1:nout]=u_start [output = true]
2828
u = collect(u)
2929
end
3030
ODESystem(Equation[], t, [u...], []; name = name)
@@ -45,7 +45,7 @@ Connector with one output signal of type Real.
4545
"""
4646
SISO(;name, u_start=0.0, y_start=0.0)
4747
48-
Single Input Single Output continuous control block.
48+
Single input single output (SISO) continuous system block.
4949
5050
# Parameters:
5151
- `u_start`: Initial value for the input
@@ -66,7 +66,7 @@ end
6666
"""
6767
MIMO(;name, nin=1, nout=1, u_start=zeros(nin), y_start=zeros(nout))
6868
69-
Base class for a multiple Input multiple Output continuous control block.
69+
Base class for a multiple input multiple output (MIMO) continuous system block.
7070
7171
# Parameters:
7272
- `nin`: Input dimension
@@ -78,8 +78,8 @@ function MIMO(; name, nin = 1, nout = 1, u_start = zeros(nin), y_start = zeros(n
7878
@named input = RealInput(nin = nin, u_start = u_start)
7979
@named output = RealOutput(nout = nout, u_start = y_start)
8080
@variables begin
81-
u[1:nin](t) = u_start
82-
y[1:nout](t) = y_start
81+
u(t)[1:nin] = u_start
82+
y(t)[1:nout] = y_start
8383
end
8484
eqs = [
8585
[u[i] ~ input.u[i] for i in 1:nin]...,

src/Electrical/Electrical.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This library contains electrical components to build up analog circuits.
44
"""
55
module Electrical
66

7-
using ModelingToolkit, Symbolics, IfElse, OrdinaryDiffEq
7+
using ModelingToolkit, Symbolics, IfElse
88
using OffsetArrays
99

1010
@parameters t

src/Mechanical/Rotational/Rotational.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@ Library to model 1-dimensional, rotational mechanical systems
33
"""
44
module Rotational
55

6-
using ModelingToolkit, Symbolics, IfElse, OrdinaryDiffEq
6+
using ModelingToolkit, Symbolics, IfElse
77
using ...Blocks: RealInput, RealOutput
88

99
@parameters t
1010
D = Differential(t)
1111

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

15-
export Fixed, Inertia, Spring, Damper, IdealGear
15+
export Fixed, Inertia, Spring, Damper, IdealGear, RotationalFriction
1616
include("components.jl")
1717

18-
export Torque
18+
export Torque, Speed
1919
include("sources.jl")
2020

21+
export AngleSensor, SpeedSensor, TorqueSensor, RelSpeedSensor
22+
include("sensors.jl")
23+
2124
end

src/Mechanical/Rotational/components.jl

Lines changed: 87 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
44
Flange fixed in housing at a given angle.
55
6+
# Connectors:
7+
- `flange` [Flange](@ref)
8+
69
# Parameters:
7-
- `phi0`: [rad] Fixed offset angle of housing
10+
- `phi0`: [`rad`] Fixed offset angle of housing
811
"""
912
function Fixed(; name, phi0 = 0.0)
1013
@named flange = Flange()
@@ -18,16 +21,20 @@ end
1821
1922
1D-rotational component with inertia.
2023
21-
# Parameters:
22-
- `J`: [kg·m²] Moment of inertia
23-
- `phi_start`: [rad] Initial value of absolute rotation angle of component
24-
- `w_start`: [rad/s] Initial value of absolute angular velocity of component
25-
- `a_start`: [rad/s²] Initial value of absolute angular acceleration of component
26-
2724
# States:
28-
- `phi`: [rad] Absolute rotation angle of component
29-
- `w`: [rad/s] Absolute angular velocity of component (= der(phi))
30-
- `a`: [rad/s²] Absolute angular acceleration of component (= der(w))
25+
- `phi`: [`rad`] Absolute rotation angle of component
26+
- `w`: [`rad/s`] Absolute angular velocity of component (= D(phi))
27+
- `a`: [`rad/s²`] Absolute angular acceleration of component (= D(w))
28+
29+
# Connectors:
30+
- `flange_a` [Flange](@ref) Left flange
31+
- `flange_b` [Flange](@ref) Right flange
32+
33+
# Parameters:
34+
- `J`: [`kg·m²`] Moment of inertia
35+
- `phi_start`: [`rad`] Initial value of absolute rotation angle of component
36+
- `w_start`: [`rad/s`] Initial value of absolute angular velocity of component
37+
- `a_start`: [`rad/s²`] Initial value of absolute angular acceleration of component
3138
"""
3239
function Inertia(; name, J, phi_start = 0.0, w_start = 0.0, a_start = 0.0)
3340
@named flange_a = Flange()
@@ -51,9 +58,17 @@ end
5158
5259
Linear 1D rotational spring
5360
61+
# States:
62+
- `phi_rel(t)`: [`rad`] Relative rotation angle (`flange_b.phi - flange_a.phi`)
63+
- `tau(t)`: [`N.m`] Torque between flanges (`flange_b.tau`)
64+
65+
# Connectors:
66+
- `flange_a` [Flange](@ref)
67+
- `flange_b` [Flange](@ref)
68+
5469
# Parameters:
55-
- `c`: [N.m/rad] Spring constant
56-
- `phi_rel0`: Unstretched spring angle
70+
- `c`: [`N.m/rad`] Spring constant
71+
- `phi_rel0`: [`rad`] Unstretched spring angle
5772
"""
5873
function Spring(; name, c, phi_rel0 = 0.0)
5974
@named partial_comp = PartialCompliant()
@@ -71,8 +86,18 @@ end
7186
7287
Linear 1D rotational damper
7388
89+
# States:
90+
- `phi_rel(t)`: [`rad`] Relative rotation angle (= flange_b.phi - flange_a.phi)
91+
- `w_rel(t)`: [`rad/s`] Relative angular velocity (= D(phi_rel))
92+
- `a_rel(t)`: [`rad/s²`] Relative angular acceleration (= D(w_rel))
93+
- `tau(t)`: [`N.m`] Torque between flanges (= flange_b.tau)
94+
95+
# Connectors:
96+
- `flange_a` [Flange](@ref)
97+
- `flange_b` [Flange](@ref)
98+
7499
# Parameters:
75-
- `d`: [N.m.s/rad] Damping constant
100+
- `d`: [`N.m.s/rad`] Damping constant
76101
"""
77102
function Damper(; name, d)
78103
@named partial_comp = PartialCompliantWithRelativeStates()
@@ -89,6 +114,15 @@ Ideal gear without inertia.
89114
90115
This element characterizes any type of gear box which is fixed in the ground and which has one driving shaft and one driven shaft.
91116
117+
# States:
118+
- `phi_a(t)`: [`rad`] Relative angle between shaft a and the support
119+
- `phi_b(t)`: [`rad`] Relative angle between shaft b and the support
120+
121+
# Connectors:
122+
- `flange_a` [Flange](@ref)
123+
- `flange_b` [Flange](@ref)
124+
- `support` [Support](@ref) if `use_support == true`
125+
92126
# Parameters:
93127
- `ratio`: Transmission ratio (flange_a.phi/flange_b.phi)
94128
- `use_support`: If support flange enabled, otherwise implicitly grounded
@@ -104,3 +138,43 @@ function IdealGear(; name, ratio, use_support = false)
104138
0 ~ ratio * flange_a.tau + flange_b.tau]
105139
extend(ODESystem(eqs, t, sts, [ratio]; name = name), partial_element)
106140
end
141+
142+
"""
143+
RotationalFriction(;name, f, tau_c, w_brk, tau_brk)
144+
145+
Models rotational friction with Stribeck effect, Coulomb friction and viscous friction between the two flanges.
146+
The friction torque is a function of the relative angular velocity between flange_a and flange_b.
147+
148+
Friction model: "Armstrong, B. and C.C. de Wit, Friction Modeling and Compensation, The Control Handbook, CRC Press, 1995."
149+
150+
# States:
151+
- `phi_rel(t)`: [`rad`] Relative rotation angle (= flange_b.phi - flange_a.phi)
152+
- `w_rel(t)`: [`rad/s`] Relative angular velocity (= D(phi_rel))
153+
- `a_rel(t)`: [`rad/s²`] Relative angular acceleration (= D(w_rel))
154+
- `tau(t)`: [`N.m`] Torque between flanges (= flange_b.tau)
155+
156+
# Connectors:
157+
- `flange_a` [Flange](@ref)
158+
- `flange_b` [Flange](@ref)
159+
160+
# Parameters:
161+
- `f`: [`N⋅m/(rad/s)`] Viscous friction coefficient
162+
- `tau_c`: [`N⋅m`] Coulomb friction torque
163+
- `w_brk`: [`rad/s`] Breakaway friction velocity
164+
- `tau_brk`: [`N⋅m`] Breakaway friction torque
165+
"""
166+
function RotationalFriction(; name, f, tau_c, w_brk, tau_brk)
167+
@named partial_comp = PartialCompliantWithRelativeStates()
168+
@unpack w_rel, tau = partial_comp
169+
pars = @parameters f=f tau_c=tau_c w_brk=w_brk tau_brk=tau_brk
170+
171+
str_scale = sqrt(2 * exp(1)) * (tau_brk - tau_c)
172+
w_st = w_brk * sqrt(2)
173+
w_coul = w_brk / 10
174+
175+
eqs = [
176+
tau ~ str_scale * (exp(-(w_rel / w_st)^2) * w_rel / w_st) +
177+
tau_c * tanh(w_rel / w_coul) + f * w_rel, # Stribeck friction + Coulomb friction + Viscous friction
178+
]
179+
extend(ODESystem(eqs, t, [], pars; name = name), partial_comp)
180+
end

0 commit comments

Comments
 (0)