Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Added support for Negative Step in CV
Browse files Browse the repository at this point in the history
  • Loading branch information
Destination2Unknown committed Aug 30, 2022
1 parent b58036d commit ebe7acb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pytunelogix/_exampleCSVs/prc.csv
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ PV;CV;SP
15.9;0;25
15.9;0;25
15.9;0;25
15.9;10;25
15.9;0;25
15.9;0;25
15.9;0;25
15.9;0;25
Expand Down
33 changes: 26 additions & 7 deletions pytunelogix/stage1/csvtuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,21 @@ def step2(filename):

#Direction
if df['PV'].iloc[1] > df['PV'].iloc[-1]:
direction="Reverse"
if df['CV'].idxmin()< df['CV'].idxmax():
direction="Reverse"
else:
direction="Direct"
else:
direction="Direct"
if df['CV'].idxmin()< df['CV'].idxmax():
direction="Direct"
else:
direction="Reverse"

#Find basic parameters
i_start=df['CV'].idxmax()
if df['CV'].idxmin()< df['CV'].idxmax():
i_start=df['CV'].idxmax()
else:
i_start=df['CV'].idxmin()
ambient.set(round(df['PV'].iloc[:i_start+onesecwindow].mean(axis = 0),2))
StartPV=df['PV'].iloc[i_start]
InitCV=df['CV'].iloc[0]
Expand All @@ -100,7 +109,7 @@ def step2(filename):
RangeL=round(float(ambient.get()),2)*lololimit

#Find DeadTime
if direction=="Reverse":
if (direction=="Reverse" and df['CV'].idxmin()< df['CV'].idxmax()) or (direction=="Direct" and df['CV'].idxmin()> df['CV'].idxmax()):
for x in range(i_start,(len(df['PV'])-window)):
if(df['PV'].iloc[x:x+twosecwindow:1].mean(axis = 0)<RangeL):
modeldt.set(round((x-i_start)*deltaT,2))
Expand All @@ -112,7 +121,7 @@ def step2(filename):
break

#Find Gain
if direction=="Reverse":
if (direction=="Reverse" and df['CV'].idxmin()< df['CV'].idxmax()) or (direction=="Direct" and df['CV'].idxmin()> df['CV'].idxmax()):
j=df['PV'].idxmin()
min_peak=df['PV'].min()
else:
Expand All @@ -128,7 +137,7 @@ def step2(filename):
tc_low=tc_value*0.99

#Find Time Constant
if direction=="Reverse":
if (direction=="Reverse" and df['CV'].idxmin()< df['CV'].idxmax()) or (direction=="Direct" and df['CV'].idxmin()> df['CV'].idxmax()):
z=df[df['PV']<=StartPV-(peak*0.1)].first_valid_index()
for x in range(z,(len(df['PV'])-window)):
if(df['PV'].iloc[x-twosecwindow:x+twosecwindow:1].mean(axis = 0)<tc_low):
Expand Down Expand Up @@ -188,7 +197,13 @@ def step3(filename):

#Find Step Size
CVStep=df['CV'].max()-df['CV'].min()
indexofstart=int(df['CV'].idxmax()) #start of step

#start of step
if df['CV'].idxmin()< df['CV'].idxmax():
indexofstart=df['CV'].idxmax()
else:
indexofstart=df['CV'].idxmin()

ambient.set(round(df['PV'].iloc[:indexofstart].mean(axis = 0),2))

#produces a model based on the parameters
Expand Down Expand Up @@ -227,6 +242,10 @@ def err(Xe,te,ye):

#Get data to plot new model
ymodel=CVStep*fopdt_func(t,float(modelgain.get()),float(modeltc.get()), float(modeldt.get()))+float(ambient.get())

#Invert sign on Negative Step
if df['CV'].idxmin()> df['CV'].idxmax():
modelgain.set(round(-Gain,2))

#Plot
plt.figure()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='pytunelogix',
version='1.1.18',
version='1.1.19',
license='MIT',
author="Destination2Unknown",
author_email='[email protected]',
Expand Down

0 comments on commit ebe7acb

Please sign in to comment.