Commit 6ed95c9d authored by Olivier Kaufmann's avatar Olivier Kaufmann
Browse files

Fixes bug in _compute_tx_volt

Showing with 7 additions and 10 deletions
+7 -10
...@@ -457,7 +457,9 @@ class OhmPiHardware: ...@@ -457,7 +457,9 @@ class OhmPiHardware:
vab_max = np.abs(vab_max) vab_max = np.abs(vab_max)
vmn_min = np.abs(vmn_min) vmn_min = np.abs(vmn_min)
vab = np.min([np.abs(tx_volt), vab_max]) k = 0
vab = np.zeros(n_steps + 1) * np.nan
vab[k] = np.min([np.abs(tx_volt), vab_max])
# self.tx.turn_on() # self.tx.turn_on()
switch_pwr_off, switch_tx_pwr_off = False, False # TODO: check if these should be moved in kwargs switch_pwr_off, switch_tx_pwr_off = False, False # TODO: check if these should be moved in kwargs
if self.tx.pwr_state == 'off': if self.tx.pwr_state == 'off':
...@@ -476,13 +478,10 @@ class OhmPiHardware: ...@@ -476,13 +478,10 @@ class OhmPiHardware:
if self.tx.pwr.pwr_state == 'off': if self.tx.pwr.pwr_state == 'off':
self.tx.pwr.pwr_state = 'on' self.tx.pwr.pwr_state = 'on'
switch_pwr_off = True switch_pwr_off = True
k = 0
diff_vab = np.inf diff_vab = np.inf
while (k < n_steps) and (diff_vab > diff_vab_lim): while (k < n_steps) and (diff_vab > diff_vab_lim):
vabs = [] vabs = []
for pol in polarities: for pol in polarities:
vab = np.zeros(n_steps + 1) * np.nan
# self.tx.polarity = pol # self.tx.polarity = pol
# set gains automatically # set gains automatically
injection = Thread(target=self._inject, kwargs={'injection_duration': 0.2, 'polarity': pol}) injection = Thread(target=self._inject, kwargs={'injection_duration': 0.2, 'polarity': pol})
...@@ -494,7 +493,6 @@ class OhmPiHardware: ...@@ -494,7 +493,6 @@ class OhmPiHardware:
injection.join() injection.join()
v = np.where((self.readings[:, 0] > delay) & (self.readings[:, 2] != 0))[0] # NOTE : discard data aquired in the first x ms v = np.where((self.readings[:, 0] > delay) & (self.readings[:, 2] != 0))[0] # NOTE : discard data aquired in the first x ms
iab = self.readings[v, 3] iab = self.readings[v, 3]
vmn = self.readings[v, 4] * self.readings[v, 2] vmn = self.readings[v, 4] * self.readings[v, 2]
iab_mean = np.mean(iab) iab_mean = np.mean(iab)
iab_std = np.std(iab) iab_std = np.std(iab)
...@@ -532,16 +530,15 @@ class OhmPiHardware: ...@@ -532,16 +530,15 @@ class OhmPiHardware:
print('Vab bounded by Vmn max') print('Vab bounded by Vmn max')
else: else:
print('Next step') print('Next step')
vab[k + 1] = new_vab
k = k + 1
vabs.append(new_vab) vabs.append(new_vab)
if diff_vab < diff_vab_lim: if diff_vab < diff_vab_lim:
print('stopped on vab increase too small') print('stopped on vab increase too small')
else: else:
print('stopped on maximum number of steps reached') print('stopped on maximum number of steps reached')
print(f'Selected Vab: {vab:.2f}') k = k + 1
vab_opt = np.min(vabs) vab[k] = np.min(vabs)
print(f'Selected Vab: {vab_opt:.2f}') vab_opt = vab[k-1]
print(f'Selected Vab: {vab_opt:.2f}')
# if strategy == 'vmax': # if strategy == 'vmax':
# # implement different strategies # # implement different strategies
......
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