Commit 4b11c4a1 authored by Olivier Kaufmann's avatar Olivier Kaufmann
Browse files

Attemps to use the sampling_rate in _vab_pulse

Showing with 19 additions and 19 deletions
+19 -19
...@@ -50,34 +50,35 @@ class OhmPiHardware: ...@@ -50,34 +50,35 @@ class OhmPiHardware:
soh_logger=self.soh_logger)) soh_logger=self.soh_logger))
def _vab_pulse(self, vab, length, sampling_rate=None, polarity=None): def _inject(self, duration):
""" Gets VMN and IAB from a single voltage pulse
"""
def inject(self, duration):
self.tx_sync.set() self.tx_sync.set()
self.tx.voltage_pulse(length=duration) self.tx.voltage_pulse(length=duration)
self.tx_sync.clear() self.tx_sync.clear()
def read_values(self, data, sampling_rate): # noqa def _read_values(self, sampling_rate): # noqa
_readings = [] _readings = []
self.tx_sync.wait() self.tx_sync.wait()
start_time = datetime.datetime.utcnow() start_time = datetime.datetime.utcnow()
while self.tx_sync.is_set(): while self.tx_sync.is_set():
lap = datetime.datetime.utcnow() lap = datetime.datetime.utcnow()
_readings.append([elapsed_seconds(start_time), self.tx.current, self.rx.voltage]) _readings.append([elapsed_seconds(start_time), self.tx.current, self.rx.voltage])
sleep_time = sampling_rate/1000.-elapsed_seconds(lap) sleep_time = sampling_rate / 1000. - elapsed_seconds(lap)
print(f'sleep_time: {sleep_time}') print(f'sleep_time: {sleep_time}')
time.sleep(np.min([sleep_time, np.abs(sleep_time)])) time.sleep(np.min([sleep_time, np.abs(sleep_time)]))
data = np.array(_readings) self.readings = np.array(_readings)
def _vab_pulse(self, vab, length, sampling_rate=None, polarity=None):
""" Gets VMN and IAB from a single voltage pulse
"""
if sampling_rate is None: if sampling_rate is None:
sampling_rate = RX_CONFIG['sampling_rate'] sampling_rate = RX_CONFIG['sampling_rate']
if polarity is not None and polarity != self.tx.polarity: if polarity is not None and polarity != self.tx.polarity:
self.tx.polarity = polarity self.tx.polarity = polarity
self.tx.voltage = vab self.tx.voltage = vab
data = None injection = Thread(target=self._inject, kwargs={'duration':length})
injection = Thread(target=inject, args=[self], kwargs={'duration':length}) readings = Thread(target=self._read_values, kwargs={'sampling_rate': sampling_rate})
readings = Thread(target=read_values, args=[self, data], kwargs={'sampling_rate': sampling_rate})
# set gains automatically # set gains automatically
self.tx.adc_gain_auto() self.tx.adc_gain_auto()
self.rx.adc_gain_auto() self.rx.adc_gain_auto()
...@@ -85,7 +86,6 @@ class OhmPiHardware: ...@@ -85,7 +86,6 @@ class OhmPiHardware:
injection.start() injection.start()
readings.join() readings.join()
injection.join() injection.join()
print(data)
iab = self.tx.current # measure current iab = self.tx.current # measure current
vmn = self.rx.voltage vmn = self.rx.voltage
return iab, vmn return iab, vmn
......
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