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
SecondOrder(; name, k = 1.0, w, d, x = 0.0, xd = 0.0)
115
131
116
132
A second-order filter with gain `k`, a bandwidth of `w` rad/s and relative damping `d`. The transfer function
117
133
is given by `Y(s)/U(s) = `
@@ -124,44 +140,47 @@ s² + 2d*w*s + w^2
124
140
125
141
Critical damping corresponds to `d=1`, which yields the fastest step response without overshoot, `d < 1` results in an underdamped filter while `d > 1` results in an overdamped filter.
126
142
`d = 1/√2` corresponds to a Butterworth filter of order 2 (maximally flat frequency response).
143
+
Initial value of the state `x` can be set with `x`, and of derivative state `xd` with `xd`.
127
144
128
145
# Parameters:
129
146
130
147
- `k`: Gain
131
148
- `w`: [`rad/s`] Angular frequency
132
149
- `d`: Damping
133
-
- `x_start`: Initial value of state (output)
134
-
- `xd_start`: Initial value of derivative of state (output)
135
150
136
151
# Connectors:
137
152
138
153
- `input`
139
154
- `output`
140
155
"""
141
-
@componentfunctionSecondOrder(; name, k =1, w, d, x_start =0.0, xd_start =0.0)
142
-
@named siso =SISO()
143
-
@unpack u, y = siso
144
-
@variablesx(t)=x_start [description ="State of SecondOrder filter $name"]
145
-
@variablesxd(t)=xd_start [description ="Derivative state of SecondOrder filter $name"]
146
-
@parameters k=k [description ="Gain of SecondOrder $name"]
147
-
@parameters w=w [description ="Bandwidth of SecondOrder $name"]
148
-
@parameters d=d [description ="Relative damping of SecondOrder $name"]
149
-
eqs = [D(x) ~ xd
156
+
@mtkmodel SecondOrder begin
157
+
@extend u, y = siso =SISO()
158
+
@variablesbegin
159
+
x(t) =0.0, [description ="State of SecondOrder filter"]
160
+
xd(t) =0.0, [description ="Derivative state of SecondOrder filter"]
161
+
end
162
+
@parametersbegin
163
+
k =1.0, [description ="Gain of SecondOrder"]
164
+
w, [description ="Bandwidth of SecondOrder"]
165
+
d, [description ="Relative damping of SecondOrder"]
166
+
end
167
+
@equationsbegin
168
+
D(x) ~ xd
150
169
D(xd) ~ w * (w * (k * u - x) -2* d * xd)
151
-
y ~ x]
152
-
extend(ODESystem(eqs, t; name = name), siso)
170
+
y ~ x
171
+
end
153
172
end
154
173
155
174
"""
156
-
PI(;name, k=1, T, x_start=0.0)
175
+
PI(;name, gainPI.k = 1.0, T, int.x = 0.0)
157
176
158
177
Textbook version of a PI-controller without actuator saturation and anti-windup measure.
178
+
Initial value of integrator state `x` can be set with `int.x`
179
+
Initial value of gain can be set with `gainPI.k`
159
180
160
181
# Parameters:
161
182
162
-
- `k`: Gain
163
183
- `T`: [s] Integrator time constant (T>0 required)
164
-
- `x_start`: Initial value for the integrator
165
184
166
185
# Connectors:
167
186
@@ -170,22 +189,28 @@ Textbook version of a PI-controller without actuator saturation and anti-windup
170
189
171
190
See also [`LimPI`](@ref)
172
191
"""
173
-
@componentfunctionPI(; name, k =1, T, x_start =0.0)
174
-
@symcheck T >0||throw(ArgumentError("Time constant `T` has to be strictly positive"))
175
-
@named err_input =RealInput() # control error
176
-
@named ctr_output =RealOutput() # control signal
177
-
@named gainPI =Gain(k)
178
-
@named addPI =Add()
179
-
@named int =Integrator(k =1/ T, x_start = x_start)
180
-
sys = [err_input, ctr_output, gainPI, addPI, int]
181
-
eqs = [
182
-
connect(err_input, addPI.input1),
183
-
connect(addPI.output, gainPI.input),
184
-
connect(gainPI.output, ctr_output),
185
-
connect(err_input, int.input),
186
-
connect(int.output, addPI.input2),
187
-
]
188
-
ODESystem(eqs, t, [], []; name = name, systems = sys)
192
+
@mtkmodel PI begin
193
+
@parametersbegin
194
+
T, [description ="Integrator time constant"]
195
+
end
196
+
begin
197
+
@symcheck T >0||
198
+
throw(ArgumentError("Time constant `T` has to be strictly positive"))
199
+
end
200
+
@componentsbegin
201
+
err_input =RealInput() # control error
202
+
ctr_output =RealOutput() # control signal
203
+
gainPI =Gain(; k =1.0)
204
+
addPI =Add()
205
+
int =Integrator(k =1/ T, x =0.0)
206
+
end
207
+
@equationsbegin
208
+
connect(err_input, addPI.input1)
209
+
connect(addPI.output, gainPI.input)
210
+
connect(gainPI.output, ctr_output)
211
+
connect(err_input, int.input)
212
+
connect(int.output, addPI.input2)
213
+
end
189
214
end
190
215
191
216
"""
@@ -224,12 +249,12 @@ See also [`LimPID`](@ref)
224
249
@named gainPID =Gain(k)
225
250
@named addPID =Add3()
226
251
if with_I
227
-
@named int =Integrator(k =1/ Ti, x_start= xi_start)
252
+
@named int =Integrator(k =1/ Ti, x= xi_start)
228
253
else
229
254
@named Izero =Constant(k =0)
230
255
end
231
256
if with_D
232
-
@named der =Derivative(k = Td, T =1/ Nd, x_start= xd_start)
257
+
@named der =Derivative(k = Td, T =1/ Nd, x= xd_start)
233
258
else
234
259
@named Dzero =Constant(k =0)
235
260
end
@@ -265,16 +290,16 @@ See also [`LimPID`](@ref)
265
290
end
266
291
267
292
"""
268
-
LimPI(;name, k=1, T, u_max=1, u_min=-u_max, Ta)
293
+
LimPI(;name, T, Ta, k = 1.0, x_start = 0.0, u_max = 1.0, u_min = -u_max)
269
294
270
295
Text-book version of a PI-controller with actuator saturation and anti-windup measure.
296
+
Initial value of gain can be set with `gainPI.k`
297
+
Initial value of integrator state `x` can be set with `int.x`
271
298
272
299
# Parameters:
273
300
274
-
- `k`: Gain
275
301
- `T`: [s] Integrator time constant (T>0 required)
276
302
- `Ta`: [s] Tracking time constant (Ta>0 required)
277
-
- `x_start`: Initial value for the integrator
278
303
279
304
# Connectors:
280
305
@@ -291,7 +316,7 @@ Text-book version of a PI-controller with actuator saturation and anti-windup me
0 commit comments