Commit 8c960b1b authored by Olivier Kaufmann's avatar Olivier Kaufmann
Browse files

Sets sampling rate for _compute_tx_volt

No related merge requests found
Showing with 20 additions and 4 deletions
+20 -4
......@@ -150,6 +150,7 @@ class RxAbstract(ABC):
self.exec_logger = create_stdout_logger('exec_tx')
self.soh_logger = kwargs.pop('soh_logger', None)
self.board_name = kwargs.pop('board_name', 'unknown RX hardware')
self._sampling_rate = kwargs.pop('sampling_rate', 1)
self.exec_logger.debug(f'{self.board_name} RX initialization')
self._adc_gain = 1.
......@@ -167,6 +168,16 @@ class RxAbstract(ABC):
def adc_gain_auto(self):
pass
@property
def sampling_rate(self):
return self._sampling_rate
@sampling_rate.setter
def sampling_rate(self, value):
assert value > 0.
self._sampling_rate = value
self.exec_logger.debug(f'Sampling rate set to {value}')
@property
@abstractmethod
def voltage(self):
......
......@@ -214,6 +214,7 @@ class Rx(RxAbstract):
self._ads_voltage_address = 0x49
self._adc_gain = 2/3
self._ads_voltage = ads.ADS1115(self.controller.bus, gain=self._adc_gain, data_rate=860, address=self._ads_voltage_address)
self._sampling_rate = kwargs.pop('sampling_rate', sampling_rate)
@property
def adc_gain(self):
......
......@@ -48,6 +48,7 @@ class OhmPiHardware:
self.mux = kwargs.pop('mux', mux_module.Mux(exec_logger=self.exec_logger,
data_logger=self.data_logger,
soh_logger=self.soh_logger))
self.readings=np.array([])
def _inject(self, duration):
self.tx_sync.set()
......@@ -86,9 +87,6 @@ class OhmPiHardware:
injection.start()
readings.join()
injection.join()
iab = self.tx.current # measure current
vmn = self.rx.voltage
return iab, vmn
def _compute_tx_volt(self, best_tx_injtime=0.1, strategy='vmax', tx_volt=5,
vab_max=voltage_max, vmn_min=voltage_min):
......@@ -136,7 +134,13 @@ class OhmPiHardware:
vab = np.min([np.abs(tx_volt), vab_max])
self.tx.polarity = 1
self.tx.turn_on()
vmn, iab = self._vab_pulse(vab=vab, length=best_tx_injtime)
if self.rx.sampling_rate*1000 > best_tx_injtime:
sampling_rate = best_tx_injtime
else:
sampling_rate = self.tx.sampling_rate
self._vab_pulse(vab=vab, length=best_tx_injtime, sampling_rate=sampling_rate)
vmn = np.mean(self.readings[:,2])
iab = np.mean(self.readings[:,1])
# if np.abs(vmn) is too small (smaller than voltage_min), strategy is not constant and vab < vab_max ,
# then we could call _compute_tx_volt with a tx_volt increased to np.min([vab_max, tx_volt*2.]) for example
if strategy == 'vmax':
......
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