control-utils 1.0.5__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.5
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.5'
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,7 +204,7 @@ 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)
194
209
 
195
210
 
@@ -272,6 +287,7 @@ def draw_horiz_line(point, d1, d2, plotstr='k:'):
272
287
  y = imag(point)
273
288
  plot([x1,x2], [y,y], plotstr)
274
289
 
290
+
275
291
  def label_angle(point, label, dr, di):
276
292
  text(real(point) + dr, imag(point) + di, label, size=font_size)
277
293
 
@@ -289,14 +305,17 @@ def calc_angle(s1, point):
289
305
  def draw_point(point, marker, markersize=10):
290
306
  plot([real(point)],[imag(point)],marker,ms=markersize)
291
307
 
308
+
292
309
  def draw_zero(zero):
293
310
  """Call draw_point with marker set to 'ro'"""
294
311
  draw_point(zero, marker='ro')
295
312
 
313
+
296
314
  def draw_pole(pole):
297
315
  """Call draw_point with marker set to 'b^'"""
298
316
  draw_point(pole, marker='b^')
299
317
 
318
+
300
319
  def draw_angle_lines(s1, point, start_p=0.1, end_p=0.6, plotstr='k:'):
301
320
  draw_line_between_points(point, s1, plotstr=plotstr, \
302
321
  start_p=start_p, end_p=end_p)
@@ -310,6 +329,7 @@ def calc_angle_list(s1, point_list):
310
329
 
311
330
  return angle_list
312
331
 
332
+
313
333
  def calc_psi_and_phi_lists(s1, TF):
314
334
  zeros_a = TF.zero()#this returns an array
315
335
  zeros = zeros_a.tolist()
@@ -427,3 +447,115 @@ def create_freq_vect(timevect):
427
447
  f = df*nvect
428
448
  return f
429
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.5
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.5',
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