From 34627e51dca98f4236fc2575cb63ca6a95b27e30 Mon Sep 17 00:00:00 2001 From: su530201 <olivier.kaufmann@umons.ac.be> Date: Wed, 14 Jun 2023 11:42:53 +0200 Subject: [PATCH] Investigates reading times --- ohmpi/hardware_components/abstract_hardware_components.py | 8 ++++++++ ohmpi/hardware_components/dummy_mux.py | 3 ++- ohmpi/hardware_components/mb_2024_rev_0_0.py | 2 +- ohmpi/hardware_components/pwr_batt.py | 3 ++- ohmpi/hardware_system.py | 5 +++-- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ohmpi/hardware_components/abstract_hardware_components.py b/ohmpi/hardware_components/abstract_hardware_components.py index c670948c..c6cd8b27 100644 --- a/ohmpi/hardware_components/abstract_hardware_components.py +++ b/ohmpi/hardware_components/abstract_hardware_components.py @@ -51,6 +51,10 @@ class PwrAbstract(ABC): self._current_adjustable = kwargs.pop('current_adjustable', False) self._current = np.nan self._state = 'off' + self._current_min = kwargs.pop('current_min', 0.) + self._current_max = kwargs.pop('current_max', 0.) + self._current_min = kwargs.pop('voltage_min', 0.) + self._voltage_max = kwargs.pop('voltage_max', 0.) @property @abstractmethod @@ -63,6 +67,7 @@ class PwrAbstract(ABC): def current(self, value, **kwargs): # add actions to set the DPS current pass + @abstractmethod def turn_off(self): self.exec_logger.debug(f'Switching {self.board_name} off') @@ -86,6 +91,7 @@ class PwrAbstract(ABC): if not self.voltage_adjustable: self.exec_logger.warning(f'Voltage cannot be set on {self.board_name}...') else: + assert self._voltage_min < value < self._voltage_max # add actions to set the DPS voltage self._voltage = value @@ -211,6 +217,7 @@ class MuxAbstract(ABC): time.sleep(activation_time) self.exec_logger.debug('Test finished.') + class TxAbstract(ABC): def __init__(self, **kwargs): self.board_name = kwargs.pop('board_name', 'unknown TX hardware') @@ -266,6 +273,7 @@ class TxAbstract(ABC): @inj_time.setter def inj_time(self, value): assert isinstance(value, float) + assert value > 0. self._inj_time = value @property diff --git a/ohmpi/hardware_components/dummy_mux.py b/ohmpi/hardware_components/dummy_mux.py index 6b94dfc0..21468e2d 100644 --- a/ohmpi/hardware_components/dummy_mux.py +++ b/ohmpi/hardware_components/dummy_mux.py @@ -1,8 +1,9 @@ -from ohmpi.ohmpi.config import HARDWARE_CONFIG +from ohmpi.config import HARDWARE_CONFIG import os from ohmpi.hardware_components import MuxAbstract MUX_CONFIG = HARDWARE_CONFIG['mux'].pop('default', {}) + class Mux(MuxAbstract): def __init__(self, **kwargs): kwargs.update({'board_name': os.path.basename(__file__).rstrip('.py')}) diff --git a/ohmpi/hardware_components/mb_2024_rev_0_0.py b/ohmpi/hardware_components/mb_2024_rev_0_0.py index 4c1d7ca4..b9fcbdca 100644 --- a/ohmpi/hardware_components/mb_2024_rev_0_0.py +++ b/ohmpi/hardware_components/mb_2024_rev_0_0.py @@ -1,5 +1,5 @@ import importlib -from ohmpi.ohmpi.config import HARDWARE_CONFIG +from ohmpi.config import HARDWARE_CONFIG import adafruit_ads1x15.ads1115 as ads # noqa from adafruit_ads1x15.analog_in import AnalogIn # noqa from adafruit_mcp230xx.mcp23008 import MCP23008 # noqa diff --git a/ohmpi/hardware_components/pwr_batt.py b/ohmpi/hardware_components/pwr_batt.py index 36abf769..dd811385 100644 --- a/ohmpi/hardware_components/pwr_batt.py +++ b/ohmpi/hardware_components/pwr_batt.py @@ -2,6 +2,7 @@ from ohmpi.hardware_components.abstract_hardware_components import PwrAbstract import numpy as np import os + class Pwr(PwrAbstract): def __init__(self, **kwargs): kwargs.update({'board_name': os.path.basename(__file__).rstrip('.py')}) @@ -11,7 +12,7 @@ class Pwr(PwrAbstract): self._voltage = voltage self._current_adjustable = False self._current = np.nan - + self._state = 'on' @property def current(self): diff --git a/ohmpi/hardware_system.py b/ohmpi/hardware_system.py index 5c3d1add..30631dbf 100644 --- a/ohmpi/hardware_system.py +++ b/ohmpi/hardware_system.py @@ -162,7 +162,7 @@ class OhmPiHardware: else: _readings = self.readings.tolist() sample = 0 - self.tx_sync.wait() + self.tx_sync.wait() # if not append or self._start_time is None: self._start_time = datetime.datetime.utcnow() while self.tx_sync.is_set(): @@ -171,7 +171,8 @@ class OhmPiHardware: self.rx.voltage]) sample += 1 sleep_time = self._start_time + datetime.timedelta(seconds=sample * sampling_rate / 1000) - lap - time.sleep(np.max([0.001, sleep_time.total_seconds()])) + time.sleep(np.max([0., sleep_time.total_seconds()])) # TODO set readings to nan if sleep time <0 and skip the sample (sample +=1) + self.exec_logger.warning(f'pulse {self._pulse}: elapsed time {(lap-self._start_time).total_seconds()} s') # TODO: Set to debug level self.readings = np.array(_readings) self._pulse += 1 -- GitLab