|
46 | 46 | # $Id$ |
47 | 47 |
|
48 | 48 | # Packages used by this module |
| 49 | +import numpy as np |
49 | 50 | from scipy import array, poly1d, row_stack, zeros_like, real, imag |
50 | 51 | import scipy.signal # signal processing toolbox |
51 | 52 | import pylab # plotting routines |
52 | 53 | from . import xferfcn |
53 | 54 | from .exception import ControlMIMONotImplemented |
54 | 55 | from functools import partial |
55 | 56 |
|
56 | | - |
57 | 57 | # Main function: compute a root locus diagram |
58 | | -def root_locus(sys, kvect, xlim=None, ylim=None, plotstr='-', Plot=True, |
| 58 | +def root_locus(sys, kvect=None, xlim=None, ylim=None, plotstr='-', Plot=True, |
59 | 59 | PrintGain=True): |
60 | 60 | """Calculate the root locus by finding the roots of 1+k*TF(s) |
61 | 61 | where TF is self.num(s)/self.den(s) and each k is an element |
62 | 62 | of kvect. |
63 | 63 |
|
64 | 64 | Parameters |
65 | 65 | ---------- |
66 | | - sys : linsys |
| 66 | + sys : LTI object |
67 | 67 | Linear input/output systems (SISO only, for now) |
68 | | - kvect : gain_range (default = None) |
| 68 | + kvect : list or ndarray, optional |
69 | 69 | List of gains to use in computing diagram |
70 | | - xlim : control of x-axis range, normally with tuple, for |
71 | | - other options, see matplotlib.axes |
72 | | - ylim : control of y-axis range |
73 | | - Plot : boolean (default = True) |
| 70 | + xlim : tuple or list, optional |
| 71 | + control of x-axis range, normally with tuple (see matplotlib.axes) |
| 72 | + ylim : tuple or list, optional |
| 73 | + control of y-axis range |
| 74 | + Plot : boolean, optional (default = True) |
74 | 75 | If True, plot magnitude and phase |
75 | 76 | PrintGain: boolean (default = True) |
76 | 77 | If True, report mouse clicks when close to the root-locus branches, |
77 | 78 | calculate gain, damping and print |
78 | | - Return values |
79 | | - ------------- |
80 | | - rlist : list of computed root locations |
| 79 | +
|
| 80 | + Returns |
| 81 | + ------- |
| 82 | + rlist : ndarray |
| 83 | + Computed root locations, given as a 2d array |
| 84 | + klist : ndarray or list |
| 85 | + Gains used. Same as klist keyword argument if provided. |
81 | 86 | """ |
82 | 87 |
|
83 | 88 | # Convert numerator and denominator to polynomials if they aren't |
84 | 89 | (nump, denp) = _systopoly1d(sys) |
85 | 90 |
|
| 91 | + if kvect is None: |
| 92 | + kvect = _default_gains(sys) |
| 93 | + |
86 | 94 | # Compute out the loci |
87 | 95 | mymat = _RLFindRoots(sys, kvect) |
88 | 96 | mymat = _RLSortRoots(sys, mymat) |
@@ -116,8 +124,11 @@ def root_locus(sys, kvect, xlim=None, ylim=None, plotstr='-', Plot=True, |
116 | 124 | ax.set_xlabel('Real') |
117 | 125 | ax.set_ylabel('Imaginary') |
118 | 126 |
|
119 | | - return mymat |
| 127 | + return mymat, kvect |
120 | 128 |
|
| 129 | +def _default_gains(sys): |
| 130 | + # TODO: update with a smart calculation of the gains using sys poles/zeros |
| 131 | + return np.logspace(-3, 3) |
121 | 132 |
|
122 | 133 | # Utility function to extract numerator and denominator polynomials |
123 | 134 | def _systopoly1d(sys): |
|
0 commit comments