Commit 48a92c35 authored by Arnaud WATLET's avatar Arnaud WATLET
Browse files

updates injection strategies (vmin and vmax)

Showing with 97 additions and 54 deletions
+97 -54
...@@ -315,23 +315,31 @@ class OhmPi(object): ...@@ -315,23 +315,31 @@ class OhmPi(object):
# select a polarity to start with # select a polarity to start with
self.pin0.value = True self.pin0.value = True
self.pin1.value = False self.pin1.value = False
# implement different strategy
if strategy == 'vmax': if strategy == 'constant':
vab = volt
elif strategy == 'vmax':
# implement different strategy
I=0 I=0
vmn=0 vmn=0
count=0 count=0
while I < 3 or abs(vmn) < 20 : while I < 3 or abs(vmn) < 20 : #TODO: hardware related - place in config
if count >0 :
if count > 0 :
print('o', volt)
volt = volt + 2 volt = volt + 2
print('>', volt)
count=count+1 count=count+1
if volt > 50: if volt > 50:
break break
# set voltage for test # set voltage for test
if count==1:
self.DPS.write_register(0x09, 1) # DPS5005 on
time.sleep(best_tx_injtime) # inject for given tx time
self.DPS.write_register(0x0000, volt, 2) self.DPS.write_register(0x0000, volt, 2)
self.DPS.write_register(0x09, 1) # DPS5005 on
time.sleep(best_tx_injtime) # inject for given tx time
# autogain # autogain
self.ads_current = ads.ADS1115(self.i2c, gain=2 / 3, data_rate=860, address=self.ads_current_address) self.ads_current = ads.ADS1115(self.i2c, gain=2 / 3, data_rate=860, address=self.ads_current_address)
self.ads_voltage = ads.ADS1115(self.i2c, gain=2 / 3, data_rate=860, address=self.ads_voltage_address) self.ads_voltage = ads.ADS1115(self.i2c, gain=2 / 3, data_rate=860, address=self.ads_voltage_address)
...@@ -352,23 +360,26 @@ class OhmPi(object): ...@@ -352,23 +360,26 @@ class OhmPi(object):
if U0 < 0: # we guessed it wrong, let's use a correction factor if U0 < 0: # we guessed it wrong, let's use a correction factor
polarity = -1 polarity = -1
vmn = U2 vmn = U2
if strategy == 'vmax':
if abs(vmn)>4500 or I> 45 : #TODO: while loop? n = 0
volt = volt - 2 while (abs(vmn) > voltage_max or I > current_max) and volt>0: #If starting voltage is too high, need to lower it down
self.DPS.write_register(0x0000, volt, 2) # print('we are out of range! so decreasing volt')
self.DPS.write_register(0x09, 1) # DPS5005 on volt = volt - 2
time.sleep(best_tx_injtime) self.DPS.write_register(0x0000, volt, 2)
I = AnalogIn(self.ads_current, ads.P0).voltage * 1000. / 50 / self.r_shunt #self.DPS.write_register(0x09, 1) # DPS5005 on
U0 = AnalogIn(self.ads_voltage, ads.P0).voltage * 1000. #time.sleep(best_tx_injtime)
U2 = AnalogIn(self.ads_voltage, ads.P2).voltage * 1000. I = AnalogIn(self.ads_current, ads.P0).voltage * 1000. / 50 / self.r_shunt
U0 = AnalogIn(self.ads_voltage, ads.P0).voltage * 1000.
polarity = 1 # by default, we guessed it right U2 = AnalogIn(self.ads_voltage, ads.P2).voltage * 1000.
vmn = U0 polarity = 1 # by default, we guessed it right
if U0 < 0: # we guessed it wrong, let's use a correction factor vmn = U0
polarity = -1 if U0 < 0: # we guessed it wrong, let's use a correction factor
vmn = U2 polarity = -1
break vmn = U2
n+=1
if n > 25 :
break
factor_I = (current_max) / I factor_I = (current_max) / I
factor_vmn = voltage_max / vmn factor_vmn = voltage_max / vmn
factor = factor_I factor = factor_I
...@@ -377,37 +388,69 @@ class OhmPi(object): ...@@ -377,37 +388,69 @@ class OhmPi(object):
vab = factor * volt * 0.8 vab = factor * volt * 0.8
if vab > tx_max: if vab > tx_max:
vab = tx_max vab = tx_max
else: print(factor_I, factor_vmn, 'factor!!')
if strategy == 'constant':
vab = volt
else:
vab = 5
# set voltage for test
self.DPS.write_register(0x0000, volt, 2)
self.DPS.write_register(0x09, 1) # DPS5005 on
time.sleep(best_tx_injtime) # inject for given tx time
# autogain elif strategy == 'vmin':
self.ads_current = ads.ADS1115(self.i2c, gain=2 / 3, data_rate=860, address=self.ads_current_address) # implement different strategy
self.ads_voltage = ads.ADS1115(self.i2c, gain=2 / 3, data_rate=860, address=self.ads_voltage_address) I=20
gain_current = self._gain_auto(AnalogIn(self.ads_current, ads.P0)) vmn=400
gain_voltage0 = self._gain_auto(AnalogIn(self.ads_voltage, ads.P0)) count=0
gain_voltage2 = self._gain_auto(AnalogIn(self.ads_voltage, ads.P2)) while I > 10 or abs(vmn) > 300 : #TODO: hardware related - place in config
gain_voltage = np.min([gain_voltage0, gain_voltage2]) if count > 0 :
self.ads_current = ads.ADS1115(self.i2c, gain=gain_current, data_rate=860, address=self.ads_current_address) volt = volt - 2
self.ads_voltage = ads.ADS1115(self.i2c, gain=gain_voltage, data_rate=860, address=self.ads_voltage_address) print(volt, count)
# we measure the voltage on both A0 and A2 to guess the polarity count=count+1
I = AnalogIn(self.ads_current, ads.P0).voltage * 1000. / 50 / self.r_shunt # noqa measure current if volt > 50:
U0 = AnalogIn(self.ads_voltage, ads.P0).voltage * 1000. # noqa measure voltage break
U2 = AnalogIn(self.ads_voltage, ads.P2).voltage * 1000. # noqa
# set voltage for test
# check polarity if count==1:
polarity = 1 # by default, we guessed it right self.DPS.write_register(0x09, 1) # DPS5005 on
vmn = U0 time.sleep(best_tx_injtime) # inject for given tx time
if U0 < 0: # we guessed it wrong, let's use a correction factor self.DPS.write_register(0x0000, volt, 2)
polarity = -1 # autogain
vmn = U2 self.ads_current = ads.ADS1115(self.i2c, gain=2 / 3, data_rate=860, address=self.ads_current_address)
self.ads_voltage = ads.ADS1115(self.i2c, gain=2 / 3, data_rate=860, address=self.ads_voltage_address)
gain_current = self._gain_auto(AnalogIn(self.ads_current, ads.P0))
gain_voltage0 = self._gain_auto(AnalogIn(self.ads_voltage, ads.P0))
gain_voltage2 = self._gain_auto(AnalogIn(self.ads_voltage, ads.P2))
gain_voltage = np.min([gain_voltage0, gain_voltage2]) #TODO: separate gain for P0 and P2
self.ads_current = ads.ADS1115(self.i2c, gain=gain_current, data_rate=860, address=self.ads_current_address)
self.ads_voltage = ads.ADS1115(self.i2c, gain=gain_voltage, data_rate=860, address=self.ads_voltage_address)
# we measure the voltage on both A0 and A2 to guess the polarity
I = AnalogIn(self.ads_current, ads.P0).voltage * 1000. / 50 / self.r_shunt # noqa measure current
U0 = AnalogIn(self.ads_voltage, ads.P0).voltage * 1000. # noqa measure voltage
U2 = AnalogIn(self.ads_voltage, ads.P2).voltage * 1000. # noqa
# check polarity
polarity = 1 # by default, we guessed it right
vmn = U0
if U0 < 0: # we guessed it wrong, let's use a correction factor
polarity = -1
vmn = U2
n=0
while (abs(vmn) < voltage_min or I < current_min) and volt > 0 : #If starting voltage is too high, need to lower it down
# print('we are out of range! so increasing volt')
volt = volt + 2
print(volt)
self.DPS.write_register(0x0000, volt, 2)
#self.DPS.write_register(0x09, 1) # DPS5005 on
#time.sleep(best_tx_injtime)
I = AnalogIn(self.ads_current, ads.P0).voltage * 1000. / 50 / self.r_shunt
U0 = AnalogIn(self.ads_voltage, ads.P0).voltage * 1000.
U2 = AnalogIn(self.ads_voltage, ads.P2).voltage * 1000.
polarity = 1 # by default, we guessed it right
vmn = U0
if U0 < 0: # we guessed it wrong, let's use a correction factor
polarity = -1
vmn = U2
n+=1
if n > 25 :
break
vab = volt
self.DPS.write_register(0x09, 0) # DPS5005 off self.DPS.write_register(0x09, 0) # DPS5005 off
# print('polarity', polarity) # print('polarity', polarity)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment