Skip to content

Commit 7689c2c

Browse files
author
Kevin Chen
committed
merging changes
bbelson@rainier.princeton.edu
1 parent acadc2d commit 7689c2c

9 files changed

Lines changed: 44 additions & 36 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: 6 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
@@ -23,8 +24,8 @@
2324
Po = tf([1], [m, c, 0]); # outer loop (position)
2425

2526
# Use state space versions
26-
# Pi = tf2ss(Pi);
27-
# Po = tf2ss(Po);
27+
Pi = tf2ss(Pi);
28+
Po = tf2ss(Po);
2829

2930
#
3031
# Inner loop control design
@@ -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]

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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,18 @@
4242

4343
import matplotlib.pyplot as plt
4444
import scipy as sp
45+
import numpy as np
4546
import xferfcn
4647

4748
# Compute poles and zeros for a system
4849
#! TODO: extend this to handle state space systems
4950
def pzmap(sys, Plot=True):
5051
"""Plot a pole/zero map for a transfer function"""
5152
if (isinstance(sys, xferfcn.TransferFunction)):
52-
poles = sp.roots(sys.den);
53-
zeros = sp.roots(sys.num);
53+
poles = sp.roots(np.squeeze(np.asarray(sys.den)));
54+
zeros = sp.roots(np.squeeze(np.asarray(sys.num)));
5455
else:
55-
raise TypeException
56+
raise NotImplementedError("pzmap not implemented for state space systems yet.")
5657

5758
if (Plot):
5859
# 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]

src/xferfcn.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -344,14 +344,14 @@ def __rmul__(self, other):
344344
def __div__(self, other):
345345
"""Divide two LTI objects."""
346346

347+
# Convert the second argument to a transfer function.
348+
other = _convertToTransferFunction(other)
349+
347350
if (self.inputs > 1 or self.outputs > 1 or
348351
other.inputs > 1 or other.outputs > 1):
349352
raise NotImplementedError("TransferFunction.__div__ is currently \
350353
implemented only for SISO systems.")
351354

352-
# Convert the second argument to a transfer function.
353-
other = _convertToTransferFunction(other)
354-
355355
num = polymul(self.num[0][0], other.den[0][0])
356356
den = polymul(self.den[0][0], other.num[0][0])
357357

@@ -487,8 +487,9 @@ def _common_den(self):
487487
488488
computes the single denominator containing all the poles of sys.den, and
489489
reports it as the array d. The output numerator array n is modified to
490-
use the common denominator. It is an sys.outputs-by-sys.inputs-by-
491-
[something] array.
490+
use the common denominator; the coefficient arrays are also padded with
491+
zeros to be the same size as d. n is an sys.outputs-by-sys.inputs-by-
492+
len(d) array.
492493
493494
"""
494495

@@ -588,16 +589,12 @@ def _common_den(self):
588589
# Multiply in the missing poles.
589590
for p in missingpoles[i][j]:
590591
num[i][j] = polymul(num[i][j], [1., -p])
591-
# Find the largest numerator polynomial size.
592-
largest = 0
593-
for i in range(self.outputs):
594-
for j in range(self.inputs):
595-
largest = max(largest, len(num[i][j]))
596-
# Pad all smaller numerator polynomials with zeros.
592+
# Pad all numerator polynomials with zeros so that the numerator arrays
593+
# are the same size as the denominator.
597594
for i in range(self.outputs):
598595
for j in range(self.inputs):
599-
num[i][j] = insert(num[i][j], zeros(largest - len(num[i][j])),
600-
zeros(largest - len(num[i][j])))
596+
num[i][j] = insert(num[i][j], zeros(len(den) - len(num[i][j])),
597+
zeros(len(den) - len(num[i][j])))
601598
# Finally, convert the numerator to a 3-D array.
602599
num = array(num)
603600
# Remove trivial imaginary parts. Check for nontrivial imaginary parts.

0 commit comments

Comments
 (0)