Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate output from feedback examples #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions ch01.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def target( t ):
u = target(t)
y = p.work( u )

print t, u, 0, u, y
print (t, u, 0, u, y)

def closed_loop( c, p, tm=5000 ):
def setpoint( t ):
Expand All @@ -62,7 +62,8 @@ def setpoint( t ):
u = c.work(e)
y = p.work(u)

print t, r, e, u, y
print (t, r, e, u, y)


# ============================================================

Expand All @@ -71,7 +72,3 @@ def setpoint( t ):

# open_loop( p, 1000 )
closed_loop( c, p, 1000 )




10 changes: 6 additions & 4 deletions ch02.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import math

r = 0.6
k = float( sys.argv[1] ) # 50..175
k = 50 # float( sys.argv[1] ) # 50..175

print "r=%f\tk=%f\n" % ( r, k ); t=0
print r, 0, 0, 0, 0
print ( "r=%f\tk=%f\n" % ( r, k ))
t=0

print ( r, 0, 0, 0, 0)

def cache( size ):
if size < 0:
Expand All @@ -24,4 +26,4 @@ def cache( size ):
u = k*c # control action
y = cache(u) # process output

print r, e, c, u, y
print ( r, e, c, u, y)
6 changes: 3 additions & 3 deletions ch03.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

import sys

r = float(sys.argv[1]) # Reference or "setpoint"
k = float(sys.argv[2]) # Controller gain
r = 10 # float(sys.argv[1]) # Reference or "setpoint"
k = .10 # float(sys.argv[2]) # Controller gain

u = 0 # "Previous" output
for _ in range( 200 ):
Expand All @@ -11,4 +11,4 @@
e = r - y # Tracking error
u = k*e # Controller ouput

print r, e, 0, u, y
print (r, e, 0, u, y)
18 changes: 9 additions & 9 deletions ch14-adserving.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def specialsteptest():
y = p.work( u )
z = f.work( y )

print t, t*fb.DT, r, 0, u, u, y, z, p.monitoring()
print( t, t*fb.DT, r, 0, u, u, y, z, p.monitoring())

quit()

Expand All @@ -103,12 +103,12 @@ def specialsteptest():

fb.DT = 1

# statictest()
#statictest()

# closedloop( 0.5, 0.25 ) # default
# closedloop( 0.0, 0.25 ) # w/o prop ctrl
# closedloop( 0.0, 1.75 ) # ringing
# closedloop( 1.0, 0.125, fb.RecursiveFilter(0.125) ) #
# closedloop_accumul( 0.5, 0.125 )
closedloop( 0.5, 0.25 ) # default
closedloop( 0.0, 0.25 ) # w/o prop ctrl
closedloop( 0.0, 1.75 ) # ringing

closedloop( 1.0, 0.125, fb.RecursiveFilter(0.125) ) #

closedloop_accumul( 0.5, 0.125 )
19 changes: 19 additions & 0 deletions data/generate-data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Generate data from example code and store in files for analysis.

* Select all local files and filter to chapter code
* Run each file sequentially
* Store the output in a file named after the script that generated it with a 'data' suffix
"""

import os
import fnmatch

DIR = 'data/'
SUFFIX = '.data'

scripts = [file for file in os.listdir() if fnmatch.fnmatch(file, 'ch*.py')]

for script in scripts:
print('Running: ' + script)
os.system('python {} > {}'.format(script, DIR + script.replace('.py', SUFFIX)))
8 changes: 4 additions & 4 deletions feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def static_test( plant_ctor, ctor_args, umax, steps, repeats, tmax ):
for t in range( tmax ):
y = p.work(u)

print u, y
print (u, y)

quit()

Expand All @@ -268,7 +268,7 @@ def step_response( setpoint, plant, tm=5000 ):
u = r
y = plant.work( u )

print t, t*DT, r, 0, u, u, y, y, plant.monitoring()
print (t, t*DT, r, 0, u, u, y, y, plant.monitoring())

quit()

Expand All @@ -278,7 +278,7 @@ def open_loop( setpoint, controller, plant, tm=5000 ):
u = controller.work( r )
y = plant.work( u )

print t, t*DT, r, 0, u, u, y, y, plant.monitoring()
print (t, t*DT, r, 0, u, u, y, y, plant.monitoring())

quit()

Expand All @@ -294,7 +294,7 @@ def closed_loop( setpoint, controller, plant, tm=5000, inverted=False,
y = plant.work(v)
z = returnfilter.work(y)

print t, t*DT, r, e, u, v, y, z, plant.monitoring()
print (t, t*DT, r, e, u, v, y, z, plant.monitoring())

quit()

Expand Down