Skip to content

Instantly share code, notes, and snippets.

@mmontagna
Created September 1, 2016 05:21
Show Gist options
  • Save mmontagna/c8213c013a054d756cf5d7b38792ffac to your computer and use it in GitHub Desktop.
Save mmontagna/c8213c013a054d756cf5d7b38792ffac to your computer and use it in GitHub Desktop.
Process control PI sketch
def scope():
pv = [0]
def actuate(x):
pv[0] += x
def read():
return pv[0]
return actuate, read
def scope_u():
i = [0]
kp = 0.01
ki = 0.02
def u(pv, sp):
e = sp - pv
print 'pv=', pv, 'sp=', sp, 'i(e)=', i[0]
i[0] += e
return kp * e + ki*i[0]
return u
def run():
import time
u = scope_u()
actuate, read = scope()
while True:
actuate(u(read(), 3.14))
time.sleep(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment