From: <kk...@us...> - 2011-02-08 22:18:57
|
Revision: 110 http://python-control.svn.sourceforge.net/python-control/?rev=110&view=rev Author: kkchen Date: 2011-02-08 22:18:49 +0000 (Tue, 08 Feb 2011) Log Message: ----------- 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 <lpa...@pr...> Modified Paths: -------------- branches/control-0.4a/examples/pvtol-lqr.py branches/control-0.4a/examples/pvtol-nested-ss.py branches/control-0.4a/examples/pvtol-nested.py branches/control-0.4a/examples/secord-matlab.py branches/control-0.4a/examples/slicot-test.py branches/control-0.4a/examples/type2_type3.py branches/control-0.4a/src/freqplot.py branches/control-0.4a/src/pzmap.py branches/control-0.4a/src/statesp.py Modified: branches/control-0.4a/examples/pvtol-lqr.py =================================================================== --- branches/control-0.4a/examples/pvtol-lqr.py 2011-02-08 22:18:42 UTC (rev 109) +++ branches/control-0.4a/examples/pvtol-lqr.py 2011-02-08 22:18:49 UTC (rev 110) @@ -119,7 +119,7 @@ subplot(221); title("Identity weights") # plot(T, Y[:,1, 1], '-', T, Y[:,2, 2], '--'); hold(True); -plot(Tx, Yx[0,:].T, '-', Ty, Yy[0,:].T, '--'); hold(True); +plot(Tx.T, Yx[0,:].T, '-', Ty.T, Yy[0,:].T, '--'); hold(True); plot([0, 10], [1, 1], 'k-'); hold(True); axis([0, 10, -0.1, 1.4]); @@ -141,9 +141,9 @@ [T3, Y3] = step(H1cx, T=linspace(0,10,100)); subplot(222); title("Effect of input weights") -plot(T1, Y1[0,:].T, 'b-'); hold(True); -plot(T2, Y2[0,:].T, 'b-'); hold(True); -plot(T3, Y3[0,:].T, 'b-'); hold(True); +plot(T1.T, Y1[0,:].T, 'b-'); hold(True); +plot(T2.T, Y2[0,:].T, 'b-'); hold(True); +plot(T3.T, Y3[0,:].T, 'b-'); hold(True); plot([0 ,10], [1, 1], 'k-'); hold(True); axis([0, 10, -0.1, 1.4]); @@ -162,7 +162,7 @@ subplot(223); title("Output weighting") [T2x, Y2x] = step(H2x, T=linspace(0,10,100)); [T2y, Y2y] = step(H2y, T=linspace(0,10,100)); -plot(T2x, Y2x[0,:].T, T2y, Y2y[0,:].T) +plot(T2x.T, Y2x[0,:].T, T2y.T, Y2y[0,:].T) ylabel('position'); xlabel('time'); ylabel('position'); legend(('x', 'y'), loc='lower right'); @@ -185,7 +185,7 @@ # step(H3x, H3y, 10); [T3x, Y3x] = step(H3x, T=linspace(0,10,100)); [T3y, Y3y] = step(H3y, T=linspace(0,10,100)); -plot(T3x, Y3x[0,:].T, T3y, Y3y[0,:].T) +plot(T3x.T, Y3x[0,:].T, T3y.T, Y3y[0,:].T) title("Physically motivated weights") xlabel('time'); legend(('x', 'y'), loc='lower right'); Modified: branches/control-0.4a/examples/pvtol-nested-ss.py =================================================================== --- branches/control-0.4a/examples/pvtol-nested-ss.py 2011-02-08 22:18:42 UTC (rev 109) +++ branches/control-0.4a/examples/pvtol-nested-ss.py 2011-02-08 22:18:49 UTC (rev 110) @@ -10,6 +10,7 @@ from matplotlib.pyplot import * # Grab MATLAB plotting functions from control.matlab import * # MATLAB-like functions +import numpy as np # System parameters m = 4; # mass of aircraft @@ -107,7 +108,7 @@ subplot(phaseh); semilogx([10^-4, 10^3], [-180, -180], 'k-') hold(True); -semilogx(w, phase, 'b-') +semilogx(w, np.squeeze(phase), 'b-') axis([10^-4, 10^3, -360, 0]); xlabel('Frequency [deg]'); ylabel('Phase [deg]'); # set(gca, 'YTick', [-360, -270, -180, -90, 0]); @@ -144,14 +145,15 @@ figure(9); (Tvec, Yvec) = step(T, None, linspace(1, 20)); -plot(Tvec, Yvec); hold(True); +plot(Tvec.T, Yvec.T); hold(True); (Tvec, Yvec) = step(Co*S, None, linspace(1, 20)); -plot(Tvec, Yvec); +plot(Tvec.T, Yvec.T); +#TODO: PZmap for statespace systems has not yet been implemented. figure(10); clf(); -(P, Z) = pzmap(T, Plot=True) -print "Closed loop poles and zeros: ", P, Z +#(P, Z) = pzmap(T, Plot=True) +#print "Closed loop poles and zeros: ", P, Z # Gang of Four figure(11); clf(); Modified: branches/control-0.4a/examples/pvtol-nested.py =================================================================== --- branches/control-0.4a/examples/pvtol-nested.py 2011-02-08 22:18:42 UTC (rev 109) +++ branches/control-0.4a/examples/pvtol-nested.py 2011-02-08 22:18:49 UTC (rev 110) @@ -10,6 +10,7 @@ from matplotlib.pyplot import * # Grab MATLAB plotting functions from control.matlab import * # MATLAB-like functions +import numpy as np # System parameters m = 4; # mass of aircraft @@ -97,7 +98,7 @@ subplot(phaseh); semilogx([10^-4, 10^3], [-180, -180], 'k-') hold(True); -semilogx(w, phase, 'b-') +semilogx(w, np.squeeze(phase), 'b-') axis([10^-4, 10^3, -360, 0]); xlabel('Frequency [deg]'); ylabel('Phase [deg]'); # set(gca, 'YTick', [-360, -270, -180, -90, 0]); @@ -134,10 +135,10 @@ figure(9); (Tvec, Yvec) = step(T, None, linspace(1, 20)); -plot(Tvec, Yvec); hold(True); +plot(Tvec.T, Yvec.T); hold(True); (Tvec, Yvec) = step(Co*S, None, linspace(1, 20)); -plot(Tvec, Yvec); +plot(Tvec.T, Yvec.T); figure(10); clf(); (P, Z) = pzmap(T, Plot=True) Modified: branches/control-0.4a/examples/secord-matlab.py =================================================================== --- branches/control-0.4a/examples/secord-matlab.py 2011-02-08 22:18:42 UTC (rev 109) +++ branches/control-0.4a/examples/secord-matlab.py 2011-02-08 22:18:49 UTC (rev 110) @@ -18,7 +18,7 @@ # Step response for the system figure(1) T, yout = step(sys) -plot(T, yout) +plot(T.T, yout.T) # Bode plot for the system figure(2) Modified: branches/control-0.4a/examples/slicot-test.py =================================================================== --- branches/control-0.4a/examples/slicot-test.py 2011-02-08 22:18:42 UTC (rev 109) +++ branches/control-0.4a/examples/slicot-test.py 2011-02-08 22:18:49 UTC (rev 110) @@ -17,7 +17,7 @@ sys = ss(A, B, C, 0); # Eigenvalue placement -from slycot import sb01bd +#from slycot import sb01bd K = place(A, B, [-3, -2, -1]) print "Pole place: K = ", K print "Pole place: eigs = ", np.linalg.eig(A - B * K)[0] Modified: branches/control-0.4a/examples/type2_type3.py =================================================================== --- branches/control-0.4a/examples/type2_type3.py 2011-02-08 22:18:42 UTC (rev 109) +++ branches/control-0.4a/examples/type2_type3.py 2011-02-08 22:18:49 UTC (rev 110) @@ -15,7 +15,7 @@ Kii = Ki # Plant transfer function from torque to rate -inertia = integrator*1/J +inertia = integrator*(1/J) friction = b # transfer function from rate to torque P = inertia # friction is modelled as a separate block Modified: branches/control-0.4a/src/freqplot.py =================================================================== --- branches/control-0.4a/src/freqplot.py 2011-02-08 22:18:42 UTC (rev 109) +++ branches/control-0.4a/src/freqplot.py 2011-02-08 22:18:49 UTC (rev 110) @@ -177,7 +177,12 @@ # Select a default range if none is provided if (omega == None): omega = default_frequency_range(syslist) - + # Interpolate between wmin and wmax if a tuple or list are provided + elif (isinstance(omega,list) | isinstance(omega,tuple)): + # Only accept tuple or list of length 2 + if (len(omega) != 2): + raise ValueError("Supported frequency arguments are (wmin,wmax) tuple or list, or frequency vector. ") + omega = np.logspace(np.log10(omega[0]),np.log10(omega[1]),num=50,endpoint=True,base=10.0) for sys in syslist: if (sys.inputs > 1 or sys.outputs > 1): #TODO: Add MIMO nyquist plots. Modified: branches/control-0.4a/src/pzmap.py =================================================================== --- branches/control-0.4a/src/pzmap.py 2011-02-08 22:18:42 UTC (rev 109) +++ branches/control-0.4a/src/pzmap.py 2011-02-08 22:18:49 UTC (rev 110) @@ -52,7 +52,7 @@ poles = sp.roots(sys.den); zeros = sp.roots(sys.num); else: - raise TypeException + raise NotImplementedError("pzmap not implemented for state space systems yet.") if (Plot): # Plot the locations of the poles and zeros Modified: branches/control-0.4a/src/statesp.py =================================================================== --- branches/control-0.4a/src/statesp.py 2011-02-08 22:18:42 UTC (rev 109) +++ branches/control-0.4a/src/statesp.py 2011-02-08 22:18:49 UTC (rev 110) @@ -73,7 +73,7 @@ """ from numpy import all, angle, any, array, concatenate, cos, delete, dot, \ - empty, exp, eye, matrix, ones, pi, poly, poly1d, roots, sin, zeros + empty, exp, eye, matrix, ones, pi, poly, poly1d, roots, shape, sin, zeros from numpy.random import rand, randn from numpy.linalg import inv, det, solve from numpy.linalg.linalg import LinAlgError @@ -456,6 +456,8 @@ # TODO: transfer function to state space conversion is still buggy! print "Warning: transfer function to state space conversion by td04ad \ is still buggy!" + #print num + #print shape(num) ssout = td04ad(sys.inputs, sys.outputs, index, den, num) states = ssout[0] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |