Skip to content

Instantly share code, notes, and snippets.

@SoutrikBandyopadhyay
Last active November 24, 2020 06:01
Show Gist options
  • Save SoutrikBandyopadhyay/648441c174d60b269c1b0cf42611bff7 to your computer and use it in GitHub Desktop.
Save SoutrikBandyopadhyay/648441c174d60b269c1b0cf42611bff7 to your computer and use it in GitHub Desktop.
class PIController:
def __init__(self):
#Maintain a History of Variables
self.yHist = []
self.tHist = []
self.uHist = []
self.eSum = 0
def initialize(self):
#Initialize the graph
self.fig, = plt.plot(self.tHist,self.yHist)
plt.xlim(0,10)
plt.ylim(0,20)
plt.ylabel("Plant Output")
plt.xlabel("Time(s)")
plt.title("Plant Response")
def updateGraph(self):
# Update the Graph
self.fig.set_xdata(self.tHist)
self.fig.set_ydata(self.yHist)
plt.pause(0.1)
plt.show()
def getControlEffort(self,yHist,tHist):
# Returns control action based on past outputs
self.yHist = yHist
self.tHist = tHist
self.updateGraph()
if(type(self.yHist) == float):
y = self.yHist
else:
y = self.yHist[-1][0]
# Set Point is 10
e = 10-y
self.eSum += e
u = 1*e + 0.001*self.eSum
print(y)
self.uHist.append(u)
return u
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment