Skip to content

Commit

Permalink
Reduce Noise
Browse files Browse the repository at this point in the history
  • Loading branch information
Destination2Unknown committed Jul 13, 2022
1 parent f3f6433 commit 9f84e8d
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions PythonPID_Simulator.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ def refresh():
ikp,iki,ikd = float(tKp.get()),float(tKi.get()),float(tKd.get())

#Find the size of the range needed
if (ideadtime+itau)*4 < minsize:
if (ideadtime+itau)*6 < minsize:
rangesize = minsize
elif (ideadtime+itau)*4 >maxsize:
elif (ideadtime+itau)*6 >maxsize:
rangesize = maxsize
else:
rangesize = int((ideadtime+itau)*4)
rangesize = int((ideadtime+itau)*6)

#setup time intervals
t = np.arange(start=0, stop=rangesize, step=1)
Expand Down Expand Up @@ -180,7 +180,7 @@ def refresh():
for i in t:
if i<len(t)-1:
if i < startofstep:
SP[i] = 0
SP[i] = ibias
elif i< rangesize*0.6:
SP[i]= 60 + ibias
else:
Expand Down Expand Up @@ -227,11 +227,11 @@ def refresh():
plt.show()

if __name__ == "__main__":
#Random Noise between -0.5 and 0.5, same set used for each run. Created once at runtime.
#Random Noise between -0.1 and 0.1, same set used for each run. Created once at runtime.
minsize=600
maxsize=7200
noise= np.random.rand(minsize)
noise-=0.5
noise= np.random.rand(minsize)/5
noise-=0.1

#Gui
root = tk.Tk()
Expand All @@ -254,32 +254,35 @@ if __name__ == "__main__":
tk.Label(root, text="Ki").grid(row=2,column=3)
tk.Label(root, text="Kd").grid(row=3,column=3)

#Entry Boxes
tK = tk.Entry(root,width=8)
ttau = tk.Entry(root,width=8)
tdt= tk.Entry(root,width=8)
tKp = tk.Entry(root,width=8)
tKi = tk.Entry(root,width=8)
tKd= tk.Entry(root,width=8)


#Defaults
tK.insert(10, "2.25")
ttau.insert(10, "60.5")
tdt.insert(10, "9.99")
tKp.insert(10, "1.1")
tKi.insert(10, "0.1")
tKd.insert(10, "0.09")


#Placement
tK.grid(row=1, column=1)
ttau.grid(row=2, column=1)
tdt.grid(row=3, column=1)
tKp.grid(row=1, column=4)
tKi.grid(row=2, column=4)
tKd.grid(row=3, column=4)

#Buttons
button_calc = tk.Button(root, text="Refresh", command=refresh)
tk.Label(root, text="itae:").grid(row=5,column=3)
itae_text = tk.StringVar()
tk.Label(root, textvariable=itae_text).grid(row=5,column=4)

button_calc.grid(row=5,column=0)

root.mainloop()

0 comments on commit 9f84e8d

Please sign in to comment.