Skip to content

Commit 56d6e69

Browse files
adds connectors to doc strings
1 parent a242952 commit 56d6e69

File tree

6 files changed

+177
-17
lines changed

6 files changed

+177
-17
lines changed

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, IfElse, OrdinaryDiffEq
5+
using ModelingToolkit, Symbolics, OrdinaryDiffEq
66
using IfElse: ifelse
77

88
@parameters t

src/Blocks/continuous.jl

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Integrator(;name, k=1, x_start=0.0)
33
44
Outputs `y = ∫k*u dt`, corresponding to the transfer function `1/s`.
5+
6+
# Connectors:
7+
- `input`
8+
- `output`
59
"""
610
function Integrator(;name, k=1, x_start=0.0)
711
@named siso = SISO()
@@ -34,6 +38,10 @@ A smaller `T` leads to a more ideal approximation of the derivative.
3438
- `k`: Gain
3539
- `T`: [s] Time constants (T>0 required; T=0 is ideal derivative block)
3640
- `x_start`: Initial value of state
41+
42+
# Connectors:
43+
- `input`
44+
- `output`
3745
"""
3846
function Derivative(; name, k=1, T, x_start=0.0)
3947
T > 0 || throw(ArgumentError("Time constant `T` has to be strictly positive"))
@@ -63,6 +71,10 @@ sT + 1
6371
- `k`: Gain
6472
- `T`: [s] Time constants (T>0 required)
6573
- `x_start`: Initial value of state
74+
75+
# Connectors:
76+
- `input`
77+
- `output`
6678
"""
6779
function FirstOrder(; name, k=1, T, x_start=0.0)
6880
T > 0 || throw(ArgumentError("Time constant `T` has to be strictly positive"))
@@ -96,6 +108,10 @@ Critical damping corresponds to `d=1`, which yields the fastest step response wi
96108
- `d`: Damping
97109
- `x_start`: Initial value of state (output)
98110
- `xd_start`: Initial value of derivative of state (output)
111+
112+
# Connectors:
113+
- `input`
114+
- `output`
99115
"""
100116
function SecondOrder(; name, k=1, w, d, x_start=0.0, xd_start=0.0)
101117
@named siso = SISO()
@@ -119,6 +135,10 @@ Textbook version of a PI-controller without actuator saturation and anti-windup
119135
- `k`: Gain
120136
- `T`: [s] Integrator time constant (T>0 required)
121137
- `x_start`: Initial value for the integrator
138+
139+
# Connectors:
140+
- `err_input`
141+
- `ctr_output`
122142
"""
123143
function PI(;name, k=1, T, x_start=0.0)
124144
T > 0 || throw(ArgumentError("Time constant `T` has to be strictly positive"))
@@ -150,6 +170,10 @@ Text-book version of a PID-controller without actuator saturation and anti-windu
150170
- `Nd`: [s] Time constant for the derivative approximation (Nd>0 required; Nd=0 is ideal derivative).
151171
- `x_start`: Initial value for the integrator.
152172
- `xd_start`: Initial value for the derivative state.
173+
174+
# Connectors:
175+
- `err_input`
176+
- `ctr_output`
153177
"""
154178
function PID(;name, k=1, Ti=false, Td=false, Nd=10, xi_start=0, xd_start=0)
155179
with_I = !isequal(Ti, false)
@@ -215,6 +239,10 @@ Text-book version of a PI-controller with actuator saturation and anti-windup me
215239
- `T`: [s] Integrator time constant (T>0 required)
216240
- `Ta`: [s] Tracking time constant (Ta>0 required)
217241
- `x_start`: Initial value for the integrator
242+
243+
# Connectors:
244+
- `err_input`
245+
- `ctr_output`
218246
"""
219247
function LimPI(;name, k=1, T, u_max=1, u_min=-u_max, Ta, x_start=0.0)
220248
Ta > 0 || throw(ArgumentError("Time constant `Ta` has to be strictly positive"))
@@ -251,11 +279,6 @@ end
251279
252280
Proportional-Integral-Derivative (PID) controller with output saturation, set-point weighting and integrator anti-windup.
253281
254-
This block has inputs
255-
- `u_r` reference/set point
256-
- `u_y` measurement signal
257-
and output `y` corresponding to the control signal.
258-
259282
The equation for the control signal is roughly
260283
```
261284
k(ep + 1/Ti * ∫e + 1/Td * d/dt(ed))
@@ -265,14 +288,20 @@ ed = wd*u_r - u_y
265288
```
266289
where the transfer function for the derivative includes additional filtering, see `? Derivative` for more details.
267290
291+
# Parameters:
268292
- `k`: Proportional gain
269-
- `Ti`: Integrator time constant. Set to `false` to turn off integral action.
270-
- `Td`: Derivative time constant. Set to `false` to turn off derivative action.
271-
- `wp`: Set-point weighting in the proportional part.
272-
- `wd`: Set-point weighting in the derivative part.
273-
- `Nd`: 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.
274-
- `Ni`: `Ni*Ti` controls the time constant `Tₜ` of anti-windup tracking. A common (default) choice is `Tₜ = √(Ti*Td)` which is realized by `Ni = √(Td / Ti)`. Anti-windup can be effectively turned off by setting `Ni = Inf`.
293+
- `Ti`: [s] Integrator time constant. Set to `false` to turn off integral action.
294+
- `Td`: [s] Derivative time constant. Set to `false` to turn off derivative action.
295+
- `wp`: [0,1] Set-point weighting in the proportional part.
296+
- `wd`: [0,1] Set-point weighting in the derivative part.
297+
- `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.
298+
- `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`.
275299
` `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`
300+
301+
# Connectors:
302+
- `reference`
303+
- `measurement`
304+
- `ctr_output`
276305
"""
277306
function LimPID(; name, k=1, Ti=false, Td=false, wp=1, wd=1,
278307
Ni= Ti == 0 ? Inf : (max(Td / Ti, 1e-6)),

src/Blocks/math.jl

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ Output the product of a gain value with the input signal.
55
66
# Parameters:
77
- `k`: Scalar gain
8+
9+
# Connectors:
10+
- `input`
11+
- `output`
812
"""
913
function Gain(k=1; name)
1014
@named siso = SISO()
@@ -23,6 +27,10 @@ Output the product of a gain matrix with the input signal vector.
2327
2428
# Parameters:
2529
- `K`: Matrix gain
30+
31+
# Connectors:
32+
- `input`
33+
- `output`
2634
"""
2735
function MatrixGain(K::AbstractArray; name)
2836
nout, nin = size(K)
@@ -41,6 +49,10 @@ Output the sum of the elements of the input port vector.
4149
4250
# Parameters:
4351
- `n`: Input port dimension
52+
53+
# Connectors:
54+
- `input`
55+
- `output`
4456
"""
4557
function Sum(n::Int; name)
4658
@named input = RealInput(;nin=n)
@@ -55,6 +67,11 @@ end
5567
Feedback(;name)
5668
5769
Output difference between reference input (input1) and feedback input (input2).
70+
71+
# Connectors:
72+
- `input1`
73+
- `input2`
74+
- `output`
5875
"""
5976
function Feedback(;name)
6077
@named input1 = RealInput()
@@ -74,6 +91,11 @@ Output the sum of the two scalar inputs.
7491
# Parameters:
7592
- `k1`: Gain for first input
7693
- `k2`: Gain for second input
94+
95+
# Connectors:
96+
- `input1`
97+
- `input2`
98+
- `output`
7799
"""
78100
function Add(;name, k1=1, k2=1)
79101
@named input1 = RealInput()
@@ -98,6 +120,12 @@ Output the sum of the three scalar inputs.
98120
- `k1`: Gain for first input
99121
- `k2`: Gain for second input
100122
- `k3`: Gain for third input
123+
124+
# Connectors:
125+
- `input1`
126+
- `input2`
127+
- `input3`
128+
- `output`
101129
"""
102130
function Add3(;name, k1=1, k2=1, k3=1)
103131
@named input1 = RealInput()
@@ -119,6 +147,11 @@ end
119147
Product(;name)
120148
121149
Output product of the two inputs.
150+
151+
# Connectors:
152+
- `input1`
153+
- `input2`
154+
- `output`
122155
"""
123156
function Product(;name)
124157
@named input1 = RealInput()
@@ -134,6 +167,11 @@ end
134167
Division(;name)
135168
136169
Output first input divided by second input.
170+
171+
# Connectors:
172+
- `input1`
173+
- `input2`
174+
- `output`
137175
"""
138176
function Division(;name)
139177
@named input1 = RealInput()
@@ -152,6 +190,10 @@ end
152190
Applies the given function to the input.
153191
154192
If the given function is not composed of simple core methods (e.g. sin, abs, ...), it has to be registered via `@register_symbolic func(u)`
193+
194+
# Connectors:
195+
- `input`
196+
- `output`
155197
"""
156198
function StaticNonLinearity(func; name)
157199
@named siso = SISO()
@@ -164,69 +206,101 @@ end
164206
Abs(;name)
165207
166208
Output the absolute value of the input.
209+
210+
# Connectors:
211+
See [`StaticNonLinearity`](@ref)
167212
"""
168213
Abs(;name) = StaticNonLinearity(abs; name)
169214

170215
"""
171216
Sign(;name)
172217
173218
Output the sign of the input
219+
220+
# Connectors:
221+
See [`StaticNonLinearity`](@ref)
174222
"""
175223
Sign(;name) = StaticNonLinearity(sign; name)
176224

177225
"""
178226
Sqrt(;name)
179227
180228
Output the square root of the input (input >= 0 required).
229+
230+
# Connectors:
231+
See [`StaticNonLinearity`](@ref)
181232
"""
182233
Sqrt(;name) = StaticNonLinearity(sqrt; name)
183234

184235
"""
185236
Sin(;name)
186237
187238
Output the sine of the input.
239+
240+
# Connectors:
241+
See [`StaticNonLinearity`](@ref)
188242
"""
189243
Sin(;name) = StaticNonLinearity(sin; name)
190244

191245
"""
192246
Cos(;name)
193247
194248
Output the cosine of the input.
249+
250+
# Connectors:
251+
See [`StaticNonLinearity`](@ref)
195252
"""
196253
Cos(;name) = StaticNonLinearity(cos; name)
197254

198255
"""
199256
Tan(;name)
200257
201258
Output the tangent of the input.
259+
260+
# Connectors:
261+
See [`StaticNonLinearity`](@ref)
202262
"""
203263
Tan(;name) = StaticNonLinearity(tan; name)
204264

205265
"""
206266
Asin(;name)
207267
208268
Output the arc sine of the input.
269+
270+
# Connectors:
271+
See [`StaticNonLinearity`](@ref)
209272
"""
210273
Asin(;name) = StaticNonLinearity(asin; name)
211274

212275
"""
213276
Acos(;name)
214277
215278
Output the arc cosine of the input.
279+
280+
# Connectors:
281+
See [`StaticNonLinearity`](@ref)
216282
"""
217283
Acos(;name) = StaticNonLinearity(acos; name)
218284

219285
"""
220286
Atan(;name)
221287
222288
Output the arc tangent of the input.
289+
290+
# Connectors:
291+
See [`StaticNonLinearity`](@ref)
223292
"""
224293
Atan(;name) = StaticNonLinearity(atan; name)
225294

226295
"""
227296
Atan2(;name)
228297
229298
Output the arc tangent of the input.
299+
300+
# Connectors:
301+
- `input1`
302+
- `input2`
303+
- `output`
230304
"""
231305
function Atan2(;name)
232306
@named input1 = RealInput()
@@ -242,40 +316,58 @@ end
242316
Sinh(;name)
243317
244318
Output the hyperbolic sine of the input.
319+
320+
# Connectors:
321+
See [`StaticNonLinearity`](@ref)
245322
"""
246323
Sinh(;name) = StaticNonLinearity(sinh; name)
247324

248325
"""
249326
Cosh(;name)
250327
251328
Output the hyperbolic cosine of the input.
329+
330+
# Connectors:
331+
See [`StaticNonLinearity`](@ref)
252332
"""
253333
Cosh(;name) = StaticNonLinearity(cosh; name)
254334

255335
"""
256336
Tanh(;name)
257337
258338
Output the hyperbolic tangent of the input.
339+
340+
# Connectors:
341+
See [`StaticNonLinearity`](@ref)
259342
"""
260343
Tanh(;name) = StaticNonLinearity(tanh; name)
261344

262345
"""
263346
Exp(;name)
264347
265348
Output the exponential (base e) of the input.
349+
350+
# Connectors:
351+
See [`StaticNonLinearity`](@ref)
266352
"""
267353
Exp(;name) = StaticNonLinearity(exp; name)
268354

269355
"""
270356
Log(;name)
271357
272358
Output the natural (base e) logarithm of the input.
359+
360+
# Connectors:
361+
See [`StaticNonLinearity`](@ref)
273362
"""
274363
Log(;name) = StaticNonLinearity(log; name)
275364

276365
"""
277366
Log10(;name)
278367
279368
Output the base 10 logarithm of the input.
369+
370+
# Connectors:
371+
See [`StaticNonLinearity`](@ref)
280372
"""
281373
Log10(;name) = StaticNonLinearity(log10; name)

0 commit comments

Comments
 (0)