control-utils 1.0.4__tar.gz → 1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,17 @@
1
- Metadata-Version: 1.1
1
+ Metadata-Version: 2.4
2
2
  Name: control_utils
3
- Version: 1.0.4
4
- Summary: package for helping with teaching or learning feedback control
3
+ Version: 1.2
4
+ Summary: package for helpful tasks in feedback controls
5
5
  Home-page: https://github.com/ryanGT/control_utils
6
6
  Author: Ryan Krauss
7
7
  Author-email: ryanwkrauss@gmail.com
8
- License: UNKNOWN
9
- Description: UNKNOWN
10
- Platform: UNKNOWN
11
8
  Classifier: Programming Language :: Python :: 3
12
9
  Classifier: License :: OSI Approved :: MIT License
13
10
  Classifier: Operating System :: OS Independent
11
+ Requires-Dist: control
12
+ Dynamic: author
13
+ Dynamic: author-email
14
+ Dynamic: classifier
15
+ Dynamic: home-page
16
+ Dynamic: requires-dist
17
+ Dynamic: summary
@@ -5,8 +5,9 @@ import numpy as np
5
5
  import control
6
6
  from control import TransferFunction as TF
7
7
  import copy
8
+ from IPython.display import display, Math, Latex
8
9
 
9
- __version__ = '1.0.4'
10
+ __version__ = '1.1.0'
10
11
 
11
12
  font_size = 20.0
12
13
 
@@ -119,6 +120,15 @@ def root_list_to_latex(pole_list):
119
120
  with (wn,z) tuples. If an entry is scalar, it is a first order
120
121
  root."""
121
122
  str_out = ""
123
+ z_count = pole_list.count(0)
124
+ if z_count > 0:
125
+ if z_count == 1:
126
+ str_out = "s"
127
+ else:
128
+ str_out = "s^{%i}" % z_count
129
+ for i in range(z_count):
130
+ pole_list.pop(pole_list.index(0))
131
+
122
132
  for p in pole_list:
123
133
  cur_str = one_root_to_latex(p)
124
134
  if len(pole_list) == 1:
@@ -132,8 +142,8 @@ def root_list_to_latex(pole_list):
132
142
  def TF_to_factored_latex(G,lhs=None,substr=None):
133
143
  """Convert a TF instance to latex where the numerator and
134
144
  denominator are factored into first and second order terms."""
135
- p_list = second_order_roots_to_tuple(G.pole())
136
- z_list = second_order_roots_to_tuple(G.zero())
145
+ p_list = second_order_roots_to_tuple(G.poles())
146
+ z_list = second_order_roots_to_tuple(G.zeros())
137
147
  if not z_list:
138
148
  z_str = '1'
139
149
  else:
@@ -153,6 +163,11 @@ def TF_to_factored_latex(G,lhs=None,substr=None):
153
163
  return rhs
154
164
 
155
165
 
166
+ def factor_TF(G):
167
+ mystr = TF_to_factored_latex(G)
168
+ return display(Math(mystr))
169
+
170
+
156
171
  def print_factored_latex_for_TF(G, **kwargs):
157
172
  mystr = TF_to_factored_latex(G, **kwargs)
158
173
  print(mystr)
@@ -175,7 +190,7 @@ def build_TF(poles=[], zeros=[]):
175
190
 
176
191
 
177
192
  def root_locus_plot(G, k=None, xlim=None, ylim=None, fmtstr='-'):
178
- rmat, kout = control.root_locus(G, k, Plot=False)
193
+ rmat, kout = control.root_locus(G, k, plot=False)
179
194
  plot(real(rmat), imag(rmat), fmtstr)
180
195
  poles = G.pole()
181
196
  plot(real(poles), imag(poles), 'x')
@@ -189,9 +204,25 @@ def root_locus_plot(G, k=None, xlim=None, ylim=None, fmtstr='-'):
189
204
 
190
205
 
191
206
  def add_point_to_root_locus(G, k, fmtstr='^'):
192
- rmat, kout = control.root_locus(G, [k], Plot=False)
207
+ rmat, kout = control.root_locus(G, [k], plot=False)
193
208
  plot(real(rmat), imag(rmat), fmtstr)
209
+
210
+
211
+ def plot_zeta_line(z, r=50, fmtstr='k:'):
212
+ """Plot radial lines for a constant zeta"""
213
+ th = np.arcsin(z)
214
+ y_z = r*np.cos(th)
215
+ x_z = -r*z
216
+ plt.plot([0,x_z],[0,y_z],fmtstr)
217
+ plt.plot([0,x_z],[0,-y_z],fmtstr)
218
+
219
+
220
+ def plot_z_wn_line(zwn, fmtstr='b--'):
221
+ """Plot a vertical line through zwn which is the zeta*wn product."""
222
+ my_y = plt.ylim()
223
+ plt.plot([zwn,zwn],my_y,fmtstr)
194
224
 
225
+
195
226
  def TF_mag(G, s1):
196
227
  """Find the magnitude of transfer function G at point s1. G is
197
228
  expected to be a control.TransferFunction instance."""
@@ -203,28 +234,36 @@ def TF_mag(G, s1):
203
234
 
204
235
 
205
236
 
206
- def plot_settling_lines(fignum, p=2.0, plotstr='k--'):
237
+ def plot_settling_lines(p=2.0, plotstr='k--'):
207
238
  """Plot lines of +/-p% to help determine the settling time of a
208
239
  step response."""
209
- figure(fignum)
210
- myx = xlim()
240
+ #figure(fignum)
241
+ myx = plt.xlim()
211
242
  p2 = float(p)/100
212
243
  plot(myx, [1.0-p2,1.0-p2], plotstr, label=None)
213
244
  plot(myx, [1.0+p2,1.0+p2], plotstr, label=None)
214
-
215
245
 
216
- def draw_constant_zeta_lines(fignum, z, r=100):
217
- figure(fignum)
246
+
247
+ def plot_overshoot_line(p=10.0, plotstr='r--'):
248
+ """Plot a line for p % overshoot."""
249
+ #figure(fignum)
250
+ myx = plt.xlim()
251
+ p2 = float(p)/100
252
+ plot(myx, [1.0+p2,1.0+p2], plotstr, label=None)
253
+
254
+
255
+ def plot_constant_zeta_lines(z, r=100):
256
+ #figure(fignum)
218
257
  x = -sin(z)*r
219
258
  y = cos(z)*r
220
259
  plot([0,x],[0,y],'k--', label=None)
221
260
  plot([0,x],[0,-y],'k--', label=None)
222
261
 
223
262
 
224
- def plot_sigma_line(fignum, sig, plotstr='k-.'):
263
+ def plot_sigma_line(sig, plotstr='k-.'):
225
264
  """Plot lines of s=-sig on a root locus to help determine the
226
- settling time of a step response."""
227
- figure(fignum)
265
+ settling time of a step response. Note: sig=zeta*wn"""
266
+ #figure(fignum)
228
267
  myy = ylim()
229
268
  plot([-sig,-sig], myy, plotstr, label=None)
230
269
 
@@ -248,6 +287,7 @@ def draw_horiz_line(point, d1, d2, plotstr='k:'):
248
287
  y = imag(point)
249
288
  plot([x1,x2], [y,y], plotstr)
250
289
 
290
+
251
291
  def label_angle(point, label, dr, di):
252
292
  text(real(point) + dr, imag(point) + di, label, size=font_size)
253
293
 
@@ -265,14 +305,17 @@ def calc_angle(s1, point):
265
305
  def draw_point(point, marker, markersize=10):
266
306
  plot([real(point)],[imag(point)],marker,ms=markersize)
267
307
 
308
+
268
309
  def draw_zero(zero):
269
310
  """Call draw_point with marker set to 'ro'"""
270
311
  draw_point(zero, marker='ro')
271
312
 
313
+
272
314
  def draw_pole(pole):
273
315
  """Call draw_point with marker set to 'b^'"""
274
316
  draw_point(pole, marker='b^')
275
317
 
318
+
276
319
  def draw_angle_lines(s1, point, start_p=0.1, end_p=0.6, plotstr='k:'):
277
320
  draw_line_between_points(point, s1, plotstr=plotstr, \
278
321
  start_p=start_p, end_p=end_p)
@@ -286,6 +329,7 @@ def calc_angle_list(s1, point_list):
286
329
 
287
330
  return angle_list
288
331
 
332
+
289
333
  def calc_psi_and_phi_lists(s1, TF):
290
334
  zeros_a = TF.zero()#this returns an array
291
335
  zeros = zeros_a.tolist()
@@ -403,3 +447,115 @@ def create_freq_vect(timevect):
403
447
  f = df*nvect
404
448
  return f
405
449
 
450
+
451
+ def random_so_tf(p_unstable=0.1, p_real=0.1):
452
+ z = random.rand()*(1 + p_real)
453
+ # unstable sometimes:
454
+ if random.rand() < p_unstable:
455
+ z *= -1
456
+ wn = 10*pi*random.rand()
457
+ G = TF(wn**2, [1,2*z*wn,wn**2])
458
+ return G
459
+
460
+
461
+ def check_zeta_and_wn(G):
462
+ p = G.poles()
463
+ wn = np.abs(p[0])
464
+ z = -np.real(p[0])/wn
465
+ return z, wn
466
+
467
+
468
+
469
+
470
+ def get_specs(G):
471
+ z, wn = check_zeta_and_wn(G)
472
+ wd = wn*np.sqrt(1-z**2)
473
+ ts = 3.91/(z*wn)
474
+ Mp = np.exp(-z*np.pi/(np.sqrt(1-z**2)))
475
+ if z < 0:
476
+ # unstable
477
+ line1 = "zeta = %0.3g, unstable!" % z
478
+ if z < -1:
479
+ # unstable real pole
480
+ line2 = "unstable real pole"
481
+ line3 = "exponential growth without oscillations"
482
+ else:
483
+ # unstable underdamped pole
484
+ line2 = "unstable complex pole"
485
+ line3 = "growing oscillations"
486
+ else:
487
+ line1 = "zeta = %0.3g, overshoot = %0.4g" % (z, Mp)
488
+ line2 = "wd = %0.4g, wn = %0.4g" % (wd, wn)
489
+ line3 = "ts = %0.4g" % ts
490
+ return [line1, line2, line3]
491
+
492
+
493
+ def find_min_wn(G_list):
494
+ mymin = 10000
495
+ for G in G_list:
496
+ poles = G.poles()
497
+ wn = np.abs(poles[0])
498
+ if wn < mymin:
499
+ mymin = wn
500
+ return mymin
501
+
502
+
503
+
504
+ def plot_step_responses(G_list, t=None, start_ind=1, stop_t=None):
505
+ line_types = ['-','--','-.','--','-']
506
+ if t is None:
507
+ if stop_t is None:
508
+ wn = find_min_wn(G_list)
509
+ T = 2*np.pi/wn
510
+ stop_t = 3*T
511
+ t = np.arange(0,stop_t,0.001)
512
+ plt.figure()
513
+
514
+ for n, G in enumerate(G_list):
515
+ to, y_n = control.step_response(G, t)
516
+ j = n + start_ind
517
+ mylabel = "$G_{%i}$" % j
518
+ lt = line_types[n]
519
+ plt.plot(t, y_n, lt, label=mylabel)
520
+
521
+ plt.legend()
522
+ plt.xlabel("Time (sec.)")
523
+ plt.ylabel("Step Response")
524
+
525
+
526
+
527
+
528
+ def plot_pole_locations(G_list, start_ind=1):
529
+ mysymbols =['^','o','s','h','D','X']
530
+ plt.figure()
531
+
532
+ N = len(G_list)
533
+ n_vect = np.arange(N)
534
+
535
+ mymax = 0
536
+
537
+ for n, G, sym in zip(n_vect, G_list, mysymbols):
538
+ poles = G.poles()
539
+ j = n + start_ind
540
+ mylabel = "$G_{%i}$" % j
541
+ plt.plot(np.real(poles), np.imag(poles), sym, label=mylabel)
542
+ wn = np.abs(poles[0])
543
+ if wn > mymax:
544
+ mymax = wn
545
+
546
+ mymax *= 1.1
547
+ plt.legend()
548
+ plt.xlabel("Real")
549
+ plt.ylabel("Imag")
550
+ myx = [-mymax,mymax/3]
551
+ myy = [-mymax,mymax]
552
+ plt.xlim(myx)
553
+ plt.ylim(myy)
554
+ plt.plot(myx,[0,0],'k:', label=None)
555
+ plt.plot([0,0], myy,'k:', label=None)
556
+
557
+
558
+
559
+
560
+
561
+
@@ -1,13 +1,17 @@
1
- Metadata-Version: 1.1
2
- Name: control-utils
3
- Version: 1.0.4
4
- Summary: package for helping with teaching or learning feedback control
1
+ Metadata-Version: 2.4
2
+ Name: control_utils
3
+ Version: 1.2
4
+ Summary: package for helpful tasks in feedback controls
5
5
  Home-page: https://github.com/ryanGT/control_utils
6
6
  Author: Ryan Krauss
7
7
  Author-email: ryanwkrauss@gmail.com
8
- License: UNKNOWN
9
- Description: UNKNOWN
10
- Platform: UNKNOWN
11
8
  Classifier: Programming Language :: Python :: 3
12
9
  Classifier: License :: OSI Approved :: MIT License
13
10
  Classifier: Operating System :: OS Independent
11
+ Requires-Dist: control
12
+ Dynamic: author
13
+ Dynamic: author-email
14
+ Dynamic: classifier
15
+ Dynamic: home-page
16
+ Dynamic: requires-dist
17
+ Dynamic: summary
@@ -3,4 +3,5 @@ control_utils/__init__.py
3
3
  control_utils.egg-info/PKG-INFO
4
4
  control_utils.egg-info/SOURCES.txt
5
5
  control_utils.egg-info/dependency_links.txt
6
+ control_utils.egg-info/requires.txt
6
7
  control_utils.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ control
@@ -5,13 +5,14 @@ import setuptools
5
5
 
6
6
  setuptools.setup(
7
7
  name='control_utils', # This is the name of your PyPI-package.
8
- version='1.0.4',
8
+ version='1.2',
9
9
  url='https://github.com/ryanGT/control_utils',
10
10
  author='Ryan Krauss',
11
11
  author_email='ryanwkrauss@gmail.com',
12
- description="package for helping with teaching or learning feedback control",
12
+ description="package for helpful tasks in feedback controls",
13
13
  #long_description=long_description,
14
14
  #long_description_content_type="text/markdown",
15
+ install_requires="control",
15
16
  packages=setuptools.find_packages(),
16
17
  classifiers=[
17
18
  "Programming Language :: Python :: 3",
File without changes