Commit cddafa65 authored by Arnaud WATLET's avatar Arnaud WATLET
Browse files

Updates dps logic

Showing with 39 additions and 15 deletions
+39 -15
...@@ -56,6 +56,7 @@ class PwrAbstract(ABC): ...@@ -56,6 +56,7 @@ class PwrAbstract(ABC):
self._voltage_min = kwargs.pop('voltage_min', 0.) self._voltage_min = kwargs.pop('voltage_min', 0.)
self._voltage_max = kwargs.pop('voltage_max', 0.) self._voltage_max = kwargs.pop('voltage_max', 0.)
self.connection = kwargs.pop('connection', None) self.connection = kwargs.pop('connection', None)
self._battery_voltage = np.nan
@property @property
@abstractmethod @abstractmethod
...@@ -92,10 +93,20 @@ class PwrAbstract(ABC): ...@@ -92,10 +93,20 @@ class PwrAbstract(ABC):
if not self.voltage_adjustable: if not self.voltage_adjustable:
self.exec_logger.debug(f'Voltage cannot be set on {self.model}...') self.exec_logger.debug(f'Voltage cannot be set on {self.model}...')
else: else:
assert self._voltage_min < value < self._voltage_max assert self._voltage_min <= value <= self._voltage_max
# add actions to set the DPS voltage # add actions to set the DPS voltage
self._voltage = value self._voltage = value
def battery_voltage(self):
# add actions to read the DPS voltage
self.exec_logger.debug(f'Battery voltage cannot be read on {self.model}...')
return self._battery_voltage
def reset_voltage(self):
if not self.voltage_adjustable:
self.exec_logger.debug(f'Voltage cannot be set on {self.model}...')
else:
self.voltage = self._voltage_min
class MuxAbstract(ABC): class MuxAbstract(ABC):
def __init__(self, **kwargs): def __init__(self, **kwargs):
......
...@@ -7,6 +7,7 @@ from digitalio import Direction # noqa ...@@ -7,6 +7,7 @@ from digitalio import Direction # noqa
from busio import I2C # noqa from busio import I2C # noqa
import time import time
import os import os
import numpy as np
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
...@@ -181,9 +182,13 @@ class Tx(TxAbstract): ...@@ -181,9 +182,13 @@ class Tx(TxAbstract):
@property @property
def tx_bat(self): def tx_bat(self):
self.soh_logger.warning(f'Cannot get battery voltage on {self.model}') if np.isnan(self.tx.pwr.battery_voltage):
self.exec_logger.debug(f'{self.model} cannot read battery voltage. Returning default battery voltage.') self.soh_logger.warning(f'Cannot get battery voltage on {self.model}')
return self.pwr.voltage self.exec_logger.debug(f'{self.model} cannot read battery voltage. Returning default battery voltage.')
return self.pwr.voltage
else:
return self.tx.pwr.battery_voltage
def voltage_pulse(self, voltage=None, length=None, polarity=1): def voltage_pulse(self, voltage=None, length=None, polarity=1):
""" Generates a square voltage pulse """ Generates a square voltage pulse
......
...@@ -91,7 +91,6 @@ class Tx(Tx_mb_2023): ...@@ -91,7 +91,6 @@ class Tx(Tx_mb_2023):
Tx_mb_2023.inject(self, polarity=polarity, injection_duration=injection_duration) Tx_mb_2023.inject(self, polarity=polarity, injection_duration=injection_duration)
self.pin6.value = False self.pin6.value = False
class Rx(Rx_mb_2023): class Rx(Rx_mb_2023):
def __init__(self, **kwargs): def __init__(self, **kwargs):
if 'model' not in kwargs.keys(): if 'model' not in kwargs.keys():
......
...@@ -2,12 +2,15 @@ from ohmpi.hardware_components.abstract_hardware_components import PwrAbstract ...@@ -2,12 +2,15 @@ from ohmpi.hardware_components.abstract_hardware_components import PwrAbstract
import numpy as np import numpy as np
import datetime import datetime
import os import os
import time
from ohmpi.utils import enforce_specs from ohmpi.utils import enforce_specs
#import minimalmodbus # noqa #import minimalmodbus # noqa
# hardware characteristics and limitations # hardware characteristics and limitations
SPECS = {'model': {'default': os.path.basename(__file__).rstrip('.py')}, SPECS = {'model': {'default': os.path.basename(__file__).rstrip('.py')},
'voltage': {'default': 12., 'max': 50., 'min': 0.}, 'voltage': {'default': 12., 'max': 50., 'min': 0.},
'voltage_min': {'default': 0},
'voltage_max': {'default': 0},
'current_max': {'default': 100.}, 'current_max': {'default': 100.},
'current_adjustable': {'default': False}, 'current_adjustable': {'default': False},
'voltage_adjustable': {'default': True} 'voltage_adjustable': {'default': True}
...@@ -54,20 +57,21 @@ class Pwr(PwrAbstract): ...@@ -54,20 +57,21 @@ class Pwr(PwrAbstract):
def turn_on(self): def turn_on(self):
self.connection.write_register(0x09, 1) self.connection.write_register(0x09, 1)
self.exec_logger.debug(f'{self.model} is on') self.exec_logger.debug(f'{self.model} is on')
time.sleep(.3)
@property @property
def voltage(self): def voltage(self):
return PwrAbstract.voltage.fget(self) # return PwrAbstract.voltage.fget(self)
return self._voltage
@voltage.setter @voltage.setter
def voltage(self, value): def voltage(self, value):
self.connection.write_register(0x0000, value, 2) self.connection.write_register(0x0000, value, 2)
self._voltage = value
def battery_voltage(self): def battery_voltage(self):
self.connection.read_register(0x05, 2) self._battery_voltage = self.connection.read_register(0x05, 2)
return self._battery_voltage
def current_max(self, value): def current_max(self, value):
self.connection.write_register(0x0001, value * 10, 0) self.connection.write_register(0x0001, value * 10, 0)
def reset_voltage(self):
self.DPS.write_register(0x0000, 0, 2) # reset to 0 volt
\ No newline at end of file
...@@ -209,7 +209,7 @@ class OhmPiHardware: ...@@ -209,7 +209,7 @@ class OhmPiHardware:
mux.barrier = self.mux_barrier mux.barrier = self.mux_barrier
@property @property
def pulses(self): def pulses(self): # TODO: is this obsolete?
pulses = {} pulses = {}
for i in np.unique(self.readings[:, 1]): for i in np.unique(self.readings[:, 1]):
r = self.readings[self.readings[:, 1] == i, :] r = self.readings[self.readings[:, 1] == i, :]
...@@ -409,15 +409,16 @@ class OhmPiHardware: ...@@ -409,15 +409,16 @@ class OhmPiHardware:
self._vab_pulses(vab, durations, sampling_rate, polarities=polarities, append=append) self._vab_pulses(vab, durations, sampling_rate, polarities=polarities, append=append)
self.exec_logger.event(f'OhmPiHardware\tvab_square_wave\tend\t{datetime.datetime.utcnow()}') self.exec_logger.event(f'OhmPiHardware\tvab_square_wave\tend\t{datetime.datetime.utcnow()}')
def _vab_pulse(self, vab, duration, sampling_rate=None, polarity=1, append=False): def _vab_pulse(self, vab=None, duration=1., sampling_rate=None, polarity=1, 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
if sampling_rate is None: if sampling_rate is None:
sampling_rate = RX_CONFIG['sampling_rate'] sampling_rate = RX_CONFIG['sampling_rate']
if self.tx.pwr.voltage_adjustable: if self.tx.pwr.voltage_adjustable:
self.tx.pwr.voltage = vab if self.tx.pwr.voltage != vab:
else: self.tx.pwr.voltage = vab
else :
vab = self.tx.pwr.voltage vab = self.tx.pwr.voltage
# reads current and voltage during the pulse # reads current and voltage during the pulse
injection = Thread(target=self._inject, kwargs={'injection_duration': duration, 'polarity': polarity}) injection = Thread(target=self._inject, kwargs={'injection_duration': duration, 'polarity': polarity})
...@@ -431,6 +432,10 @@ class OhmPiHardware: ...@@ -431,6 +432,10 @@ class OhmPiHardware:
def _vab_pulses(self, vab, durations, sampling_rate, polarities=None, append=False): def _vab_pulses(self, vab, durations, sampling_rate, polarities=None, append=False):
n_pulses = len(durations) n_pulses = len(durations)
self.exec_logger.debug(f'n_pulses: {n_pulses}') self.exec_logger.debug(f'n_pulses: {n_pulses}')
if self.tx.pwr.voltage_adjustable:
self.tx.pwr.voltage = vab
else:
vab = self.tx.pwr.voltage
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:
...@@ -440,7 +445,7 @@ class OhmPiHardware: ...@@ -440,7 +445,7 @@ class OhmPiHardware:
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, duration=durations[i], sampling_rate=sampling_rate, polarity=polarities[i], self._vab_pulse(self, vab, duration=durations[i], sampling_rate=sampling_rate, polarity=polarities[i],
append=True) append=True)
def switch_mux(self, electrodes, roles=None, state='off', **kwargs): def switch_mux(self, electrodes, roles=None, state='off', **kwargs):
......
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