Commit a732c5a2 authored by Olivier Kaufmann's avatar Olivier Kaufmann
Browse files

Tests a way to solve I/O error on adc

Showing with 13 additions and 9 deletions
+13 -9
...@@ -36,6 +36,7 @@ class CtlAbstract(ABC): ...@@ -36,6 +36,7 @@ class CtlAbstract(ABC):
def _cpu_temp(self): def _cpu_temp(self):
pass pass
class PwrAbstract(ABC): class PwrAbstract(ABC):
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.board_name = kwargs.pop('board_name', 'unknown PWR hardware') self.board_name = kwargs.pop('board_name', 'unknown PWR hardware')
...@@ -88,6 +89,7 @@ class PwrAbstract(ABC): ...@@ -88,6 +89,7 @@ class PwrAbstract(ABC):
# add actions to set the DPS voltage # add actions to set the DPS voltage
self._voltage = value self._voltage = value
class MuxAbstract(ABC): class MuxAbstract(ABC):
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.board_name = kwargs.pop('board_name', 'unknown MUX hardware') self.board_name = kwargs.pop('board_name', 'unknown MUX hardware')
...@@ -129,7 +131,7 @@ class MuxAbstract(ABC): ...@@ -129,7 +131,7 @@ class MuxAbstract(ABC):
def reset(self): def reset(self):
pass pass
def switch(self, elec_dict=None, state='off'): # TODO: generalize for other roles def switch(self, elec_dict=None, state='off'): # TODO: generalize for other roles
"""Switch a given list of electrodes with different roles. """Switch a given list of electrodes with different roles.
Electrodes with a value of 0 will be ignored. Electrodes with a value of 0 will be ignored.
......
...@@ -243,7 +243,7 @@ class OhmPiHardware: ...@@ -243,7 +243,7 @@ class OhmPiHardware:
lengths = [cycle_length/2]*2*cycles lengths = [cycle_length/2]*2*cycles
self._vab_pulses(vab, lengths, sampling_rate, append=append) self._vab_pulses(vab, lengths, sampling_rate, append=append)
def _vab_pulse(self, vab, length, sampling_rate=None, polarity=1, append=False): def _vab_pulse(self, vab, length, sampling_rate=None, polarity=1, auto_gain = False, append=False):
""" Gets VMN and IAB from a single voltage pulse """ Gets VMN and IAB from a single voltage pulse
""" """
self.tx.polarity = polarity self.tx.polarity = polarity
...@@ -253,11 +253,12 @@ class OhmPiHardware: ...@@ -253,11 +253,12 @@ class OhmPiHardware:
self.tx.pwr.voltage = vab self.tx.pwr.voltage = vab
else: else:
vab = self.tx.pwr.voltage vab = self.tx.pwr.voltage
# set gains automatically if auto_gain:
gain_auto = Thread(target=self._gain_auto) # set gains automatically
injection = Thread(target=self._inject, kwargs={'inj_time': 0.2, 'polarity': polarity}) gain_auto = Thread(target=self._gain_auto)
gain_auto.start() injection = Thread(target=self._inject, kwargs={'inj_time': 0.2, 'polarity': polarity})
injection.start() gain_auto.start()
injection.start()
# reads current and voltage during the pulse # reads current and voltage during the pulse
injection = Thread(target=self._inject, kwargs={'inj_time':length, 'polarity': polarity}) injection = Thread(target=self._inject, kwargs={'inj_time':length, 'polarity': polarity})
readings = Thread(target=self._read_values, kwargs={'sampling_rate': sampling_rate, 'append': append}) readings = Thread(target=self._read_values, kwargs={'sampling_rate': sampling_rate, 'append': append})
...@@ -271,13 +272,14 @@ class OhmPiHardware: ...@@ -271,13 +272,14 @@ class OhmPiHardware:
if sampling_rate is None: if sampling_rate is None:
sampling_rate = RX_CONFIG['sampling_rate'] sampling_rate = RX_CONFIG['sampling_rate']
if polarities is not None: if polarities is not None:
assert len(polarities)==n_pulses assert len(polarities) == n_pulses
else: else:
polarities = [-self.tx.polarity * np.heaviside(i % 2, -1.) for i in range(n_pulses)] polarities = [-self.tx.polarity * np.heaviside(i % 2, -1.) for i in range(n_pulses)]
if not append: if not append:
self._clear_values() self._clear_values()
for i in range(n_pulses): for i in range(n_pulses):
self._vab_pulse(self, length=lengths[i], sampling_rate=sampling_rate, polarity=polarities[i], append=True) self._vab_pulse(self, length=lengths[i], sampling_rate=sampling_rate, polarity=polarities[i],
auto_gain=(i == 0), append=True)
def switch_mux(self, electrodes, roles=None, state='off'): def switch_mux(self, electrodes, roles=None, state='off'):
"""Switches on multiplexer relays for given quadrupole. """Switches on multiplexer relays for given quadrupole.
......
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