Skip to content

Commit 2868a9a

Browse files
committed
Cleanup
1 parent ee71b4d commit 2868a9a

11 files changed

Lines changed: 100 additions & 158 deletions

BlockA/SysReg_crashcourse_TimeDomain_BlockA_01_Basics.py

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,11 @@
22
%matplotlib notebook
33
import numpy as np
44
import matplotlib.pyplot as plt
5-
plt.rcParams.update({ 'text.usetex': False, 'mathtext.fontset': 'cm',
6-
'font.size': 12.0, 'axes.labelsize': 'medium',
7-
'xtick.labelsize': 'x-small', 'ytick.labelsize': 'x-small',
8-
'axes.grid': True, 'axes.formatter.limits': [-3, 6],
9-
'grid.alpha': 0.5, 'figure.figsize': [11.0, 4],
10-
'figure.constrained_layout.use': True, 'scatter.marker': 'x',
11-
'animation.html': 'jshtml'})
12-
13-
from IPython.display import display, Markdown
14-
5+
from IPython.display import display
156
import warnings
167
warnings.filterwarnings("ignore")
17-
18-
import scipy.signal as signal
19-
import scipy.linalg as sclin
20-
import numpy.random as rng
21-
import numpy.linalg as lin
22-
import control as cm
238
from helperFunctions import *
9+
setPlotStyle()
2410

2511
# %% [markdown]
2612
# # Time domain
@@ -55,14 +41,16 @@
5541

5642
# %%
5743
## Eigenvalues
58-
sig1 = -0.8
59-
sig2 = 3 + 15j
60-
sig3 = -0.5 + 5j
44+
SIG = [ -0.8,
45+
2 + 15j,
46+
-0.5 + 5j,
47+
-0.5 - 5j,
48+
] # Add or remove any you'd like to see
6149

6250
###### Plotting #########
63-
fig, ax = plt.subplots(1,3)
64-
for sig, idx in zip([sig1, sig2, sig3], range(3)):
65-
t = np.linspace(0, 3/abs(np.real(sig)), num=300) # Adapt to convergence speed
51+
fig, ax = plt.subplots(1,len(SIG))
52+
for sig, idx in zip(SIG, range(len(SIG))):
53+
t = np.linspace(0, 3/abs(sig.real) if sig.real != 0 else 1, 300) # Adapt to convergence speed
6654
if np.iscomplex(sig): # Plot decomposition
6755
l1, = ax[idx].plot(t, np.exp(sig.real * t), 'r--', label=f"$e^{r"{"}{sig.real}t{r"}"}$") # Upper envelope
6856
ax[idx].plot(t, -np.exp(sig.real * t), 'r--') # Lower envelope
@@ -97,17 +85,13 @@
9785
#
9886
# It's a nice sanity check that any fundamental block scheme of an $n$-th order system has $n$ integrators.
9987
#
100-
#
10188
# ## Equilibrium points
10289
#         *Forever and unchanging*
10390
#
10491
# Often, systems will have equilibria, meaning there are states where system will remain over time. These state-input point pairs are denoted as $(x_e, u_e)$ or $(\bar x, \bar u)$. I'll use the latter since this is more traditional in control and we have to appease our control elders (JW). So equilibria remain unchanging, so the derivative of the state is zero. In mathematicians' language
10592
# $$ \dot{\bar x} = f(\bar x, \bar u) = 0. $$
10693
# Finding the equilibria states as a function of the equilibria inputs is as simple as solving this equation.
10794
#
108-
#
109-
#
110-
#
11195

11296
# %% [markdown]
11397
# <div style="text-align:center;background-color:tomato;">End of lecture 3</div>

BlockA/SysReg_crashcourse_TimeDomain_BlockA_02_StateSpace.py

Lines changed: 58 additions & 43 deletions
Large diffs are not rendered by default.

BlockA/SysReg_crashcourse_TimeDomain_BlockA_03_ControlSynthesis.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,7 @@
22
%matplotlib notebook
33
import numpy as np
44
import matplotlib.pyplot as plt
5-
plt.rcParams.update({ 'text.usetex': False, 'mathtext.fontset': 'cm',
6-
'font.size': 12.0, 'axes.labelsize': 'medium',
7-
'xtick.labelsize': 'x-small', 'ytick.labelsize': 'x-small',
8-
'axes.grid': True, 'axes.formatter.limits': [-3, 6],
9-
'grid.alpha': 0.5, 'figure.figsize': [11.0, 4],
10-
'figure.constrained_layout.use': True, 'scatter.marker': 'x',
11-
'animation.html': 'jshtml'})
12-
13-
from IPython.display import display, Markdown
14-
5+
from IPython.display import display
156
import warnings
167
warnings.filterwarnings("ignore")
178

@@ -21,6 +12,7 @@
2112
import numpy.linalg as lin
2213
import control as cm
2314
from helperFunctions import *
15+
setPlotStyle()
2416

2517
# %% [markdown]
2618
# ## Textbook input signals
@@ -40,7 +32,7 @@
4032

4133
## impulse response
4234
impIn = np.zeros_like(T_res)
43-
impIn[int(-T_res[0]/(T_res[1] - T_res[0]))] = 1./0.02
35+
impIn[int(-T_res[0]/(T_res[1] - T_res[0]))] = 1./(T_res[1] - T_res[0])
4436
impResponse = cm.forced_response(P_res,
4537
T = T_res,
4638
U = impIn)

BlockA/SysReg_crashcourse_TimeDomain_BlockA_04_Observers.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,15 @@
22
%matplotlib notebook
33
import numpy as np
44
import matplotlib.pyplot as plt
5-
plt.rcParams.update({ 'text.usetex': False, 'mathtext.fontset': 'cm',
6-
'font.size': 12.0, 'axes.labelsize': 'medium',
7-
'xtick.labelsize': 'x-small', 'ytick.labelsize': 'x-small',
8-
'axes.grid': True, 'axes.formatter.limits': [-3, 6],
9-
'grid.alpha': 0.5, 'figure.figsize': [11.0, 4],
10-
'figure.constrained_layout.use': True, 'scatter.marker': 'x',
11-
'animation.html': 'jshtml'})
12-
13-
from IPython.display import display, Markdown
5+
from IPython.display import display
146

157
import warnings
168
warnings.filterwarnings("ignore")
17-
18-
import scipy.signal as signal
19-
import scipy.linalg as sclin
209
import numpy.random as rng
2110
import numpy.linalg as lin
2211
import control as cm
2312
from helperFunctions import *
24-
13+
setPlotStyle()
2514

2615
# %% [markdown]
2716
# ## Observe this

BlockA/SysReg_crashcourse_TimeDomain_BlockA_05_Summary.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,22 @@
22
%matplotlib notebook
33
import numpy as np
44
import matplotlib.pyplot as plt
5-
plt.rcParams.update({ 'text.usetex': False, 'mathtext.fontset': 'cm',
6-
'font.size': 12.0, 'axes.labelsize': 'medium',
7-
'xtick.labelsize': 'x-small', 'ytick.labelsize': 'x-small',
8-
'axes.grid': True, 'axes.formatter.limits': [-3, 6],
9-
'grid.alpha': 0.5, 'figure.figsize': [11.0, 4],
10-
'figure.constrained_layout.use': True, 'scatter.marker': 'x',
11-
'animation.html': 'jshtml'})
12-
13-
from IPython.display import display, Markdown
5+
from IPython.display import display
146

157
import warnings
168
warnings.filterwarnings("ignore")
17-
18-
import scipy.signal as signal
19-
import scipy.linalg as sclin
209
import numpy.random as rng
2110
import numpy.linalg as lin
2211
import control as cm
2312
from helperFunctions import *
24-
13+
setPlotStyle()
2514

2615
# %% [markdown]
2716
# ## Connecting the dots
2817
#
2918
# Time to make the full picture: state feedback control with state estimation! Some important things to note:
30-
# - Since the state feedback is based on the state estimation, we want the error to go to zero faster than the controller works. If the controller is faster than the observer you're just doing random stuff basically until the estimate converges. Rule of thumb: the observer should be 4 to 10 times faster (larger magnitude poles) than the controller.
19+
# - Since the state feedback is based on the state estimation, we want the error to go to zero faster than the controller works. If the controller is faster than the observer you're just doing
20+
# random stuff basically until the estimate converges. Rule of thumb: the observer should be 4 to 10 times faster (larger magnitude poles) than the controller.
3121
# - Making the observer extremely fast works well in theory, but as soon as your output is noisy, the fast observer will amplify this noise enourmously and your estimate will be terrible.
3222
# - In the example below I'll make an LQR observer, but since the observer is a regulator type controller, no feedforward gain is needed.
3323
# - Strictly speaking you can classify this as output feedback

BlockB/SysReg_crashcourse_FreqDomain_BlockB_02_BodeNyquist.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22
%matplotlib notebook
33
import numpy as np
44
import matplotlib.pyplot as plt
5-
plt.rcParams.update({ 'mathtext.fontset': 'cm',
6-
'font.size': 12.0, 'axes.labelsize': 'medium',
7-
'xtick.labelsize': 'x-small', 'ytick.labelsize': 'x-small',
8-
'axes.grid': True, 'axes.formatter.limits': [-3, 6],
9-
'grid.alpha': 0.5, 'figure.figsize': [11.0, 4],
10-
'figure.constrained_layout.use': True, 'scatter.marker': 'x',
11-
'animation.html': 'jshtml'
12-
})
135

146
from matplotlib.ticker import MultipleLocator
157
from matplotlib.gridspec import GridSpec
@@ -19,9 +11,8 @@
1911
import warnings
2012
warnings.filterwarnings("ignore")
2113

22-
import control as cm
2314
from helperFunctions import *
24-
15+
setPlotStyle()
2516

2617
# %% [markdown]
2718
# # Visualising complex numbers
@@ -192,7 +183,7 @@ def anim_init(z1, ax):
192183
ax[i].annotate("$z_1$", xy=(np.real(z1), np.imag(z1)),
193184
xytext=(.5,.3), textcoords='offset fontsize', color='red')
194185

195-
## Animation time! Yeah don't focus too much on this it's fine
186+
## Animation time! Don't focus too much on this it's fine
196187
r = cntr - z1
197188
rm = np.max(np.abs(r))
198189
ax[1].set(aspect='equal', xlabel="$\mathfrak{Re}\{G(s)\}$", ylabel="$\mathfrak{Im}\{G(s)\}$", xlim=[-rm+np.real(z1), rm+np.real(z1)], ylim=[-rm+np.imag(z1),rm+np.imag(z1)])
@@ -331,7 +322,6 @@ def animate(t):
331322

332323
ax[2].cla()
333324
ax[2].set(xlabel = r"$\omega$", ylabel = r"$\angle G(s)$ / ${}^\circ$")
334-
# ax[2].semilogx(np.abs(OM_full), ang, 'k')
335325
ax[2].semilogx(np.abs(OM_full)[:OM_full.size//2], ang[:OM_full.size//2], 'k')
336326
ax[2].semilogx(np.abs(OM_full)[OM_full.size//2:], ang[OM_full.size//2:], 'k--')
337327

@@ -358,3 +348,6 @@ def animate(t):
358348
anim = animation.FuncAnimation(fig, func=animate, frames=50, interval=150, blit=True)
359349

360350
display(anim)
351+
352+
# %% [markdown]
353+
# Note the relation between the two plots!

BlockB/SysReg_crashcourse_FreqDomain_BlockB_03_1st2ndOrder.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,16 @@
22
%matplotlib notebook
33
import numpy as np
44
import matplotlib.pyplot as plt
5-
plt.rcParams.update({ 'mathtext.fontset': 'cm',
6-
'font.size': 12.0, 'axes.labelsize': 'medium',
7-
'xtick.labelsize': 'x-small', 'ytick.labelsize': 'x-small',
8-
'axes.grid': True, 'axes.formatter.limits': [-3, 6],
9-
'grid.alpha': 0.5, 'figure.figsize': [11.0, 4],
10-
'figure.constrained_layout.use': True, 'scatter.marker': 'x',
11-
'animation.html': 'jshtml'
12-
})
13-
145
from matplotlib.ticker import MultipleLocator
156
from matplotlib.gridspec import GridSpec
16-
import matplotlib.animation as animation
17-
from IPython.display import display, Markdown
7+
from IPython.display import display
188

199
import warnings
2010
warnings.filterwarnings("ignore")
2111

2212
import control as cm
2313
from helperFunctions import *
14+
setPlotStyle()
2415

2516
# %% [markdown]
2617
# ## Your own transfer function toolbox
@@ -33,9 +24,9 @@
3324
# - a time-delay, $e^{-\tau_1 s}$, that delays with $\tau_1$ time
3425

3526
# %%
36-
k1, p1, z1 = 1e-2, 0.3, 7. #CHANGEME
27+
k1, p1, z1 = 1e-2, 0.3, 7. #CHANGEME
3728
om_p, zeta_p, om_z, zeta_z = .1, .1, 4., 2. #CHANGEME
38-
tau1 = 3e-3 #CHANGEME
29+
tau1 = 3e-3 #CHANGEME
3930

4031
OM = np.logspace(-2, 3.5, 400)
4132
S = OM*1j

BlockB/SysReg_crashcourse_FreqDomain_BlockB_04_SystemAnalysis.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,14 @@
22
%matplotlib notebook
33
import numpy as np
44
import matplotlib.pyplot as plt
5-
plt.rcParams.update({ 'mathtext.fontset': 'cm',
6-
'font.size': 12.0, 'axes.labelsize': 'medium',
7-
'xtick.labelsize': 'x-small', 'ytick.labelsize': 'x-small',
8-
'axes.grid': True, 'axes.formatter.limits': [-3, 6],
9-
'grid.alpha': 0.5, 'figure.figsize': [11.0, 4],
10-
'figure.constrained_layout.use': True, 'scatter.marker': 'x',
11-
'animation.html': 'jshtml'
12-
})
13-
145
from matplotlib.ticker import MultipleLocator
156
from matplotlib.gridspec import GridSpec
16-
from IPython.display import display, Markdown
7+
from IPython.display import display
178

189
import warnings
1910
warnings.filterwarnings("ignore")
20-
21-
import control as cm
2211
from helperFunctions import *
23-
12+
setPlotStyle()
2413

2514
# %% [markdown]
2615
# ## Performance Margins
@@ -119,6 +108,7 @@
119108
# ## Minimum Phase Systems
120109
# Minimum phase systems (MPS) are systems where the phase is the absolute minimum possible value for any given magnitude. Defined the other way around: MPS are systems without phase addition from factors not
121110
# contributing to the magnitude. These factors are only time-delays and RHP zeros. Lets look at the difference between a LHP and RHP zero:
111+
#
122112
# %%
123113
OM = np.logspace(-3, 3, 700)
124114
S = OM*1j

BlockB/SysReg_crashcourse_FreqDomain_BlockB_05_ControlSynthesis.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,14 @@
22
%matplotlib notebook
33
import numpy as np
44
import matplotlib.pyplot as plt
5-
plt.rcParams.update({ 'mathtext.fontset': 'cm',
6-
'font.size': 12.0, 'axes.labelsize': 'medium',
7-
'xtick.labelsize': 'x-small', 'ytick.labelsize': 'x-small',
8-
'axes.grid': True, 'axes.formatter.limits': [-3, 6],
9-
'grid.alpha': 0.5, 'figure.figsize': [11.0, 4],
10-
'figure.constrained_layout.use': True, 'scatter.marker': 'x',
11-
'animation.html': 'jshtml'
12-
})
13-
14-
from matplotlib.ticker import MultipleLocator
155
from matplotlib.gridspec import GridSpec
16-
import matplotlib.animation as animation
17-
from IPython.display import display, Markdown
6+
from IPython.display import display
187

198
import warnings
209
warnings.filterwarnings("ignore")
2110

22-
import control as cm
2311
from helperFunctions import *
12+
setPlotStyle()
2413

2514

2615
# %% [markdown]
639 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)