Commit 26c1bb46 authored by Olivier Kaufmann's avatar Olivier Kaufmann
Browse files

Searches for run_measurement error

Showing with 19 additions and 9 deletions
+19 -9
...@@ -289,7 +289,7 @@ class TxAbstract(ABC): ...@@ -289,7 +289,7 @@ class TxAbstract(ABC):
pass pass
@abstractmethod @abstractmethod
def inject(self, polarity=1, injection_duration=None): def inject(self, polarity=1, injection_duration=None, switch_pwr=False):
""" """
Abstract method to define injection Abstract method to define injection
Parameters Parameters
...@@ -303,15 +303,20 @@ class TxAbstract(ABC): ...@@ -303,15 +303,20 @@ class TxAbstract(ABC):
if injection_duration is None: if injection_duration is None:
injection_duration = self._injection_duration injection_duration = self._injection_duration
if np.abs(polarity) > 0: if np.abs(polarity) > 0:
self.pwr.turn_on() if switch_pwr:
self.pwr.turn_on()
self.tx_sync.set() self.tx_sync.set()
time.sleep(injection_duration) time.sleep(injection_duration)
self.pwr.turn_off() self.tx_sync.clear()
if switch_pwr:
self.pwr.turn_off()
else: else:
self.tx_sync.set() self.tx_sync.set()
self.pwr.turn_off() if switch_pwr:
self.pwr.turn_off()
time.sleep(injection_duration) time.sleep(injection_duration)
self.tx_sync.clear() self.tx_sync.clear()
@property @property
def injection_duration(self): def injection_duration(self):
......
...@@ -10,6 +10,7 @@ import numpy as np ...@@ -10,6 +10,7 @@ import numpy as np
import os import os
from ohmpi.hardware_components import TxAbstract, RxAbstract from ohmpi.hardware_components import TxAbstract, RxAbstract
from ohmpi.utils import enforce_specs from ohmpi.utils import enforce_specs
import inspect
# hardware characteristics and limitations # hardware characteristics and limitations
# voltages are given in mV, currents in mA, sampling rates in Hz and data_rate in S/s # voltages are given in mV, currents in mA, sampling rates in Hz and data_rate in S/s
...@@ -36,6 +37,7 @@ SPECS = {'rx': {'sampling_rate': {'min': 2., 'default': 10., 'max': 100.}, ...@@ -36,6 +37,7 @@ SPECS = {'rx': {'sampling_rate': {'min': 2., 'default': 10., 'max': 100.},
# TODO: move low_battery spec in pwr # TODO: move low_battery spec in pwr
def _ads_1115_gain_auto(channel): # Make it a class method ? def _ads_1115_gain_auto(channel): # Make it a class method ?
"""Automatically sets the gain on a channel """Automatically sets the gain on a channel
...@@ -161,7 +163,10 @@ class Tx(TxAbstract): ...@@ -161,7 +163,10 @@ class Tx(TxAbstract):
def polarity(self, polarity): def polarity(self, polarity):
assert polarity in [-1, 0, 1] assert polarity in [-1, 0, 1]
self._polarity = polarity self._polarity = polarity
print(f'asserted polarity: {self.polarity}') # debugging code
curframe = inspect.currentframe()
calframe = inspect.getouterframes(curframe, 2)
print(f'polarity called from: {calframe}')
if polarity == 1: if polarity == 1:
print('pin0') print('pin0')
......
...@@ -33,6 +33,7 @@ SPECS = {'rx': {'sampling_rate': {'min': 2., 'default': 10., 'max': 100.}, ...@@ -33,6 +33,7 @@ SPECS = {'rx': {'sampling_rate': {'min': 2., 'default': 10., 'max': 100.},
# TODO: move low_battery spec in pwr # TODO: move low_battery spec in pwr
def _ads_1115_gain_auto(channel): # Make it a class method ? def _ads_1115_gain_auto(channel): # Make it a class method ?
"""Automatically sets the gain on a channel """Automatically sets the gain on a channel
...@@ -124,7 +125,6 @@ class Rx(Rx_mb_2023): ...@@ -124,7 +125,6 @@ class Rx(Rx_mb_2023):
self.pin_DG1.value = True # closed gain 1 active self.pin_DG1.value = True # closed gain 1 active
self.pin_DG2.value = False # open gain 0.5 inactive self.pin_DG2.value = False # open gain 0.5 inactive
def gain_auto(self): def gain_auto(self):
self._dg411_gain_auto() self._dg411_gain_auto()
......
...@@ -178,13 +178,13 @@ class OhmPiHardware: ...@@ -178,13 +178,13 @@ class OhmPiHardware:
rx_gains = [] rx_gains = []
for pol in polarities: for pol in polarities:
# self.tx.polarity = pol # self.tx.polarity = pol
# self.tx_sync.wait()
# 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})
# readings = Thread(target=self._read_values) # readings = Thread(target=self._read_values)
get_tx_gain = Thread(target=self.tx.gain_auto) get_tx_gain = Thread(target=self.tx.gain_auto)
get_rx_gain = Thread(target=self.rx.gain_auto) get_rx_gain = Thread(target=self.rx.gain_auto)
injection.start() injection.start()
self.tx_sync.wait()
get_tx_gain.start() # TODO: add a barrier to synchronize? get_tx_gain.start() # TODO: add a barrier to synchronize?
get_rx_gain.start() get_rx_gain.start()
get_tx_gain.join() get_tx_gain.join()
...@@ -404,7 +404,7 @@ class OhmPiHardware: ...@@ -404,7 +404,7 @@ class OhmPiHardware:
assert 0. <= duty_cycle <= 1. assert 0. <= duty_cycle <= 1.
if duty_cycle < 1.: if duty_cycle < 1.:
durations = [cycle_duration/2 * duty_cycle, cycle_duration/2*(1.-duty_cycle)] * 2 * cycles durations = [cycle_duration/2 * duty_cycle, cycle_duration/2*(1.-duty_cycle)] * 2 * cycles
pol = [-int(1. * np.heaviside(i % 2, -1.)) for i in range(2 * cycles)] pol = [-int(polarity * np.heaviside(i % 2, -1.)) for i in range(2 * cycles)]
# pol = [-int(self.tx.polarity * np.heaviside(i % 2, -1.)) for i in range(2 * cycles)] # pol = [-int(self.tx.polarity * np.heaviside(i % 2, -1.)) for i in range(2 * cycles)]
polarities = [0] * (len(pol) * 2) polarities = [0] * (len(pol) * 2)
polarities[0::2] = pol polarities[0::2] = pol
......
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