-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclasses_reset.qmd
257 lines (201 loc) · 8.93 KB
/
classes_reset.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
---
title: "Reset systems"
bibliography: ref_hybrid.bib
csl: ieee-control-systems.csl
format:
html:
html-math-method: katex
code-fold: true
code-summary: "Show the code"
crossref:
fig-prefix: Fig.
eq-prefix: Eq.
engine: julia
---
We have introduced two major modeling frameworks for hybrid systems – [hybrid automata](hybrid_automata.qmd) and [hybrid equations](hybrid_equations.qmd). Now we are ready to model any hybrid system. It turns out useful, however, to define a few special classes of hybrid systems. Their special features are reflected in the structure of their models (hybrid automata or hybrid equations). The special classes of hybrid systems that we are going to discuss are
- reset systems,
- switched systems,
- piecewise affine (PWA) systems.
## Reset systems
They are also called *impulsive systems* (the reason is going to be clear soon). They are conveniently defined within the hybrid automata framework. In a hybrid automaton modelling a reset system we can only identify a single discrete state (mode), not more. In the digraph representation, we can only observe a single node.
![Reset system](classes_figures/reset_system.png){width=40% #fig-reset-system}
Within the hybrid equations framework, in a reset system some variables reset (jump) and flow, others only flow, but there are no variables that only reset... Well, this definition is not perfect, because as we have discussed earlier, even when staying constant between two jumps, the state variable is, technically speaking, also flowing. What we want to express is that there are not discrete variables in such model, but the hybrid equations framework intentionally does not distinguish between continuous and discrete variables.
We can recognize the bouncing ball as a prominent example of a reset system. Another example follows.
::: {#exm-reset-oscillator}
## Reset oscillator
We consider a hybrid system state-space modelled by the following hybrid equations:
$$
\begin{aligned}
\begin{bmatrix}
\dot x_1\\ \dot x_2
\end{bmatrix}
&=
\begin{bmatrix}
0 & 1\\ -1 & 2\delta
\end{bmatrix}
\begin{bmatrix}
x_1\\x_2
\end{bmatrix}
+
\begin{bmatrix}
0\\1
\end{bmatrix},
\quad \bm x \in \mathcal C,\\
x_1^+ &= -x_1, \quad \bm x \in \mathcal D,
\end{aligned}
$$
where
$$
\begin{aligned}
\mathcal D &= \{\bm x \in \mathbb R^2 \mid x_1<0, x_2=0\},\\
\mathcal C &= \mathbb R^2\setminus\mathcal D.
\end{aligned}
$$
Simulation outcomes for some concrete value of the small positive parameter $\delta$ are shown in the following figure.
```{julia}
#| eval: true
using OrdinaryDiffEq
δ = 0.1
A = [0.0 1.0;
-1.0 2δ]
b = [0.0; 1.0]
x0 = [0.2, 0.0]
tspan = (0.0, 100)
f(x, p, t) = A*x + b
cond_fcn(x, t, integrator) = x[1]<0 ? x[2] : 1.0
affect!(integrator) = integrator.u[1] = -integrator.u[1]
cb = ContinuousCallback(cond_fcn, affect!)
prob = ODEProblem(f, x0, tspan)
sol = solve(prob, Tsit5(),callback=cb, reltol = 1e-6, abstol = 1e-6, saveat = 0.1)
using Plots
plot(sol[1,:],sol[2,:],lw=2,legend=false, tickfontsize=12, xtickfontsize=12, ytickfontsize=12)
xlabel!("x₁")
ylabel!("x₂")
```
Isn't it fascinating that a linear system augmented with resetting can exhibit such a complex behavior?
:::
## Clegg's integrator (CI)
Clegg's integrator is a reset element that can be used in control systems.
Its function is as follows. As soon as the sign of the input changes, the integrator resets to zero. As a consequence, the integrator keeps the sign of its input and output identical.
Unlike the traditional (linear) integrator, the CI exhibits much smaller phase lag (some 38 vs 90 deg).
::: {#exm-clegg}
## Response of Clegg's integrator to a sinusoidal input
Here is a response of the Clegg's integrator to a sinusoidal input.
``` {julia}
#| eval: true
using OrdinaryDiffEq
f(x, u, t) = u(t) # We adhere to the control systems notation that x is the state variable and u is the input.
x0 = 0.0 # The initial state.
tspan = (0.0, 10) # The time span.
u = t -> 1.0*sin(t) # The (control) input.
cond_fcn(x, t, integrator) = integrator.p(t) # The condition function. If zero, the event is triggered.
affect!(integrator) = integrator.u = 0.0 # Beware that internally, u is the state variable. Here, the state variable is reset to zero.
cb = ContinuousCallback(cond_fcn, affect!)
prob = ODEProblem(f, x0, tspan, u)
sol = solve(prob, Tsit5(),callback=cb, reltol = 1e-6, abstol = 1e-6, saveat = 0.1)
using Plots
t = sol.t
plot(sol.t,u.(t),label="u",lw=2)
plot!(sol,lw=2,label="x", tickfontsize=12, xtickfontsize=12, ytickfontsize=12)
xlabel!("t")
```
:::
It may be of historical curiosity that originally the concept was presented in the form of an analog circuit (opamps, diodes, resistors, capacitors). See the references if you are interested.
## First-order reset element (FORE)
Another simple reset element that can be used in control systems is known as FORE (first-order reset element) described by
$$
\begin{array}{lr}
\dot u = a u + k e, & \mathrm{when}\; e\neq 0,\\
u^+ = 0, & \mathrm{when}\; e = 0.
\end{array}
$$
::: {#exm-fore}
## FORE
Consider a plant modelled by $G(s) = \frac{s+1}{s(s+0.2)}$ and a first-order controller $C=\frac{1}{s+1}$ in the feedback loop as in @fig-foe.
![First-order controller in a feedback loop](classes_figures/foe.png){width=60% #fig-foe}
The response of the closed-loop system to a step reference input is shown using the following code.
``` {julia}
#| eval: false
using ModelingToolkit, Plots, OrdinaryDiffEq
using ModelingToolkit: t_nounits as t
using ModelingToolkit: D_nounits as D
function plant(; name)
@variables x₁(t)=0 x₂(t) = 0 u(t) y(t)
eqs = [D(x₁) ~ x₂
D(x₂) ~ -0.2x₂ + u
y ~ x₁ + x₂]
ODESystem(eqs, t; name = name)
end
function controller(; name)
@variables x(t)=0 u(t) y(t)
eqs = [D(x) ~ -x + u
y ~ x]
ODESystem(eqs, t, name = name)
end
@named C = controller()
@named P = plant()
t_of_step = 1.0
r(t) = t >= t_of_step ? 1.0 : 0.0
@register_symbolic r(t)
connections = [C.u ~ r(t) - P.y
C.y ~ P.u]
@named T = ODESystem(connections, t, systems = [C, P])
T = structural_simplify(T)
equations(T)
observed(T)
using DifferentialEquations: solve
prob = ODEProblem(complete(T), [], (0.0, 30.0), [])
sol = solve(prob, Tsit5(), saveat = 0.1)
using Plots
plot(sol.t, sol[P.y], label = "", xlabel = "t", ylabel = "y", lw = 2)
```
Now we turn the first-order controller into a FORE controller by augumenting it with the above described resetting functionality. The feedback loop is in @fig-fore.
![First-order reset element (FORE) in a feedback loop](classes_figures/fore.png){width=60% #fig-fore}
The response of the closed-loop system to a step reference input is shown using the following code.
``` {julia}
#| eval: false
using ModelingToolkit, Plots, OrdinaryDiffEq
using ModelingToolkit: t_nounits as t
using ModelingToolkit: D_nounits as D
function plant(; name)
@variables x₁(t)=0 x₂(t) = 0 u(t) y(t)
eqs = [D(x₁) ~ x₂
D(x₂) ~ -0.2x₂ + u
y ~ x₁ + x₂]
ODESystem(eqs, t; name = name)
end
function controller(; name)
@variables x(t)=0 u(t) y(t)
eqs = [D(x) ~ -x + u
y ~ x]
ODESystem(eqs, t, name = name)
end
@named C = controller()
@named P = plant()
t_of_step = 1.0
r(t) = t >= t_of_step ? 1.0 : 0.0
@register_symbolic r(t)
connections = [C.u ~ r(t) - P.y
C.y ~ P.u]
zero_crossed = [C.u ~ 0]
reset = [C.x ~ 0]
@named T = ODESystem(connections, t, systems = [C, P], continuous_events = zero_crossed => reset)
T = structural_simplify(T)
equations(T)
observed(T)
using DifferentialEquations: solve
prob = ODEProblem(complete(T), [], (0.0, 30.0), [])
sol = solve(prob, Tsit5(), saveat = 0.1)
using Plots
plot(sol.t, sol[P.y], label = "", xlabel = "t", ylabel = "y", lw = 2)
```
Obviously the introduction of the resetting functionality into the first order controller had a positive effect on the transient response of the closed-loop system.
:::
## When (not) to use reset control?
However conceptually simple, reset control is not a panacea. Analysis and design of reset control systems is not straightforward compared to the traditional linear control systems. In particular, guaranteeing closed-loop stability upon introduction of resetting into a linear controller is not easy and may require advanced concepts (some of them we are going to introduce later in the course). Therefore we should use reset control with care. We should always do our best to find (another) linear controller that has a performance comparable or even better than reset control system.
But reset control can be helfpul if the plant is subject to *fundamental limitations of achievable control performance* such as
- integrators and unstable poles,
- zeros in the right half-plane (non-minimum phase),
- delays,
- ...
In these situations reset control can be a way to beat the so-called *waterbed effect*.