Commit 7839c673 authored by Olivier Kaufmann's avatar Olivier Kaufmann
Browse files

Adds enforce_specs in utils

Showing with 17 additions and 6 deletions
+17 -6
...@@ -23,7 +23,7 @@ SPECS = {'RX': {'voltage_adc_voltage_min': 10., 'voltage_adc_voltage_max': 4500. ...@@ -23,7 +23,7 @@ SPECS = {'RX': {'voltage_adc_voltage_min': 10., 'voltage_adc_voltage_max': 4500.
'data_rate': 860.}, 'data_rate': 860.},
'TX': {'current_adc_voltage_min': 10., 'bias': 0., 'injection_voltage_max': 12000., 'low_battery': 12000., 'TX': {'current_adc_voltage_min': 10., 'bias': 0., 'injection_voltage_max': 12000., 'low_battery': 12000.,
'tx_mcp_board_address': 0x20, 'data_rate': 860., 'comptatible_power_sources': ['pwr_batt', 'dps5005'], 'tx_mcp_board_address': 0x20, 'data_rate': 860., 'comptatible_power_sources': ['pwr_batt', 'dps5005'],
'r_shunt'}} 'r_shunt': 2., 'activation_delay': 0.005, 'release_delay': 0.001}}
# TODO: move low_battery spec in pwr # TODO: move low_battery spec in pwr
...@@ -102,7 +102,7 @@ class Tx(TxAbstract): ...@@ -102,7 +102,7 @@ class Tx(TxAbstract):
if kwargs['pwr'] not in SPECS['TX']['compatible_power_sources']: if kwargs['pwr'] not in SPECS['TX']['compatible_power_sources']:
self.exec_logger.warning(f'Incompatible power source specified check config') self.exec_logger.warning(f'Incompatible power source specified check config')
assert kwargs['pwr'] in SPECS['TX'] assert kwargs['pwr'] in SPECS['TX']
self.pwr = None # TODO: set a list of compatible power system with the tx #self.pwr = None # TODO: set a list of compatible power system with the tx
self.exec_logger.event(f'{self.board_name}\ttx_init\tbegin\t{datetime.datetime.utcnow()}') self.exec_logger.event(f'{self.board_name}\ttx_init\tbegin\t{datetime.datetime.utcnow()}')
self._voltage = kwargs.pop('voltage', TX_CONFIG['default_voltage']) self._voltage = kwargs.pop('voltage', TX_CONFIG['default_voltage'])
self.voltage_adjustable = False self.voltage_adjustable = False
...@@ -134,7 +134,6 @@ class Tx(TxAbstract): ...@@ -134,7 +134,6 @@ class Tx(TxAbstract):
self.pin4.direction = Direction.OUTPUT self.pin4.direction = Direction.OUTPUT
self.pin4.value = True self.pin4.value = True
self._latency = kwargs.pop('latency', TX_CONFIG['latency'])
self._bias = kwargs.pop('bias', TX_CONFIG['bias']) self._bias = kwargs.pop('bias', TX_CONFIG['bias'])
self.exec_logger.event(f'{self.board_name}\ttx_init\tend\t{datetime.datetime.utcnow()}') self.exec_logger.event(f'{self.board_name}\ttx_init\tend\t{datetime.datetime.utcnow()}')
...@@ -190,15 +189,15 @@ class Tx(TxAbstract): ...@@ -190,15 +189,15 @@ class Tx(TxAbstract):
if polarity == 1: if polarity == 1:
self.pin0.value = True self.pin0.value = True
self.pin1.value = False self.pin1.value = False
time.sleep(0.005) # Max turn on time of 211EH relays = 5ms time.sleep(SPECS['TX']['activation_delay']) # Max turn on time of 211EH relays = 5ms
elif polarity == -1: elif polarity == -1:
self.pin0.value = False self.pin0.value = False
self.pin1.value = True self.pin1.value = True
time.sleep(0.005) # Max turn on time of 211EH relays = 5ms time.sleep(SPECS['TX']['activation_delay']) # Max turn on time of 211EH relays = 5ms
else: else:
self.pin0.value = False self.pin0.value = False
self.pin1.value = False self.pin1.value = False
time.sleep(0.001) # Max turn off time of 211EH relays = 1ms time.sleep(SPECS['TX']['release_delay']) # Max turn off time of 211EH relays = 1ms
def turn_off(self): def turn_off(self):
self.pwr.turn_off(self) self.pwr.turn_off(self)
......
...@@ -4,6 +4,18 @@ import shutil ...@@ -4,6 +4,18 @@ import shutil
import collections.abc import collections.abc
import numpy as np import numpy as np
def enforce_specs(kwargs, specs, key):
kwargs.update({key: kwargs.pop(key, specs[key]['default'])})
s = specs.copy()
min_value = s[key].pop('min', -np.inf)
s[key]['min'] = min_value
max_value = s[key].pop('max', np.inf)
s[key]['max'] = max_value
if kwargs[key] < min_value:
kwargs[key] = min_value
elif kwargs[key] > max_value:
kwargs[key] = max_value
return kwargs
def update_dict(d, u): def update_dict(d, u):
"""Updates a dictionary by adding elements to collection items associated to existing keys """Updates a dictionary by adding elements to collection items associated to existing keys
......
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