Skip to content

Commit afd3fe3

Browse files
committed
Lint fixes to examples/*.py
1 parent 223c38f commit afd3fe3

14 files changed

+53
-66
lines changed

examples/bdalg-matlab.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# bdalg-matlab.py - demonstrate some MATLAB commands for block diagram altebra
1+
# bdalg-matlab.py - demonstrate some MATLAB commands for block diagram algebra
22
# RMM, 29 May 09
33

4-
from control.matlab import * # MATLAB-like functions
4+
from control.matlab import ss, ss2tf, tf, tf2ss # MATLAB-like functions
55

66
# System matrices
77
A1 = [[0, 1.], [-4, -1]]

examples/check-controllability-and-observability.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
RMM, 6 Sep 2010
55
"""
66

7-
import numpy as np # Load the scipy functions
8-
from control.matlab import * # Load the controls systems library
7+
import numpy as np # Load the numpy functions
8+
from control.matlab import ss, ctrb, obsv # Load the controls systems library
99

1010
# Parameters defining the system
1111

examples/cruise-control.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ def pi_update(t, x, u, params={}):
247247
# Assign variables for inputs and states (for readability)
248248
v = u[0] # current velocity
249249
vref = u[1] # reference velocity
250-
z = x[0] # integrated error
251250

252251
# Compute the nominal controller output (needed for anti-windup)
253252
u_a = pi_output(t, x, u, params)
@@ -394,7 +393,7 @@ def sf_output(t, z, u, params={}):
394393
ud = params.get('ud', 0)
395394

396395
# Get the system state and reference input
397-
x, y, r = u[0], u[1], u[2]
396+
x, r = u[0], u[2]
398397

399398
return ud - K * (x - xd) - ki * z + kf * (r - yd)
400399

@@ -440,13 +439,13 @@ def sf_output(t, z, u, params={}):
440439
4./180. * pi for t in T]
441440
t, y = ct.input_output_response(
442441
cruise_sf, T, [vref, gear, theta_hill], [X0[0], 0],
443-
params={'K': K, 'kf': kf, 'ki': 0.0, 'kf': kf, 'xd': xd, 'ud': ud, 'yd': yd})
442+
params={'K': K, 'kf': kf, 'ki': 0.0, 'xd': xd, 'ud': ud, 'yd': yd})
444443
subplots = cruise_plot(cruise_sf, t, y, label='Proportional', linetype='b--')
445444

446445
# Response of the system with state feedback + integral action
447446
t, y = ct.input_output_response(
448447
cruise_sf, T, [vref, gear, theta_hill], [X0[0], 0],
449-
params={'K': K, 'kf': kf, 'ki': 0.1, 'kf': kf, 'xd': xd, 'ud': ud, 'yd': yd})
448+
params={'K': K, 'kf': kf, 'ki': 0.1, 'xd': xd, 'ud': ud, 'yd': yd})
450449
cruise_plot(cruise_sf, t, y, label='PI control', t_hill=8, linetype='b-',
451450
subplots=subplots, legend=True)
452451

examples/kincar.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import numpy as np
55
import matplotlib.pyplot as plt
6-
import control as ct
76
import control.flatsys as fs
87

98
#

examples/mrac_siso_mit.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def adaptive_controller_state(t, xc, uc, params):
4646
# Parameters
4747
gam = params["gam"]
4848
Am = params["Am"]
49-
Bm = params["Bm"]
5049
signB = params["signB"]
5150

5251
# Controller inputs

examples/phase_plane_plots.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
# using the phaseplot module. Most of these figures line up with examples
66
# in FBS2e, with different display options shown as different subplots.
77

8-
import time
98
import warnings
10-
from math import pi, sqrt
9+
from math import pi
1110

1211
import matplotlib.pyplot as plt
1312
import numpy as np

examples/pvtol-nested-ss.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import os
1212
import matplotlib.pyplot as plt # MATLAB plotting functions
13-
from control.matlab import * # MATLAB-like functions
1413
import numpy as np
1514
import math
1615
import control as ct
@@ -23,12 +22,12 @@
2322
c = 0.05 # damping factor (estimated)
2423

2524
# Transfer functions for dynamics
26-
Pi = tf([r], [J, 0, 0]) # inner loop (roll)
27-
Po = tf([1], [m, c, 0]) # outer loop (position)
25+
Pi = ct.tf([r], [J, 0, 0]) # inner loop (roll)
26+
Po = ct.tf([1], [m, c, 0]) # outer loop (position)
2827

2928
# Use state space versions
30-
Pi = tf2ss(Pi)
31-
Po = tf2ss(Po)
29+
Pi = ct.tf2ss(Pi)
30+
Po = ct.tf2ss(Po)
3231

3332
#
3433
# Inner loop control design
@@ -40,68 +39,68 @@
4039

4140
# Design a simple lead controller for the system
4241
k, a, b = 200, 2, 50
43-
Ci = k*tf([1, a], [1, b]) # lead compensator
42+
Ci = k*ct.tf([1, a], [1, b]) # lead compensator
4443

4544
# Convert to statespace
46-
Ci = tf2ss(Ci)
45+
Ci = ct.tf2ss(Ci)
4746

4847
# Compute the loop transfer function for the inner loop
4948
Li = Pi*Ci
5049

5150

5251
# Bode plot for the open loop process
5352
plt.figure(1)
54-
bode(Pi)
53+
ct.bode(Pi)
5554

5655
# Bode plot for the loop transfer function, with margins
5756
plt.figure(2)
58-
bode(Li)
57+
ct.bode(Li)
5958

6059
# Compute out the gain and phase margins
6160
#! Not implemented
6261
# (gm, pm, wcg, wcp) = margin(Li);
6362

6463
# Compute the sensitivity and complementary sensitivity functions
65-
Si = feedback(1, Li)
64+
Si = ct.feedback(1, Li)
6665
Ti = Li*Si
6766

6867
# Check to make sure that the specification is met
6968
plt.figure(3)
70-
gangof4(Pi, Ci)
69+
ct.gangof4(Pi, Ci)
7170

7271
# Compute out the actual transfer function from u1 to v1 (see L8.2 notes)
7372
# Hi = Ci*(1-m*g*Pi)/(1+Ci*Pi);
74-
Hi = parallel(feedback(Ci, Pi), -m*g*feedback(Ci*Pi, 1))
73+
Hi = ct.parallel(ct.feedback(Ci, Pi), -m*g*ct.feedback(Ci*Pi, 1))
7574

7675
plt.figure(4)
7776
plt.clf()
78-
bode(Hi)
77+
ct.bode(Hi)
7978

8079
# Now design the lateral control system
8180
a, b, K = 0.02, 5, 2
82-
Co = -K*tf([1, 0.3], [1, 10]) # another lead compensator
81+
Co = -K*ct.tf([1, 0.3], [1, 10]) # another lead compensator
8382

8483
# Convert to statespace
85-
Co = tf2ss(Co)
84+
Co = ct.tf2ss(Co)
8685

8786
# Compute the loop transfer function for the outer loop
8887
Lo = -m*g*Po*Co
8988

9089
plt.figure(5)
91-
bode(Lo, display_margins=True) # margin(Lo)
90+
ct.bode(Lo, display_margins=True) # margin(Lo)
9291

9392
# Finally compute the real outer-loop loop gain + responses
9493
L = Co*Hi*Po
95-
S = feedback(1, L)
96-
T = feedback(L, 1)
94+
S = ct.feedback(1, L)
95+
T = ct.feedback(L, 1)
9796

9897
# Compute stability margins
9998
#! Not yet implemented
10099
# (gm, pm, wgc, wpc) = margin(L);
101100

102101
plt.figure(6)
103102
plt.clf()
104-
out = ct.bode(L, logspace(-4, 3), initial_phase=-math.pi/2)
103+
out = ct.bode(L, np.logspace(-4, 3), initial_phase=-math.pi/2)
105104
axs = ct.get_plot_axes(out)
106105

107106
# Add crossover line to magnitude plot
@@ -111,7 +110,7 @@
111110
# Nyquist plot for complete design
112111
#
113112
plt.figure(7)
114-
nyquist(L)
113+
ct.nyquist(L)
115114

116115
# set up the color
117116
color = 'b'
@@ -126,10 +125,10 @@
126125
# 'EdgeColor', color, 'FaceColor', color);
127126

128127
plt.figure(9)
129-
Yvec, Tvec = step(T, linspace(1, 20))
128+
Yvec, Tvec = ct.step_response(T, np.linspace(1, 20))
130129
plt.plot(Tvec.T, Yvec.T)
131130

132-
Yvec, Tvec = step(Co*S, linspace(1, 20))
131+
Yvec, Tvec = ct.step_response(Co*S, np.linspace(1, 20))
133132
plt.plot(Tvec.T, Yvec.T)
134133

135134
#TODO: PZmap for statespace systems has not yet been implemented.
@@ -142,7 +141,7 @@
142141
# Gang of Four
143142
plt.figure(11)
144143
plt.clf()
145-
gangof4(Hi*Po, Co, linspace(-2, 3))
144+
ct.gangof4(Hi*Po, Co, np.linspace(-2, 3))
146145

147146
if 'PYCONTROL_TEST_EXAMPLES' not in os.environ:
148147
plt.show()

examples/pvtol.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ def _pvtol_flat_forward(states, inputs, params={}):
6464
F1, F2 = inputs
6565

6666
# Use equations of motion for higher derivates
67-
x1ddot = (F1 * cos(theta) - F2 * sin(theta)) / m
68-
x2ddot = (F1 * sin(theta) + F2 * cos(theta) - m * g) / m
6967
thddot = (r * F1) / J
7068

7169
# Flat output is a point above the vertical axis
@@ -110,7 +108,6 @@ def _pvtol_flat_reverse(zflag, params={}):
110108
J = params.get('J', 0.0475) # inertia around pitch axis
111109
r = params.get('r', 0.25) # distance to center of force
112110
g = params.get('g', 9.8) # gravitational constant
113-
c = params.get('c', 0.05) # damping factor (estimated)
114111

115112
# Given the flat variables, solve for the state
116113
theta = np.arctan2(-zflag[0][2], zflag[1][2] + g)
@@ -185,18 +182,13 @@ def _windy_update(t, x, u, params):
185182
def _noisy_update(t, x, u, params):
186183
# Get the inputs
187184
F1, F2, Dx, Dy = u[:4]
188-
if u.shape[0] > 4:
189-
Nx, Ny, Nth = u[4:]
190-
else:
191-
Nx, Ny, Nth = 0, 0, 0
192185

193186
# Get the system response from the original dynamics
194187
xdot, ydot, thetadot, xddot, yddot, thddot = \
195188
_pvtol_update(t, x, u[0:2], params)
196189

197190
# Get the parameter values we need
198191
m = params.get('m', 4.) # mass of aircraft
199-
J = params.get('J', 0.0475) # inertia around pitch axis
200192

201193
# Now add the disturbances
202194
xddot += Dx / m
@@ -219,7 +211,6 @@ def _noisy_output(t, x, u, params):
219211
def pvtol_noisy_A(x, u, params={}):
220212
# Get the parameter values we need
221213
m = params.get('m', 4.) # mass of aircraft
222-
J = params.get('J', 0.0475) # inertia around pitch axis
223214
c = params.get('c', 0.05) # damping factor (estimated)
224215

225216
# Get the angle and compute sine and cosine

examples/secord-matlab.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
import os
55
import matplotlib.pyplot as plt # MATLAB plotting functions
6-
from control.matlab import * # MATLAB-like functions
6+
import numpy as np
7+
from control.matlab import ss, step, bode, nyquist, rlocus # MATLAB-like functions
78

89
# Parameters defining the system
910
m = 250.0 # system mass
@@ -24,15 +25,15 @@
2425

2526
# Bode plot for the system
2627
plt.figure(2)
27-
mag, phase, om = bode(sys, logspace(-2, 2), plot=True)
28+
mag, phase, om = bode(sys, np.logspace(-2, 2), plot=True)
2829
plt.show(block=False)
2930

3031
# Nyquist plot for the system
3132
plt.figure(3)
3233
nyquist(sys)
3334
plt.show(block=False)
3435

35-
# Root lcous plot for the system
36+
# Root locus plot for the system
3637
rlocus(sys)
3738

3839
if 'PYCONTROL_TEST_EXAMPLES' not in os.environ:

examples/sisotool_example.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@
1010

1111
#%%
1212
import matplotlib.pyplot as plt
13-
from control.matlab import *
13+
import control as ct
1414

1515
# first example, aircraft attitude equation
16-
s = tf([1,0],[1])
16+
s = ct.tf([1,0],[1])
1717
Kq = -24
1818
T2 = 1.4
1919
damping = 2/(13**.5)
2020
omega = 13**.5
2121
H = (Kq*(1+T2*s))/(s*(s**2+2*damping*omega*s+omega**2))
2222
plt.close('all')
23-
sisotool(-H)
23+
ct.sisotool(-H)
2424

2525
#%%
2626

2727
# a simple RL, with multiple poles in the origin
2828
plt.close('all')
2929
H = (s+0.3)/(s**4 + 4*s**3 + 6.25*s**2)
30-
sisotool(H)
30+
ct.sisotool(H)
3131

3232
#%%
3333

@@ -43,4 +43,4 @@
4343
plt.close('all')
4444
H = (b0 + b1*s + b2*s**2) / (a0 + a1*s + a2*s**2 + a3*s**3)
4545

46-
sisotool(H)
46+
ct.sisotool(H)

examples/slycot-import-test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
import numpy as np
8-
from control.matlab import *
8+
import control as ct
99
from control.exception import slycot_check
1010

1111
# Parameters defining the system
@@ -17,12 +17,12 @@
1717
A = np.array([[1, -1, 1.], [1, -k/m, -b/m], [1, 1, 1]])
1818
B = np.array([[0], [1/m], [1]])
1919
C = np.array([[1., 0, 1.]])
20-
sys = ss(A, B, C, 0)
20+
sys = ct.ss(A, B, C, 0)
2121

2222
# Python control may be used without slycot, for example for a pole placement.
2323
# Eigenvalue placement
2424
w = [-3, -2, -1]
25-
K = place(A, B, w)
25+
K = ct.place(A, B, w)
2626
print("[python-control (from scipy)] K = ", K)
2727
print("[python-control (from scipy)] eigs = ", np.linalg.eig(A - B*K)[0])
2828

examples/type2_type3.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
import os
66
import matplotlib.pyplot as plt # Grab MATLAB plotting functions
7-
from control.matlab import * # MATLAB-like functions
8-
from numpy import pi
9-
integrator = tf([0, 1], [1, 0]) # 1/s
7+
import control as ct
8+
import numpy as np
9+
10+
integrator = ct.tf([0, 1], [1, 0]) # 1/s
1011

1112
# Parameters defining the system
1213
J = 1.0
@@ -29,20 +30,20 @@
2930

3031
# System Transfer Functions
3132
# tricky because the disturbance (base motion) is coupled in by friction
32-
closed_loop_type2 = feedback(C_type2*feedback(P, friction), gyro)
33+
closed_loop_type2 = ct.feedback(C_type2*ct.feedback(P, friction), gyro)
3334
disturbance_rejection_type2 = P*friction/(1. + P*friction+P*C_type2)
34-
closed_loop_type3 = feedback(C_type3*feedback(P, friction), gyro)
35+
closed_loop_type3 = ct.feedback(C_type3*ct.feedback(P, friction), gyro)
3536
disturbance_rejection_type3 = P*friction/(1. + P*friction + P*C_type3)
3637

3738
# Bode plot for the system
3839
plt.figure(1)
39-
bode(closed_loop_type2, logspace(0, 2)*2*pi, dB=True, Hz=True) # blue
40-
bode(closed_loop_type3, logspace(0, 2)*2*pi, dB=True, Hz=True) # green
40+
ct.bode(closed_loop_type2, np.logspace(0, 2)*2*np.pi, dB=True, Hz=True) # blue
41+
ct.bode(closed_loop_type3, np.logspace(0, 2)*2*np.pi, dB=True, Hz=True) # green
4142
plt.show(block=False)
4243

4344
plt.figure(2)
44-
bode(disturbance_rejection_type2, logspace(0, 2)*2*pi, Hz=True) # blue
45-
bode(disturbance_rejection_type3, logspace(0, 2)*2*pi, Hz=True) # green
45+
ct.bode(disturbance_rejection_type2, np.logspace(0, 2)*2*np.pi, Hz=True) # blue
46+
ct.bode(disturbance_rejection_type3, np.logspace(0, 2)*2*np.pi, Hz=True) # green
4647

4748
if 'PYCONTROL_TEST_EXAMPLES' not in os.environ:
4849
plt.show()

examples/vehicle.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import numpy as np
55
import matplotlib.pyplot as plt
6-
import control as ct
76
import control.flatsys as fs
87

98
#

0 commit comments

Comments
 (0)