Skip to content

Commit c99651a

Browse files
author
Kevin Chen
committed
Modified examples so that they are compatible with the new classes. Minor changes to some of the python-control files to handle bugs found in examples.
Lauren Padilla <lpadilla@princeton.edu>
1 parent 9316665 commit c99651a

9 files changed

Lines changed: 30 additions & 20 deletions

File tree

examples/pvtol-lqr.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119

120120
subplot(221); title("Identity weights")
121121
# plot(T, Y[:,1, 1], '-', T, Y[:,2, 2], '--'); hold(True);
122-
plot(Tx, Yx[0,:].T, '-', Ty, Yy[0,:].T, '--'); hold(True);
122+
plot(Tx.T, Yx[0,:].T, '-', Ty.T, Yy[0,:].T, '--'); hold(True);
123123
plot([0, 10], [1, 1], 'k-'); hold(True);
124124

125125
axis([0, 10, -0.1, 1.4]);
@@ -141,9 +141,9 @@
141141
[T3, Y3] = step(H1cx, T=linspace(0,10,100));
142142

143143
subplot(222); title("Effect of input weights")
144-
plot(T1, Y1[0,:].T, 'b-'); hold(True);
145-
plot(T2, Y2[0,:].T, 'b-'); hold(True);
146-
plot(T3, Y3[0,:].T, 'b-'); hold(True);
144+
plot(T1.T, Y1[0,:].T, 'b-'); hold(True);
145+
plot(T2.T, Y2[0,:].T, 'b-'); hold(True);
146+
plot(T3.T, Y3[0,:].T, 'b-'); hold(True);
147147
plot([0 ,10], [1, 1], 'k-'); hold(True);
148148

149149
axis([0, 10, -0.1, 1.4]);
@@ -162,7 +162,7 @@
162162
subplot(223); title("Output weighting")
163163
[T2x, Y2x] = step(H2x, T=linspace(0,10,100));
164164
[T2y, Y2y] = step(H2y, T=linspace(0,10,100));
165-
plot(T2x, Y2x[0,:].T, T2y, Y2y[0,:].T)
165+
plot(T2x.T, Y2x[0,:].T, T2y.T, Y2y[0,:].T)
166166
ylabel('position');
167167
xlabel('time'); ylabel('position');
168168
legend(('x', 'y'), loc='lower right');
@@ -185,7 +185,7 @@
185185
# step(H3x, H3y, 10);
186186
[T3x, Y3x] = step(H3x, T=linspace(0,10,100));
187187
[T3y, Y3y] = step(H3y, T=linspace(0,10,100));
188-
plot(T3x, Y3x[0,:].T, T3y, Y3y[0,:].T)
188+
plot(T3x.T, Y3x[0,:].T, T3y.T, Y3y[0,:].T)
189189
title("Physically motivated weights")
190190
xlabel('time');
191191
legend(('x', 'y'), loc='lower right');

examples/pvtol-nested-ss.py

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

1111
from matplotlib.pyplot import * # Grab MATLAB plotting functions
1212
from control.matlab import * # MATLAB-like functions
13+
import numpy as np
1314

1415
# System parameters
1516
m = 4; # mass of aircraft
@@ -107,7 +108,7 @@
107108
subplot(phaseh);
108109
semilogx([10^-4, 10^3], [-180, -180], 'k-')
109110
hold(True);
110-
semilogx(w, phase, 'b-')
111+
semilogx(w, np.squeeze(phase), 'b-')
111112
axis([10^-4, 10^3, -360, 0]);
112113
xlabel('Frequency [deg]'); ylabel('Phase [deg]');
113114
# set(gca, 'YTick', [-360, -270, -180, -90, 0]);
@@ -144,14 +145,15 @@
144145

145146
figure(9);
146147
(Tvec, Yvec) = step(T, None, linspace(1, 20));
147-
plot(Tvec, Yvec); hold(True);
148+
plot(Tvec.T, Yvec.T); hold(True);
148149

149150
(Tvec, Yvec) = step(Co*S, None, linspace(1, 20));
150-
plot(Tvec, Yvec);
151+
plot(Tvec.T, Yvec.T);
151152

153+
#TODO: PZmap for statespace systems has not yet been implemented.
152154
figure(10); clf();
153-
(P, Z) = pzmap(T, Plot=True)
154-
print "Closed loop poles and zeros: ", P, Z
155+
#(P, Z) = pzmap(T, Plot=True)
156+
#print "Closed loop poles and zeros: ", P, Z
155157

156158
# Gang of Four
157159
figure(11); clf();

examples/pvtol-nested.py

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

1111
from matplotlib.pyplot import * # Grab MATLAB plotting functions
1212
from control.matlab import * # MATLAB-like functions
13+
import numpy as np
1314

1415
# System parameters
1516
m = 4; # mass of aircraft
@@ -97,7 +98,7 @@
9798
subplot(phaseh);
9899
semilogx([10^-4, 10^3], [-180, -180], 'k-')
99100
hold(True);
100-
semilogx(w, phase, 'b-')
101+
semilogx(w, np.squeeze(phase), 'b-')
101102
axis([10^-4, 10^3, -360, 0]);
102103
xlabel('Frequency [deg]'); ylabel('Phase [deg]');
103104
# set(gca, 'YTick', [-360, -270, -180, -90, 0]);
@@ -134,10 +135,10 @@
134135

135136
figure(9);
136137
(Tvec, Yvec) = step(T, None, linspace(1, 20));
137-
plot(Tvec, Yvec); hold(True);
138+
plot(Tvec.T, Yvec.T); hold(True);
138139

139140
(Tvec, Yvec) = step(Co*S, None, linspace(1, 20));
140-
plot(Tvec, Yvec);
141+
plot(Tvec.T, Yvec.T);
141142

142143
figure(10); clf();
143144
(P, Z) = pzmap(T, Plot=True)

examples/secord-matlab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Step response for the system
1919
figure(1)
2020
T, yout = step(sys)
21-
plot(T, yout)
21+
plot(T.T, yout.T)
2222

2323
# Bode plot for the system
2424
figure(2)

examples/slicot-test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
sys = ss(A, B, C, 0);
1818

1919
# Eigenvalue placement
20-
from slycot import sb01bd
20+
#from slycot import sb01bd
2121
K = place(A, B, [-3, -2, -1])
2222
print "Pole place: K = ", K
2323
print "Pole place: eigs = ", np.linalg.eig(A - B * K)[0]

examples/type2_type3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
Kii = Ki
1616

1717
# Plant transfer function from torque to rate
18-
inertia = integrator*1/J
18+
inertia = integrator*(1/J)
1919
friction = b # transfer function from rate to torque
2020
P = inertia # friction is modelled as a separate block
2121

src/freqplot.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,12 @@ def nyquist(syslist, omega=None):
177177
# Select a default range if none is provided
178178
if (omega == None):
179179
omega = default_frequency_range(syslist)
180-
180+
# Interpolate between wmin and wmax if a tuple or list are provided
181+
elif (isinstance(omega,list) | isinstance(omega,tuple)):
182+
# Only accept tuple or list of length 2
183+
if (len(omega) != 2):
184+
raise ValueError("Supported frequency arguments are (wmin,wmax) tuple or list, or frequency vector. ")
185+
omega = np.logspace(np.log10(omega[0]),np.log10(omega[1]),num=50,endpoint=True,base=10.0)
181186
for sys in syslist:
182187
if (sys.inputs > 1 or sys.outputs > 1):
183188
#TODO: Add MIMO nyquist plots.

src/pzmap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def pzmap(sys, Plot=True):
5252
poles = sp.roots(sys.den);
5353
zeros = sp.roots(sys.num);
5454
else:
55-
raise TypeException
55+
raise NotImplementedError("pzmap not implemented for state space systems yet.")
5656

5757
if (Plot):
5858
# Plot the locations of the poles and zeros

src/statesp.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"""
7474

7575
from numpy import all, angle, any, array, concatenate, cos, delete, dot, \
76-
empty, exp, eye, matrix, ones, pi, poly, poly1d, roots, sin, zeros
76+
empty, exp, eye, matrix, ones, pi, poly, poly1d, roots, shape, sin, zeros
7777
from numpy.random import rand, randn
7878
from numpy.linalg import inv, det, solve
7979
from numpy.linalg.linalg import LinAlgError
@@ -456,6 +456,8 @@ def _convertToStateSpace(sys, **kw):
456456
# TODO: transfer function to state space conversion is still buggy!
457457
print "Warning: transfer function to state space conversion by td04ad \
458458
is still buggy!"
459+
#print num
460+
#print shape(num)
459461
ssout = td04ad(sys.inputs, sys.outputs, index, den, num)
460462

461463
states = ssout[0]

0 commit comments

Comments
 (0)