You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -172,14 +176,19 @@ Initial value of the state `x` can be set with `x`, and of derivative state `xd`
172
176
end
173
177
174
178
"""
175
-
PI(;name, gainPI.k = 1.0, T, int.x = 0.0)
179
+
PI(;name, k = 1.0, T = 1.0, int.x = 0.0)
176
180
177
181
Textbook version of a PI-controller without actuator saturation and anti-windup measure.
178
-
The proportional gain can be set with `gainPI.k`
182
+
The proportional gain can be set with `k`
179
183
Initial value of integrator state `x` can be set with `int.x`
180
184
181
-
# Parameters:
185
+
The PI controller is implemented on standard form:
186
+
```math
187
+
U(s) = k (1 + \\dfrac{1}{sT}) E(S)
188
+
```
182
189
190
+
# Parameters:
191
+
- `k`: Proportional gain
183
192
- `T`: [s] Integrator time constant (T>0 required)
184
193
185
194
# Connectors:
@@ -191,7 +200,8 @@ See also [`LimPI`](@ref)
191
200
"""
192
201
@mtkmodel PI begin
193
202
@parametersbegin
194
-
T, [description ="Integrator time constant"]
203
+
k =1.0, [description ="Proportional gain"]
204
+
T =1.0, [description ="Integrator time constant"]
195
205
end
196
206
begin
197
207
@symcheck T >0||
@@ -200,7 +210,7 @@ See also [`LimPI`](@ref)
200
210
@componentsbegin
201
211
err_input =RealInput() # control error
202
212
ctr_output =RealOutput() # control signal
203
-
gainPI =Gain(; k=1.0)
213
+
gainPI =Gain(; k)
204
214
addPI =Add()
205
215
int =Integrator(k =1/ T, x =0.0)
206
216
end
@@ -294,6 +304,12 @@ end
294
304
295
305
Text-book version of a PI-controller with actuator saturation and anti-windup measure.
296
306
307
+
The PI controller is implemented on standard form
308
+
```math
309
+
u(t) = sat(k (e(t) + ∫\\dfrac{1}{T}e(t) dt) )
310
+
```
311
+
The simplified expression above is given without the anti-windup protection.
312
+
297
313
# Parameters:
298
314
299
315
- `k`: Proportional gain
@@ -537,3 +553,85 @@ linearized around the operating point `x₀, u₀`, we have `y0, u0 = h(x₀, u
537
553
end
538
554
539
555
StateSpace(A, B, C, D =nothing; kwargs...) =StateSpace(; A, B, C, D, kwargs...)
556
+
557
+
symbolic_eps(t) =eps(t)
558
+
@register_symbolicsymbolic_eps(t)
559
+
560
+
"""
561
+
TransferFunction(; b, a, name)
562
+
563
+
A single input, single output, linear time-invariant system provided as a transfer-function.
564
+
```
565
+
Y(s) = b(s) / a(s) U(s)
566
+
```
567
+
where `b` and `a` are vectors of coefficients of the numerator and denominator polynomials, respectively, ordered such that the coefficient of the highest power of `s` is first.
568
+
569
+
The internal state realization is on controller canonical form, with state variable `x`, output variable `y` and input variable `u`. For numerical robustness, the realization used by the integrator is scaled by the last entry of the `a` parameter. The internally scaled state variable is available as `x_scaled`.
570
+
571
+
To set the initial state, it's recommended to set the initial condition for `x`, and let that of `x_scaled` be computed automatically.
572
+
573
+
# Parameters:
574
+
- `b`: Numerator polynomial coefficients, e.g., `2s + 3` is specified as `[2, 3]`
575
+
- `a`: Denomenator polynomial coefficients, e.g., `s² + 2ωs + ω^2` is specified as `[1, 2ω, ω^2]`
576
+
577
+
# Connectors:
578
+
- `input`
579
+
- `output`
580
+
581
+
See also [`StateSpace`](@ref) which handles MIMO systems, as well as [ControlSystemsMTK.jl](https://juliacontrol.github.io/ControlSystemsMTK.jl/stable/) for an interface between [ControlSystems.jl](https://juliacontrol.github.io/ControlSystems.jl/stable/) and ModelingToolkit.jl for advanced manipulation of transfer functions and linear statespace systems. For linearization, see [`linearize`](@ref) and [Linear Analysis](https://docs.sciml.ai/ModelingToolkitStandardLibrary/stable/API/linear_analysis/).
582
+
"""
583
+
@componentfunctionTransferFunction(; b = [1], a = [1, 1], name)
584
+
nb =length(b)
585
+
na =length(a)
586
+
nb <= na ||
587
+
error("Transfer function is not proper, the numerator must not be longer than the denominator")
588
+
nx = na -1
589
+
nbb =max(0, na - nb)
590
+
591
+
@namedbegin
592
+
input =RealInput()
593
+
output =RealOutput()
594
+
end
595
+
596
+
@parametersbegin
597
+
b[1:nb] = b,
598
+
[
599
+
description ="Numerator coefficients of transfer function (e.g., 2s + 3 is specified as [2,3])",
600
+
]
601
+
a[1:na] = a,
602
+
[
603
+
description ="Denominator coefficients of transfer function (e.g., `s² + 2ωs + ω^2` is specified as [1, 2ω, ω^2])",
604
+
]
605
+
bb[1:(nbb + nb)] = [zeros(nbb); b]
606
+
d = bb[1] / a[1], [description ="Direct feedthrough gain"]
0 commit comments