Commit 3b8f9d82 authored by Olivier Kaufmann's avatar Olivier Kaufmann
Browse files

Rewrites TX voltage handling

Showing with 30 additions and 16 deletions
+30 -16
......@@ -22,7 +22,8 @@ HARDWARE_CONFIG = {
},
'tx' : {'model' : 'ohmpi_card_3_15',
'mcp_board_address': 0x20,
'current_max': 4800 / 50 / 2, # Maximum current
'voltage_max': 12, # Maximum voltage [V]
'current_max': 4800 / 50 / 2, # Maximum current [mA]
'r_shunt': 2 # Shunt resistance in Ohms
},
'rx' : {'model': 'ohmpi_card_3_15',
......
......@@ -18,6 +18,7 @@ class ControllerAbstract(ABC):
self.exec_logger.debug(f'{self.board_name} Controller initialization')
self._cpu_temp_available = False
self.max_cpu_temp = np.inf
@property
def cpu_temperature(self):
if not self._cpu_temp_available:
......@@ -167,6 +168,9 @@ class TxAbstract(ABC):
self._dps_state = 'off'
self._adc_gain = 1.
self.inj_time = inj_time
self._voltage = 0.
self.voltage_adjustable = True
self._current_adjustable = False
self.exec_logger.debug(f'{self.board_name} TX initialization')
@property
......@@ -230,16 +234,17 @@ class TxAbstract(ABC):
self._dps_state = 'on'
@property
@abstractmethod
def voltage(self):
# add actions to read the DPS voltage and return it
return None
return self._voltage
@voltage.setter
@abstractmethod
def voltage(self, value):
# add actions to set the DPS voltage
pass
assert isinstance(value, float)
if not self.voltage_adjustable:
self.exec_logger.warning(f'Voltage cannot be set on {self.board_name}...')
else:
self._voltage = value
# Add specifics to set DPS voltage
@property
@abstractmethod
......
......@@ -74,6 +74,8 @@ class Tx(TxAbstract):
kwargs.update({'board_name': os.path.basename(__file__).rstrip('.py')})
super().__init__(**kwargs)
self._voltage = kwargs.pop('voltage', TX_CONFIG['default_voltage'])
self.voltage_adjustable = False
self.current_adjustable = False
if self.controller is None:
self.controller = controller_module.Controller()
......@@ -164,13 +166,6 @@ class Tx(TxAbstract):
self.pin1.value = False
#time.sleep(0.001) # TODO: check max switching time of relays
@property
def voltage(self):
return self._voltage
@voltage.setter
def voltage(self, value):
self.exec_logger.debug(f'Voltage cannot be set on {self.board_name}...')
def turn_off(self):
pass
......@@ -207,6 +202,16 @@ class Tx(TxAbstract):
time.sleep(length)
self.inject(state='off')
@property
def voltage(self):
return self._voltage
@voltage.setter
def voltage(self, value):
assert isinstance(value, float)
value = np.max(TX_CONFIG['voltage_min'], np.min(value, TX_CONFIG['voltage_max']))
super().voltage = value
class Rx(RxAbstract):
def __init__(self, **kwargs):
kwargs.update({'board_name': os.path.basename(__file__).rstrip('.py')})
......
......@@ -224,7 +224,10 @@ class OhmPiHardware:
sampling_rate = RX_CONFIG['sampling_rate']
if polarity is not None and polarity != self.tx.polarity:
self.tx.polarity = polarity
self.tx.voltage = vab
if self.tx.voltage_adjustable:
self.tx.voltage = vab
else:
vab = self.tx.voltage
injection = Thread(target=self._inject, kwargs={'duration':length})
readings = Thread(target=self._read_values, kwargs={'sampling_rate': sampling_rate, 'append': append})
# set gains automatically
......@@ -289,7 +292,7 @@ class OhmPiHardware:
if mux not in mux_workers:
mux_workers.append(mux)
except KeyError:
self.exec_logger.warning(f'({elec}, {roles[idx]} is not in cabling. It will be ignored...')
self.exec_logger.warning(f'({elec}, {roles[idx]}) is not in cabling. It will be ignored...')
mux_workers = list(set(mux_workers))
b = Barrier(len(mux_workers)+1)
self.mux_barrier = b
......
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