8000 changes for python 3 · MaxGaukler/python-control@038785a · GitHub
[go: up one dir, main page]

Skip to content

Commit 038785a

Browse files
committed
changes for python 3
1 parent af7fa06 commit 038785a

23 files changed

+198
-251
lines changed

ChangeLog

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,52 @@
1+
2012-11-02 Richard Murray <murray@altura.local>
2+
3+
* src/xferfcn.py, src/timeresp.py, src/statesp.py, src/statefbk.py,
4+
src/robust.py, src/rlocus.py, src/pzmap.py, src/phaseplot.py,
5+
src/nichols.py, src/modelsimp.py, src/matlab.py, src/margins.py,
6+
src/freqplot.py, src/ctrlutil.py, src/bdalg.py: globally referenced
7+
import commands for python 3.x
8+
9+
* src/__init__.py: changed import commands to be global instead of
10+
local ('from control.bdalg ...' instead of 'from bdalg ...')
11+
12+
2012-10-31 Richard Murray <murray@altura.local>
13+
14+
* src/xferfcn.py (TransferFunction._common_den): converted print
15+
statements to python 3 compatible form and included
16+
__future__.print_function
17+
18+
* src/phaseplot.py: converted print statements to python 3
19+
compatible form and included __future__.print_function
20+
21+
* src/mateqn.py (lyap, dlyap): converted except T, E to except T(E)
22+
23+
* src/margins.py: converted print statements to python 3
24+
compatible form and included __future__.print_function
25+
26+
* src/xferfcn.py (TransferFunction.__add__, __mul__, __div__,
27+
feedback): converted raise T, E to raise T(E) for python 3
28+
29+
* src/xferfcn.py (TransferFunction.returnScipySignalLti): fixed
30+
raise(T(E)) bug
31+
32+
* src/statesp.py (_rss_generate): fixed raise(T(E)) bug
33+
34+
* src/statefbk.py (acker, gram): converted raise T, E to raise T(E) for
35+
python 3
36+
37+
* src/modelsimp.py (hsvd, modred, balred): fixed raise(T(E)) bug and
38+
converted raise T, E to raise T(E) for python 3
39+
40+
* src/margins.py (stability_margins): fixed raise(T(E)) bug
41+
42+
* src/statesp.py: converted raise T, E to raise T(E) for python 3
43+
44+
* tests/test_all.py: converted print statements to python 3
45+
compatible form and included __future__.print_function
46+
47+
* tests/statefbk_test.py (TestStatefbk.setUp): turned off debugging
48+
flag (accidently left on)
49+
150
2012-10-27 Richard Murray <murray@altura.local>
251

352
* src/statefbk.py (acker): small updates to docstring

src/__init__.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,30 @@
5757

5858
# Import functions from within the control system library
5959
#! Should probably only import the exact functions we use...
60-
from bdalg import series, parallel, negate, feedback
61-
from delay import pade
62-
from dtime import sample_system
63-
from freqplot import bode_plot, nyquist_plot, gangof4_plot
64-
from freqplot import bode, nyquist, gangof4
65-
from lti import timebase, timebaseEqual, isdtime, isctime
66-
from margins import stability_margins, phase_crossover_frequencies
67-
from mateqn import lyap, dlyap, care, dare
68-
from modelsimp import hsvd, modred, balred, era, markov
69-
from nichols import nichols_plot, nichols
70-
from phaseplot import phase_plot, box_grid
71-
from rlocus import root_locus
72-
from statefbk import place, lqr, ctrb, obsv, gram, acker
73-
from statesp import StateSpace
74-
from timeresp import forced_response, initial_response, step_response, \
60+
from control.bdalg import series, parallel, negate, feedback
61+
from control.delay import pade
62+
from control.dtime import sample_system
63+
from control.freqplot import bode_plot, nyquist_plot, gangof4_plot
64+
from control.freqplot import bode, nyquist, gangof4
65+
from control.lti import timebase, timebaseEqual, isdtime, isctime
66+
from control.margins import stability_margins, phase_crossover_frequencies
67+
from control.mateqn import lyap, dlyap, care, dare
68+
from control.modelsimp import hsvd, modred, balred, era, markov
69+
from control.nichols import nichols_plot, nichols
70+
from control.phaseplot import phase_plot, box_grid
71+
from control.rlocus import root_locus
72+
from control.statefbk import place, lqr, ctrb, obsv, gram, acker
73+
from control.statesp import StateSpace
74+
from control.timeresp import forced_response, initial_response, step_response, \
7575
impulse_response
76-
from xferfcn import TransferFunction
76+
from control.xferfcn import TransferFunction
77+
from control.ctrlutil import unwrap, issys
7778

7879
# Import some of the more common (and benign) MATLAB shortcuts
7980
# By default, don't import conflicting commands here
80-
from matlab import ss, tf, ss2tf, tf2ss, drss
81-
from matlab import pole, zero, evalfr, freqresp, dcgain
82-
from matlab import nichols, rlocus, margin
81+
from control.matlab import ss, tf, ss2tf, tf2ss, drss
82+
from control.matlab import pole, zero, evalfr, freqresp, dcgain
83+
from control.matlab import nichols, rlocus, margin
8384
# bode and nyquist come directly from freqplot.py
84-
from matlab import step, impulse, initial, lsim
85-
from matlab import ssdata, tfdata
85+
from control.matlab import step, impulse, initial, lsim
86+
from control.matlab import ssdata, tfdata

src/bdalg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
"""
5353

5454
import scipy as sp
55-
import xferfcn as tf
56-
import statesp as ss
55+
import control.xferfcn as tf
56+
import control.statesp as ss
5757

5858
def series(sys1, sys2):
5959
"""Return the series connection sys2 * sys1 for --> sys1 --> sys2 -->.

src/ctrlutil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242

4343
# Packages that we need access to
4444
import scipy as sp
45-
import statesp
46-
import xferfcn
45+
import control.statesp as statesp
46+
import control.xferfcn as xferfcn
4747

4848
# Specific functions that we use
4949
from scipy import pi

src/delay.py

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

4343
from __future__ import division
4444

45-
4645
def pade(T, n=1):
4746
"""
4847
Create a linear system that approximates a delay.

src/dtime.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@
5151
import numpy as np
5252
from cmath import exp
5353
from warnings import warn
54-
from lti import isctime
55-
from statesp import StateSpace, _convertToStateSpace
56-
from xferfcn import TransferFunction, _convertToTransferFunction
54+
from control.lti import isctime
55+
from control.statesp import StateSpace, _convertToStateSpace
56+
from control.xferfcn import TransferFunction, _convertToTransferFunction
5757

5858
# Sample a continuous time system
5959
def sample_system(sysc, Ts, method='matched'):

src/freqplot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
import scipy as sp
4646
import numpy as np
4747
from warnings import warn
48-
from ctrlutil import unwrap
49-
from bdalg import feedback
50-
from lti import isdtime, timebaseEqual
48+
from control.ctrlutil import unwrap
49+
from control.bdalg import feedback
50+
from control.lti import isdtime, timebaseEqual
5151

5252
#
5353
# Main plotting functions

src/margins.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
"""margin.py
23
34
Functions for computing stability margins and related functions.
@@ -47,10 +48,10 @@
4748
4849
"""
4950

50-
import xferfcn
51-
from freqplot import bode
5251
import numpy as np
53-
from lti import isdtime
52+
import control.xferfcn as xferfcn
53+
from control.freqplot import bode
54+
from control.lti import isdtime
5455

5556
# gain and phase margins
5657
# contributed by Sawyer B. Fuller <minster@caltech.edu>
@@ -92,7 +93,7 @@ def stability_margins(sysdata, deg=True):
9293

9394
# TODO: implement for discrete time systems
9495
if (isdtime(sys, strict=True)):
95-
raise(NotImplementedError("Function not implemented in discrete time"))
96+
raise NotImplementedError("Function not implemented in discrete time")
9697

9798
mag, phase, omega = bode(sys, deg=deg, Plot=False)
9899
elif len(sysdata) == 3:
@@ -118,15 +119,15 @@ def stability_margins(sysdata, deg=True):
118119
wp = np.nan
119120
pm = np.inf
120121
else: # gain always greater than one
121-
print "margin: no magnitude crossings found"
122+
print("margin: no magnitude crossings found")
122123
wp = np.nan
123124
pm = np.nan
124125
else:
125126
min_mag_crossing_i = neg_mag_crossings_i[np.argmin(mag_crossings_p)]
126127
wp = omega[min_mag_crossing_i]
127128
pm = crossover + phase[min_mag_crossing_i]
128129
if pm < 0:
129-
print "warning: system unstable: negative phase margin"
130+
print("warning: system unstable: negative phase margin")
130131

131132
# gain margin from minimum gain margin among all phase crossovers
132133
neg_phase_crossings_i = np.nonzero(np.diff(wrapped_phase < -crossover) > 0)[0]
@@ -140,7 +141,7 @@ def stability_margins(sysdata, deg=True):
140141
wg = omega[min_phase_crossing_i]
141142
gm = abs(1/mag[min_phase_crossing_i])
142143
if gm < 1:
143-
print "warning: system unstable: gain margin < 1"
144+
print("warning: system unstable: gain margin < 1")
144145

145146
# stability margin from minimum abs distance from -1 point
146147
if deg:

src/mateqn.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939

4040
from numpy.linalg import inv
4141
from scipy import shape, size, asarray, copy, zeros, eye, dot
42-
43-
from exception import ControlSlycot, ControlArgument
42+
from control.exception import ControlSlycot, ControlArgument
4443

4544
#### Lyapunov equation solvers lyap and dlyap
4645

@@ -120,7 +119,7 @@ def lyap(A,Q,C=None,E=None):
120119
# Solve the Lyapunov equation by calling Slycot function sb03md
121120
try:
122121
X,scale,sep,ferr,w = sb03md(n,-Q,A,eye(n,n),'C',trana='T')
123-
except ValueError, ve:
122+
except ValueError(ve):
124123
if ve.info < 0:
125124
e = ValueError(ve.message)
126125
e.info = ve.info
@@ -151,7 +150,7 @@ def lyap(A,Q,C=None,E=None):
151150
# Solve the Sylvester equation by calling the Slycot function sb04md
152151
try:
153152
X = sb04md(n,m,A,Q,-C)
154-
except ValueError, ve:
153+
except ValueError(ve):
155154
if ve.info < 0:
156155
e = ValueError(ve.message)
157156
e.info = ve.info
@@ -194,7 +193,7 @@ def lyap(A,Q,C=None,E=None):
194193
try:
195194
A,E,Q,Z,X,scale,sep,ferr,alphar,alphai,beta = \
196195
sg03ad('C','B','N','T','L',n,A,E,eye(n,n),eye(n,n),-Q)
197-
except ValueError, ve:
196+
except ValueError(ve):
198197
if ve.info < 0 or ve.info > 4:
199198
e = ValueError(ve.message)
200199
e.info = ve.info
@@ -307,7 +306,7 @@ def dlyap(A,Q,C=None,E=None):
307306
# Solve the Lyapunov equation by calling the Slycot function sb03md
308307
try:
309308
X,scale,sep,ferr,w = sb03md(n,-Q,A,eye(n,n),'D',trana='T')
310-
except ValueError, ve:
309+
except ValueError(ve):
311310
if ve.info < 0:
312311
e = ValueError(ve.message)
313312
e.info = ve.info
@@ -334,7 +333,7 @@ def dlyap(A,Q,C=None,E=None):
334333
# Solve the Sylvester equation by calling Slycot function sb04qd
335334
try:
336335
X = sb04qd(n,m,-A,asarray(Q).T,C)
337-
except ValueError, ve:
336+
except ValueError(ve):
338337
if ve.info < 0:
339338
e = ValueError(ve.message)
340339
e.info = ve.info
@@ -371,7 +370,7 @@ def dlyap(A,Q,C=None,E=None):
371370
try:
372371
A,E,Q,Z,X,scale,sep,ferr,alphar,alphai,beta = \
373372
sg03ad('D','B','N','T','L',n,A,E,eye(n,n),eye(n,n),-Q)
374-
except ValueError, ve:
373+
except ValueError(ve):
375374
if ve.info < 0 or ve.info > 4:
376375
e = ValueError(ve.message)
377376
e.info = ve.info
@@ -506,7 +505,7 @@ def care(A,B,Q,R=None,S=None,E=None):
506505
# functions sb02mt and sb02md
507506
try:
508507
A_b,B_b,Q_b,R_b,L_b,ipiv,oufact,G = sb02mt(n,m,B,R)
509-
except ValueError, ve:
508+
except ValueError(ve):
510509
if ve.info < 0:
511510
e = ValueError(ve.message)
512511
e.info = ve.info
@@ -521,7 +520,7 @@ def care(A,B,Q,R=None,S=None,E=None):
521520

522521
try:
523522
X,rcond,w,S_o,U,A_inv = sb02md(n,A,G,Q,'C')
524-
except ValueError, ve:
523+
except ValueError(ve):
525524
if ve.info < 0 or ve.info > 5:
526525
e = ValueError(ve.message)
527526
e.info = ve.info
@@ -608,7 +607,7 @@ def care(A,B,Q,R=None,S=None,E=None):
608607
try:
609608
rcondu,X,alfar,alfai,beta,S_o,T,U,iwarn = \
610609
sg02ad('C','B','N','U','N','N','S','R',n,m,0,A,E,B,Q,R,S)
611-
except ValueError, ve:
610+
except ValueError(ve):
612611
if ve.info < 0 or ve.info > 7:
613612
e = ValueError(ve.message)
614613
e.info = ve.info
@@ -765,7 +764,7 @@ def dare(A,B,Q,R,S=None,E=None):
765764
# functions sb02mt and sb02md
766765
try:
767766
A_b,B_b,Q_b,R_b,L_b,ipiv,oufact,G = sb02mt(n,m,B,R)
768-
except ValueError, ve:
767+
except ValueError(ve):
769768
if ve.info < 0:
770769
e = ValueError(ve.message)
771770
e.info = ve.info
@@ -780,7 +779,7 @@ def dare(A,B,Q,R,S=None,E=None):
780779

781780
try:
782781
X,rcond,w,S,U,A_inv = sb02md(n,A,G,Q,'D')
783-
except ValueError, ve:
782+
except ValueError(ve):
784783
if ve.info < 0 or ve.info > 5:
785784
e = ValueError(ve.message)
786785
e.info = ve.info
@@ -870,7 +869,7 @@ def dare(A,B,Q,R,S=None,E=None):
870869
try:
871870
rcondu,X,alfar,alfai,beta,S_o,T,U,iwarn = \
872871
sg02ad('D','B','N','U','N','N','S','R',n,m,0,A,E,B,Q,R,S)
873-
except ValueError, ve:
872+
except ValueError(ve):
874873
if ve.info < 0 or ve.info > 7:
875874
e = ValueError(ve.message)
876875
e.info = ve.info

src/matlab.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,26 @@
7070
from numpy import linspace, logspace
7171

7272
# Control system library
73-
import ctrlutil
74-
import freqplot
75-
import timeresp
76-
import margins
77-
from statesp import StateSpace, _rss_generate, _convertToStateSpace
78-
from xferfcn import TransferFunction, _convertToTransferFunction
79-
from lti import Lti #base class of StateSpace, TransferFunction
80-
from dtime import sample_system
81-
from exception import ControlArgument
73+
import control.ctrlutil as ctrlutil
74+
import control.freqplot as freqplot
75+
import control.timeresp as timeresp
76+
import control.margins as margins
77+
from control.statesp import StateSpace, _rss_generate, _convertToStateSpace
78+
from control.xferfcn import TransferFunction, _convertToTransferFunction
79+
from control.lti import Lti #base class of StateSpace, TransferFunction
80+
from control.dtime import sample_system
81+
from control.exception import ControlArgument
8282

8383
# Import MATLAB-like functions that can be used as-is
84-
from ctrlutil import unwrap
85-
from freqplot import nyquist, gangof4
86-
from nichols import nichols
87-
from bdalg import series, parallel, negate, feedback
88-
from pzmap import pzmap
89-
from statefbk import ctrb, obsv, gram, place, lqr
90-
from delay import pade
91-
from modelsimp import hsvd, balred, modred
92-
from mateqn import lyap, dlyap, dare, care
84+
from control.ctrlutil import unwrap
85+
from control.freqplot import nyquist, gangof4
86+
from control.nichols import nichols
87+
from control.bdalg import series, parallel, negate, feedback
88+
from control.pzmap import pzmap
89+
from control.statefbk import ctrb, obsv, gram, place, lqr
90+
from control.delay import pade
91+
from control.modelsimp import hsvd, balred, modred
92+
from control.mateqn import lyap, dlyap, dare, care
9393

9494
__doc__ += r"""
9595
The following tables give an overview of the module ``control.matlab``.
@@ -999,7 +999,7 @@ def bode(*args, **keywords):
999999
return freqplot.bode(syslist, omega, **keywords)
10001000

10011001
# Nichols chart grid
1002-
from nichols import nichols_grid
1002+
from control.nichols import nichols_grid
10031003
def ngrid():
10041004
nichols_grid()
10051005
ngrid.__doc__ = re.sub('nichols_grid', 'ngrid', nichols_grid.__doc__)
@@ -1022,7 +1022,7 @@ def rlocus(sys, klist = None, **keywords):
10221022
klist:
10231023
list of gains used to compute roots
10241024
"""
1025-
from rlocus import root_locus
1025+
from control.rlocus import root_locus
10261026
#! TODO: update with a smart calculation of the gains using sys poles/zeros
10271027
if klist == None:
10281028
klist = logspace(-3, 3)

0 commit comments

Comments
 (0)
0