Skip to content

Commit 01370ef

Browse files
committed
Updated commenting for easy IPython
1 parent 1934a73 commit 01370ef

8 files changed

+108
-44
lines changed

oneD_combined_control.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
GitHub: https://github.com/botprof/agv-examples
55
"""
66

7-
# %% SIMULATION SETUP
7+
# %%
8+
# SIMULATION SETUP
89

910
from scipy import signal
1011
import numpy as np
@@ -25,7 +26,8 @@
2526
lambda_sc = np.roots([1, 2 * ZETA * OMEGA_N, OMEGA_N ** 2])
2627
lambda_zc = np.exp(lambda_sc * T)
2728

28-
# %% PARAMETERS
29+
# %%
30+
# PARAMETERS
2931

3032
# Function that models the vehicle and sensor(s) in discrete time
3133
F = np.array([[1, T], [0, 1]])
@@ -39,7 +41,8 @@
3941
lambda_zo = np.array([0.5, 0.4])
4042
LT = signal.place_poles(F.T, H.T, lambda_zo)
4143

42-
# %% FUNCTION DEFINITIONS
44+
# %%
45+
# FUNCTION DEFINITIONS
4346

4447

4548
def vehicle(x, u, F, G):
@@ -60,7 +63,8 @@ def observer(x_hat, u, y, F, G, H, L):
6063
return x_hat_new
6164

6265

63-
# %% RUN SIMULATION
66+
# %%
67+
# RUN SIMULATION
6468

6569
# Create an array of time values [s]
6670
SIM_TIME = 20.0
@@ -88,7 +92,8 @@ def observer(x_hat, u, y, F, G, H, L):
8892
x[:, k] = vehicle(x[:, k - 1], u[k - 1], F, G)
8993
u[k] = controller(x_hat[:, k], K.gain_matrix)
9094

91-
# %% MAKE A PLOT
95+
# %%
96+
# MAKE A PLOT
9297

9398
# Change some plot settings (optional)
9499
plt.rc("text", usetex=True)
@@ -120,7 +125,8 @@ def observer(x_hat, u, y, F, G, H, L):
120125
# Save the plot
121126
plt.savefig("../agv-book/figs/ch2/oneD_combined_control_fig1.pdf")
122127

123-
# %% MAKE AN ANIMATION
128+
# %%
129+
# MAKE AN ANIMATION
124130

125131
# Set the side length of the vehicle [m]
126132
LENGTH = 1.0

oneD_discrete_control.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
GitHub: https://github.com/botprof/agv-examples
55
"""
66

7-
# %% SIMULATION SETUP
7+
# %%
8+
# SIMULATION SETUP
89

910
from scipy import signal
1011
import numpy as np
1112
import matplotlib.pyplot as plt
1213
from mobotpy.models import Cart
1314

14-
# %% PARAMETERS
15+
# %%
16+
# PARAMETERS
1517

1618
# Set some parameters that describe the desired behaviour
1719
ZETA = 1.1
@@ -34,7 +36,8 @@
3436
# Find gain matrix K that places the poles at lambda_z
3537
K = signal.place_poles(F, G, lambda_z)
3638

37-
# %% FUNCTION DEFINITIONS
39+
# %%
40+
# FUNCTION DEFINITIONS
3841

3942

4043
def vehicle(x, u, F, G):
@@ -49,7 +52,8 @@ def controller(x, K):
4952
return u
5053

5154

52-
# %% RUN SIMULATION
55+
# %%
56+
# RUN SIMULATION
5357

5458
# Create an array of time values [s]
5559
SIM_TIME = 30.0
@@ -70,7 +74,8 @@ def controller(x, K):
7074
x[:, k] = vehicle(x[:, k - 1], u[k - 1], F, G)
7175
u[k] = controller(x[:, k], K.gain_matrix)
7276

73-
# %% MAKE A PLOT
77+
# %%
78+
# MAKE A PLOT
7479

7580
# Change some plot settings (optional)
7681
plt.rc("text", usetex=True)
@@ -99,7 +104,8 @@ def controller(x, K):
99104
# Save the plot
100105
plt.savefig("../agv-book/figs/ch2/oneD_discrete_control_fig1.pdf")
101106

102-
# %% MAKE AN ANIMATION
107+
# %%
108+
# MAKE AN ANIMATION
103109

104110
# Set the side length of the vehicle [m]
105111
LENGTH = 1.0

oneD_dynamic.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
GitHub: https://github.com/botprof/agv-examples
55
"""
66

7-
# %% SIMULATION SETUP
7+
# %%
8+
# SIMULATION SETUP
89

910
import numpy as np
1011
import matplotlib.pyplot as plt
@@ -18,7 +19,8 @@
1819
t = np.arange(0, SIM_TIME, T)
1920
N = np.size(t)
2021

21-
# %% FUNCTION DEFINITIONS
22+
# %%
23+
# FUNCTION DEFINITIONS
2224

2325
# Set the mass of the vehicle [kg]
2426
M = 10.0
@@ -34,7 +36,8 @@ def vehicle(x, u, F, G):
3436
return x_new
3537

3638

37-
# %% RUN SIMULATION
39+
# %%
40+
# RUN SIMULATION
3841

3942
# Initialize arrays that will be populated with our inputs and states
4043
x = np.zeros((2, N))
@@ -50,7 +53,8 @@ def vehicle(x, u, F, G):
5053
x[:, k] = vehicle(x[:, k - 1], u[k - 1], F, G)
5154
u[k] = np.sin(k * T)
5255

53-
# %% MAKE A PLOT
56+
# %%
57+
# MAKE A PLOT
5458

5559
# Change some plot settings (optional)
5660
plt.rc("text", usetex=True)
@@ -79,7 +83,8 @@ def vehicle(x, u, F, G):
7983
# Save the plot
8084
plt.savefig("../agv-book/figs/ch2/oneD_dynamic_fig1.pdf")
8185

82-
# %% MAKE AN ANIMATION
86+
# %%
87+
# MAKE AN ANIMATION
8388

8489
# Set the side length of the vehicle [m]
8590
LENGTH = 1.0
@@ -94,3 +99,8 @@ def vehicle(x, u, F, G):
9499

95100
# Show all the plots to the screen
96101
plt.show()
102+
103+
# Show animation in HTML output if you are using IPython or Jupyter notebooks
104+
# plt.rc('animation', html='jshtml')
105+
# display(ani)
106+
# plt.close()

oneD_dynamic_control.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
GitHub: https://github.com/botprof/agv-examples
55
"""
66

7-
# %% SIMULATION SETUP
7+
# %%
8+
# SIMULATION SETUP
89

910
import numpy as np
1011
import matplotlib.pyplot as plt
@@ -18,7 +19,8 @@
1819
t = np.arange(0, SIM_TIME, T)
1920
N = np.size(t)
2021

21-
# %% FUNCTION DEFINITIONS
22+
# %%
23+
# FUNCTION DEFINITIONS
2224

2325
# Set the mass of the vehicle [kg]
2426
m = 10.0
@@ -40,7 +42,8 @@ def controller(x, K):
4042
return u
4143

4244

43-
# %% RUN SIMULATION
45+
# %%
46+
# RUN SIMULATION
4447

4548
# Initialize arrays that will be populated with our inputs and states
4649
x = np.zeros((2, N))
@@ -59,7 +62,8 @@ def controller(x, K):
5962
x[:, k] = vehicle(x[:, k - 1], u[k - 1], F, G)
6063
u[k] = controller(x[:, k], K)
6164

62-
# %% MAKE A PLOT
65+
# %%
66+
# MAKE A PLOT
6367

6468
# Change some plot settings (optional)
6569
plt.rc("text", usetex=True)
@@ -88,7 +92,8 @@ def controller(x, K):
8892
# Save the plot
8993
plt.savefig("../agv-book/figs/ch2/oneD_dynamic_control_fig1.pdf")
9094

91-
# %% MAKE AN ANIMATION
95+
# %%
96+
# MAKE AN ANIMATION
9297

9398
# Set the side length of the vehicle [m]
9499
LENGTH = 1.0
@@ -103,3 +108,8 @@ def controller(x, K):
103108

104109
# Show all the plots to the screen
105110
plt.show()
111+
112+
# Show animation in HTML output if you are using IPython or Jupyter notebooks
113+
# plt.rc('animation', html='jshtml')
114+
# display(ani)
115+
# plt.close()

oneD_dynamic_observer.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
GitHub: https://github.com/botprof/agv-examples
55
"""
66

7-
# %% SIMULATION SETUP
7+
# %%
8+
# SIMULATION SETUP
89

910
from scipy import signal
1011
import numpy as np
@@ -18,7 +19,8 @@
1819
t = np.arange(0, SIM_TIME, T)
1920
N = np.size(t)
2021

21-
# %% VEHICLE MODEL DEFINITION
22+
# %%
23+
# VEHICLE MODEL DEFINITION
2224

2325
# Set the mass of the vehicle [kg]
2426
M = 10.0
@@ -35,7 +37,8 @@ def vehicle(x, u, F, G):
3537
return x_new
3638

3739

38-
# %% OBSERVER DEFINTION
40+
# %%
41+
# OBSERVER DEFINITION
3942

4043
# Choose estimator gains for stability
4144
lambda_z = np.array([0.5, 0.4])
@@ -48,7 +51,8 @@ def observer(x_hat, u, y, F, G, H, L):
4851
return x_hat_new
4952

5053

51-
# %% RUN SIMULATION
54+
# %%
55+
# RUN SIMULATION
5256

5357
# Initialize arrays that will be populated with our inputs and states
5458
x = np.zeros((2, N))
@@ -71,7 +75,8 @@ def observer(x_hat, u, y, F, G, H, L):
7175
x[:, k] = vehicle(x[:, k - 1], u[k - 1], F, G)
7276
u[k] = 2.0 * np.sin(k * T)
7377

74-
# %% MAKE A PLOT
78+
# %%
79+
# MAKE A PLOT
7580

7681
# Change some plot settings (optional)
7782
plt.rc("text", usetex=True)

oneD_integral_control.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
GitHub: https://github.com/botprof/agv-examples
55
"""
66

7-
# %% SIMULATION SETUP
7+
# %%
8+
# SIMULATION SETUP
89

910
from scipy import signal
1011
import numpy as np
1112
import matplotlib.pyplot as plt
1213
from mobotpy.models import Cart
1314

14-
# %% PARAMETERS
15+
# %%
16+
# PARAMETERS
1517

1618
# Set some variables that describe the desired behaviour
1719
ZETA = 1.1
@@ -39,7 +41,8 @@
3941
# Find gain matrix K that places the poles inside the unit disk
4042
K = signal.place_poles(A, B, lambda_z)
4143

42-
# %% FUNCTION DEFINITIONS
44+
# %%
45+
# FUNCTION DEFINITIONS
4346

4447

4548
def vehicle(x, u, F, G):
@@ -60,7 +63,8 @@ def controller(x, xi, K):
6063
return u
6164

6265

63-
# %% RUN SIMULATION
66+
# %%
67+
# RUN SIMULATION
6468

6569
# Create an array of time values [s]
6670
SIM_TIME = 15.0
@@ -83,7 +87,8 @@ def controller(x, xi, K):
8387
xi[k] = integrator(x[:, k - 1], xi[k - 1])
8488
u[k] = controller(x[:, k], xi[k], K.gain_matrix)
8589

86-
# %% MAKE A PLOT
90+
# %%
91+
# MAKE A PLOT
8792

8893
# Change some plot settings (optional)
8994
plt.rc("text", usetex=True)
@@ -112,7 +117,8 @@ def controller(x, xi, K):
112117
# Save the plot
113118
plt.savefig("../agv-book/figs/ch2/oneD_integral_control_fig1.pdf")
114119

115-
# %% MAKE AN ANIMATION
120+
# %%
121+
# MAKE AN ANIMATION
116122

117123
# Set the side length of the vehicle [m]
118124
LENGTH = 1.0

0 commit comments

Comments
 (0)