Commit 21449f87 authored by Guillaume Blanchy's avatar Guillaume Blanchy
Browse files

Merge branch 'dev/dummy' into v2025_alpha

Showing with 408 additions and 39 deletions
+408 -39
...@@ -27,26 +27,55 @@ OHMPI_CONFIG = { ...@@ -27,26 +27,55 @@ OHMPI_CONFIG = {
} # TODO: add a dictionary with INA models and associated gain values } # TODO: add a dictionary with INA models and associated gain values
HARDWARE_CONFIG = { HARDWARE_CONFIG = {
'ctl': {'model' : 'dummy_ctl' 'ctl': {'model' : 'dummy_ctl'},
}, 'pwr': {'model': 'pwr_batt', 'voltage': 12., 'interface_name': 'none'},
'pwr' : {'model': 'dummy_pwr'}, 'tx': {'model': 'dummy_tx',
'tx' : {'model' : 'dummy_tx', 'voltage_max': 50., # Maximum voltage supported by the TX board [V]
'current_max': 4800 / 50 / 2, # Maximum current 'current_max': 4800 / 50 / 2, # Maximum voltage read by the current ADC on the TX board [A]
'R_shunt': 2 # Shunt resistance in Ohms 'r_shunt': 2, # Shunt resistance in Ohms
'interface_name': 'i2c'
}, },
'rx' : {'model': 'dummy_rx', 'rx': {'model': 'dummy_rx',
'coef_p2': 2.50, # slope for conversion for ADS, measurement in V/V
'sampling_rate': 50., # number of samples per second
'interface_name': 'i2c',
}, },
'mux': {'model' : 'dummy_mux', 'mux': {'boards':
'max_elec': 64, {'mux_A':
'voltage_max' : 100, {'model': 'dummy_mux',
'current_max' : 3 'mux_tca_address': 0x70,
'roles': {'A': 'X'},
'cabling': {(i, j): ('mux_A', i) for j in ['A'] for i in range(1, 65)},
'voltage_max': 12.},
'mux_B':
{'model': 'dummy_mux',
'mux_tca_address': 0x71,
'roles': {'B': 'X'},
'cabling': {(i, j): ('mux_B', i) for j in ['B'] for i in range(1, 65)},
'voltage_max': 12.},
'mux_M':
{'model': 'dummy_mux',
'mux_tca_address': 0x72,
'roles': {'M': 'X'},
'cabling': {(i, j): ('mux_M', i) for j in ['M'] for i in range(1, 65)},
'voltage_max': 12.},
'mux_N':
{'model': 'dummy_mux',
'mux_tca_address': 0x73,
'roles': {'N': 'X'},
'cabling': {(i, j): ('mux_N', i) for j in ['N'] for i in range(1, 65)},
'voltage_max': 12.},
},
'default': {'interface_name': 'i2c',
'voltage_max': 12.,
'current_max': 3.}
} }
} }
# SET THE LOGGING LEVELS, MQTT BROKERS AND MQTT OPTIONS ACCORDING TO YOUR NEEDS # SET THE LOGGING LEVELS, MQTT BROKERS AND MQTT OPTIONS ACCORDING TO YOUR NEEDS
# Execution logging configuration # Execution logging configuration
EXEC_LOGGING_CONFIG = { EXEC_LOGGING_CONFIG = {
'logging_level': logging.INFO, 'logging_level': logging.INFO, # TODO: set logging level back to INFO
'log_file_logging_level': logging.DEBUG, 'log_file_logging_level': logging.DEBUG,
'logging_to_console': True, 'logging_to_console': True,
'file_name': f'exec{logging_suffix}.log', 'file_name': f'exec{logging_suffix}.log',
...@@ -70,8 +99,8 @@ DATA_LOGGING_CONFIG = { ...@@ -70,8 +99,8 @@ DATA_LOGGING_CONFIG = {
# State of Health logging configuration (For a future release) # State of Health logging configuration (For a future release)
SOH_LOGGING_CONFIG = { SOH_LOGGING_CONFIG = {
'logging_level': logging.INFO, 'logging_level': logging.INFO,
'log_file_logging_level': logging.DEBUG,
'logging_to_console': True, 'logging_to_console': True,
'log_file_logging_level': logging.DEBUG,
'file_name': f'soh{logging_suffix}.log', 'file_name': f'soh{logging_suffix}.log',
'max_bytes': 16777216, 'max_bytes': 16777216,
'backup_count': 1024, 'backup_count': 1024,
...@@ -115,3 +144,77 @@ MQTT_CONTROL_CONFIG = { ...@@ -115,3 +144,77 @@ MQTT_CONTROL_CONFIG = {
'client_id': f'{OHMPI_CONFIG["id"]}', 'client_id': f'{OHMPI_CONFIG["id"]}',
'ctrl_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/ctrl' 'ctrl_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/ctrl'
} }
# # SET THE LOGGING LEVELS, MQTT BROKERS AND MQTT OPTIONS ACCORDING TO YOUR NEEDS
# # Execution logging configuration
# EXEC_LOGGING_CONFIG = {
# 'logging_level': logging.INFO,
# 'log_file_logging_level': logging.DEBUG,
# 'logging_to_console': True,
# 'file_name': f'exec{logging_suffix}.log',
# 'max_bytes': 262144,
# 'backup_count': 30,
# 'when': 'd',
# 'interval': 1
# }
# # Data logging configuration
# DATA_LOGGING_CONFIG = {
# 'logging_level': logging.INFO,
# 'logging_to_console': True,
# 'file_name': f'data{logging_suffix}.log',
# 'max_bytes': 16777216,
# 'backup_count': 1024,
# 'when': 'd',
# 'interval': 1
# }
# # State of Health logging configuration (For a future release)
# SOH_LOGGING_CONFIG = {
# 'logging_level': logging.INFO,
# 'log_file_logging_level': logging.DEBUG,
# 'logging_to_console': True,
# 'file_name': f'soh{logging_suffix}.log',
# 'max_bytes': 16777216,
# 'backup_count': 1024,
# 'when': 'd',
# 'interval': 1
# }
# # MQTT logging configuration parameters
# MQTT_LOGGING_CONFIG = {
# 'hostname': mqtt_broker,
# 'port': 1883,
# 'qos': 2,
# 'retain': False,
# 'keepalive': 60,
# 'will': None,
# 'auth': {'username': 'mqtt_user', 'password': 'mqtt_password'},
# 'tls': None,
# 'protocol': MQTTv31,
# 'transport': 'tcp',
# 'client_id': f'{OHMPI_CONFIG["id"]}',
# 'exec_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/exec',
# 'exec_logging_level': logging.DEBUG,
# 'data_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/data',
# 'data_logging_level': DATA_LOGGING_CONFIG['logging_level'],
# 'soh_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/soh',
# 'soh_logging_level': SOH_LOGGING_CONFIG['logging_level']
# }
# # MQTT control configuration parameters
# MQTT_CONTROL_CONFIG = {
# 'hostname': mqtt_broker,
# 'port': 1883,
# 'qos': 2,
# 'retain': False,
# 'keepalive': 60,
# 'will': None,
# 'auth': {'username': 'mqtt_user', 'password': 'mqtt_password'},
# 'tls': None,
# 'protocol': MQTTv31,
# 'transport': 'tcp',
# 'client_id': f'{OHMPI_CONFIG["id"]}',
# 'ctrl_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/ctrl'
# }
# import sys import logging
# sys.path.extend(['/home/su530201/PycharmProjects/OhmPi']) from ohmpi.utils import change_config
change_config('../configs/config_dummy.py', verbose=True)
from ohmpi.hardware_components.dummy_tx import Tx from ohmpi.hardware_components.dummy_tx import Tx
from ohmpi.hardware_components.dummy_rx import Rx from ohmpi.hardware_components.dummy_rx import Rx
from ohmpi.logging_setup import create_stdout_logger from ohmpi.logging_setup import create_stdout_logger
exec_logger = create_stdout_logger(name='exec') # exec_logger = create_stdout_logger(name='exec')
soh_logger = create_stdout_logger(name='soh') # soh_logger = create_stdout_logger(name='soh')
stand_alone = False
part_of_hardware_system = False
within_ohmpi = True
# Stand alone
if stand_alone:
print('\nCreating TX...')
tx = Tx(exec_logger=exec_logger, soh_logger=soh_logger)
print('\nCreating RX...')
rx = Rx(exec_logger=exec_logger, soh_logger=soh_logger)
if part_of_hardware_system:
from ohmpi.hardware_system import OhmPiHardware
print('Starting test of as part of an OhmPiHardware system.')
# mux_id = 'mux_03'
k = OhmPiHardware()
k.exec_logger.setLevel(logging.DEBUG)
# Test mux switching
k.reset_mux()
# k.switch_mux(electrodes=[1, 4, 2, 3], roles=['A', 'B', 'M', 'N'], state='on')
# time.sleep(1.)
# k.switch_mux(electrodes=[1, 4, 2, 3], roles=['A', 'B', 'M', 'N'], state='off')
# k.mux_boards[mux_id].test(activation_time=.4)
k.test_mux(activation_time=0.01)
k.reset_mux()
if within_ohmpi:
from ohmpi.ohmpi import OhmPi
# from ohmpi.plots import plot_exec_log
print('\nCreating TX...') print('Starting test with OhmPi.')
tx = Tx(exec_logger=exec_logger, soh_logger=soh_logger) k = OhmPi(mqtt=False)
print('\nCreating RX...') k._hw.exec_logger.setLevel(logging.DEBUG)
rx = Rx(exec_logger=exec_logger, soh_logger=soh_logger) A, B, M, N = (32, 29, 31, 30)
k.reset_mux()
# k.test_mux(activation_time=0.01)#mux_id='mux_A')
k._hw.switch_mux([A, B, M, N], state='on')
k._hw.vab_square_wave(12.,1., cycles=2)
# TODO self.tx_sync_wait() is blocking here
# k._hw.switch_mux([A, B, M, N], state='off')
# k._hw.calibrate_rx_bias() # electrodes 1 4 2 3 should be connected to a reference circuit
# k._hw.rx._bias = -1.38
# print(f'Resistance: {k._hw.last_rho :.2f} ohm, dev. {k._hw.last_dev:.2f} %, rx bias: {k._hw.rx._bias:.2f} mV')
# k._hw._plot_readings()
A, B, M, N = (0, 0, 0, 0)
# k._hw.switch_mux([A, B, M, N], state='on')
# k._hw.vab_square_wave(12., cycle_duration=10., cycles=3)
# k._hw.switch_mux([A, B, M, N], state='off')
# print(f'OhmPiHardware Resistance: {k._hw.last_rho :.2f} ohm, dev. {k._hw.last_dev:.2f} %, rx bias: {k._hw.rx._bias:.2f} mV')
# k._hw._plot_readings()
print('using OhmPi')
# d = k.run_measurement([A, B, M, N], injection_duration=1., nb_stack=2, duty_cycle=0.5)
# print('---', d)
# k._hw._plot_readings()
# print(f'OhmPiHardware: Resistance: {k._hw.last_resistance() :.2f} ohm, dev. {k._hw.last_dev():.2f} %, sp: {k._hw.sp:.2f} mV, rx bias: {k._hw.rx._bias:.2f} mV')
# print(f'OhmPi: Resistance: {d["R [ohm]"] :.2f} ohm, dev. {d["R_std [%]"]:.2f} %, rx bias: {k._hw.rx._bias:.2f} mV')
# k._hw._plot_readings(save_fig=False)
# plot_exec_log('ohmpi/logs/exec.log')
change_config('../configs/config_default.py', verbose=False)
...@@ -14,29 +14,67 @@ logging_suffix = '' ...@@ -14,29 +14,67 @@ logging_suffix = ''
# OhmPi configuration # OhmPi configuration
OHMPI_CONFIG = { OHMPI_CONFIG = {
'id': ohmpi_id, # Unique identifier of the OhmPi board (string) 'id': ohmpi_id, # Unique identifier of the OhmPi board (string)
# 'R_shunt': 2, # Shunt resistance in Ohms
# 'Imax': 4800 / 50 / 2, # Maximum current
# 'coef_p2': 2.50, # slope for current conversion for ADS.P2, measurement in V/V
# 'nb_samples': 20, # Max value 10 # was named integer before...
# 'version': 2, # Is this still needed?
# 'max_elec': 64,
# 'board_addresses': {'A': 0x73, 'B': 0x72, 'M': 0x71, 'N': 0x70}, # CHECK IF YOUR BOARDS HAVE THESE ADDRESSES
'settings': 'ohmpi_settings.json', # INSERT YOUR FAVORITE SETTINGS FILE HERE 'settings': 'ohmpi_settings.json', # INSERT YOUR FAVORITE SETTINGS FILE HERE
} # 'board_version': 'mb.2023.0.0',#,'22.10',
# 'mcp_board_address': 0x20
} # TODO: add a dictionary with INA models and associated gain values
HARDWARE_CONFIG = { HARDWARE_CONFIG = {
'ctl': {'model' : 'dummy_ctl' 'ctl': {'model' : 'dummy_ctl'},
}, 'pwr': {'model': 'pwr_batt', 'voltage': 12., 'interface_name': 'none'},
'tx' : {'model' : 'dummy_tx', 'tx': {'model': 'dummy_tx',
'current_max': 4800 / 50 / 2, # Maximum current mA 'voltage_max': 50., # Maximum voltage supported by the TX board [V]
'current_max': 4800 / 50 / 2, # Maximum voltage read by the current ADC on the TX board [A]
'r_shunt': 2, # Shunt resistance in Ohms 'r_shunt': 2, # Shunt resistance in Ohms
'low_battery': 12. # Volts 'interface_name': 'i2c'
}, },
'rx' : {'model': 'dummy_rx', 'rx': {'model': 'dummy_rx',
'coef_p2': 2.50, # slope for conversion for ADS, measurement in V/V
'sampling_rate': 50., # number of samples per second
'interface_name': 'i2c',
}, },
'mux': {'model' : 'dummy_mux', 'mux': {'boards':
'max_elec': 64, {'mux_A':
'voltage_max' : 100, {'model': 'dummy_mux',
'current_max' : 3 'mux_tca_address': 0x70,
'roles': {'A': 'X'},
'cabling': {(i, j): ('mux_A', i) for j in ['A'] for i in range(1, 65)},
'voltage_max': 12.},
'mux_B':
{'model': 'dummy_mux',
'mux_tca_address': 0x71,
'roles': {'B': 'X'},
'cabling': {(i, j): ('mux_B', i) for j in ['B'] for i in range(1, 65)},
'voltage_max': 12.},
'mux_M':
{'model': 'dummy_mux',
'mux_tca_address': 0x72,
'roles': {'M': 'X'},
'cabling': {(i, j): ('mux_M', i) for j in ['M'] for i in range(1, 65)},
'voltage_max': 12.},
'mux_N':
{'model': 'dummy_mux',
'mux_tca_address': 0x73,
'roles': {'N': 'X'},
'cabling': {(i, j): ('mux_N', i) for j in ['N'] for i in range(1, 65)},
'voltage_max': 12.},
},
'default': {'interface_name': 'i2c',
'voltage_max': 12.,
'current_max': 3.}
} }
} }
# SET THE LOGGING LEVELS, MQTT BROKERS AND MQTT OPTIONS ACCORDING TO YOUR NEEDS # SET THE LOGGING LEVELS, MQTT BROKERS AND MQTT OPTIONS ACCORDING TO YOUR NEEDS
# Execution logging configuration # Execution logging configuration
EXEC_LOGGING_CONFIG = { EXEC_LOGGING_CONFIG = {
'logging_level': logging.INFO, 'logging_level': logging.INFO, # TODO: set logging level back to INFO
'log_file_logging_level': logging.DEBUG, 'log_file_logging_level': logging.DEBUG,
'logging_to_console': True, 'logging_to_console': True,
'file_name': f'exec{logging_suffix}.log', 'file_name': f'exec{logging_suffix}.log',
...@@ -105,3 +143,77 @@ MQTT_CONTROL_CONFIG = { ...@@ -105,3 +143,77 @@ MQTT_CONTROL_CONFIG = {
'client_id': f'{OHMPI_CONFIG["id"]}', 'client_id': f'{OHMPI_CONFIG["id"]}',
'ctrl_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/ctrl' 'ctrl_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/ctrl'
} }
# # SET THE LOGGING LEVELS, MQTT BROKERS AND MQTT OPTIONS ACCORDING TO YOUR NEEDS
# # Execution logging configuration
# EXEC_LOGGING_CONFIG = {
# 'logging_level': logging.INFO,
# 'log_file_logging_level': logging.DEBUG,
# 'logging_to_console': True,
# 'file_name': f'exec{logging_suffix}.log',
# 'max_bytes': 262144,
# 'backup_count': 30,
# 'when': 'd',
# 'interval': 1
# }
# # Data logging configuration
# DATA_LOGGING_CONFIG = {
# 'logging_level': logging.INFO,
# 'logging_to_console': True,
# 'file_name': f'data{logging_suffix}.log',
# 'max_bytes': 16777216,
# 'backup_count': 1024,
# 'when': 'd',
# 'interval': 1
# }
# # State of Health logging configuration (For a future release)
# SOH_LOGGING_CONFIG = {
# 'logging_level': logging.INFO,
# 'log_file_logging_level': logging.DEBUG,
# 'logging_to_console': True,
# 'file_name': f'soh{logging_suffix}.log',
# 'max_bytes': 16777216,
# 'backup_count': 1024,
# 'when': 'd',
# 'interval': 1
# }
# # MQTT logging configuration parameters
# MQTT_LOGGING_CONFIG = {
# 'hostname': mqtt_broker,
# 'port': 1883,
# 'qos': 2,
# 'retain': False,
# 'keepalive': 60,
# 'will': None,
# 'auth': {'username': 'mqtt_user', 'password': 'mqtt_password'},
# 'tls': None,
# 'protocol': MQTTv31,
# 'transport': 'tcp',
# 'client_id': f'{OHMPI_CONFIG["id"]}',
# 'exec_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/exec',
# 'exec_logging_level': logging.DEBUG,
# 'data_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/data',
# 'data_logging_level': DATA_LOGGING_CONFIG['logging_level'],
# 'soh_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/soh',
# 'soh_logging_level': SOH_LOGGING_CONFIG['logging_level']
# }
# # MQTT control configuration parameters
# MQTT_CONTROL_CONFIG = {
# 'hostname': mqtt_broker,
# 'port': 1883,
# 'qos': 2,
# 'retain': False,
# 'keepalive': 60,
# 'will': None,
# 'auth': {'username': 'mqtt_user', 'password': 'mqtt_password'},
# 'tls': None,
# 'protocol': MQTTv31,
# 'transport': 'tcp',
# 'client_id': f'{OHMPI_CONFIG["id"]}',
# 'ctrl_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/ctrl'
# }
...@@ -8,3 +8,13 @@ class Ctl(CtlAbstract): ...@@ -8,3 +8,13 @@ class Ctl(CtlAbstract):
def __init__(self, **kwargs): def __init__(self, **kwargs):
kwargs.update({'model': os.path.basename(__file__).rstrip('.py')}) kwargs.update({'model': os.path.basename(__file__).rstrip('.py')})
super().__init__(**kwargs) super().__init__(**kwargs)
self.interfaces = dict()
# None interface for battery
self.interfaces['none'] = None
self.interfaces['i2c'] = None
self.max_cpu_temp = 85. # °C
@property
def _cpu_temp(self):
return 42
...@@ -17,5 +17,5 @@ class Mux(MuxAbstract): ...@@ -17,5 +17,5 @@ class Mux(MuxAbstract):
def switch_one(self, *args): def switch_one(self, *args):
MuxAbstract.switch_one(self, *args) MuxAbstract.switch_one(self, *args)
def test(self, *args): def test(self, *args, **kwargs):
MuxAbstract.test(self, *args) MuxAbstract.test(self, *args)
\ No newline at end of file
from ohmpi.ohmpi.config import HARDWARE_CONFIG from ohmpi.config import HARDWARE_CONFIG
import numpy as np import numpy as np
import os import os
from ohmpi.hardware_components import RxAbstract from ohmpi.hardware_components import RxAbstract
RX_CONFIG = HARDWARE_CONFIG['rx'] RX_CONFIG = HARDWARE_CONFIG['rx']
# hardware characteristics and limitations
# voltages are given in mV, currents in mA, sampling rates in Hz and data_rate in S/s
SPECS = {'rx': {'model': {'default': os.path.basename(__file__).rstrip('.py')},
'sampling_rate': {'min': 2., 'default': 10., 'max': 100.},
'data_rate': {'default': 860.},
'bias': {'min': -5000., 'default': 0., 'max': 5000.},
'coef_p2': {'default': 1.00},
'mcp_address': {'default': 0x27},
'ads_address': {'default': 0x49},
'voltage_min': {'default': 10.0},
'voltage_max': {'default': 5000.0}, # [mV]
'dg411_gain_ratio': {'default': 1/2}, # lowest resistor value over sum of resistor values
'vmn_hardware_offset': {'default': 2500.},
},
'tx': {'model': {'default': os.path.basename(__file__).rstrip('.py')},
'adc_voltage_min': {'default': 10.}, # Minimum voltage value used in vmin strategy
'adc_voltage_max': {'default': 4500.}, # Maximum voltage on ads1115 used to measure current
'voltage_max': {'min': 0., 'default': 12., 'max': 50.}, # Maximum input voltage
'data_rate': {'default': 860.},
'mcp_address': {'default': 0x21},
'ads_address': {'default': 0x48},
'compatible_power_sources': {'default': ['pwr_batt', 'dps5005']},
'r_shunt': {'min': 0.001, 'default': 2.},
'activation_delay': {'default': 0.010}, # Max turn on time of OMRON G5LE-1 5VDC relays
'release_delay': {'default': 0.005}, # Max turn off time of OMRON G5LE-1 5VDC relays = 1ms
'pwr_latency': {'default': 4.}
}}
# hardware characteristics and limitations # hardware characteristics and limitations
# ADC for voltage # ADC for voltage
voltage_adc_voltage_min = 10. # mV voltage_adc_voltage_min = 10. # mV
...@@ -30,6 +58,9 @@ class Rx(RxAbstract): ...@@ -30,6 +58,9 @@ class Rx(RxAbstract):
gain = 1. gain = 1.
self.exec_logger.debug(f'Setting RX ADC gain automatically to {gain}') self.exec_logger.debug(f'Setting RX ADC gain automatically to {gain}')
self.adc_gain = gain self.adc_gain = gain
def gain_auto(self):
self._adc_gain_auto()
@property @property
def voltage(self): def voltage(self):
......
...@@ -6,6 +6,34 @@ from ohmpi.hardware_components import TxAbstract ...@@ -6,6 +6,34 @@ from ohmpi.hardware_components import TxAbstract
TX_CONFIG = HARDWARE_CONFIG['tx'] TX_CONFIG = HARDWARE_CONFIG['tx']
# hardware characteristics and limitations
# voltages are given in mV, currents in mA, sampling rates in Hz and data_rate in S/s
SPECS = {'rx': {'model': {'default': os.path.basename(__file__).rstrip('.py')},
'sampling_rate': {'min': 2., 'default': 10., 'max': 100.},
'data_rate': {'default': 860.},
'bias': {'min': -5000., 'default': 0., 'max': 5000.},
'coef_p2': {'default': 1.00},
'mcp_address': {'default': 0x27},
'ads_address': {'default': 0x49},
'voltage_min': {'default': 10.0},
'voltage_max': {'default': 5000.0}, # [mV]
'dg411_gain_ratio': {'default': 1/2}, # lowest resistor value over sum of resistor values
'vmn_hardware_offset': {'default': 2500.},
},
'tx': {'model': {'default': os.path.basename(__file__).rstrip('.py')},
'adc_voltage_min': {'default': 10.}, # Minimum voltage value used in vmin strategy
'adc_voltage_max': {'default': 4500.}, # Maximum voltage on ads1115 used to measure current
'voltage_max': {'min': 0., 'default': 12., 'max': 50.}, # Maximum input voltage
'data_rate': {'default': 860.},
'mcp_address': {'default': 0x21},
'ads_address': {'default': 0x48},
'compatible_power_sources': {'default': ['pwr_batt', 'dps5005']},
'r_shunt': {'min': 0.001, 'default': 2.},
'activation_delay': {'default': 0.010}, # Max turn on time of OMRON G5LE-1 5VDC relays
'release_delay': {'default': 0.005}, # Max turn off time of OMRON G5LE-1 5VDC relays = 1ms
'pwr_latency': {'default': 4.}
}}
# ADC for current # ADC for current
current_adc_voltage_min = 10. # mV current_adc_voltage_min = 10. # mV
current_adc_voltage_max = 4500. # mV current_adc_voltage_max = 4500. # mV
...@@ -24,8 +52,6 @@ TX_CONFIG['dps_switch_on_warm_up'] = TX_CONFIG.pop('dps_switch_on_warmup', dps_s ...@@ -24,8 +52,6 @@ TX_CONFIG['dps_switch_on_warm_up'] = TX_CONFIG.pop('dps_switch_on_warmup', dps_s
TX_CONFIG['low_battery'] = TX_CONFIG.pop('low_battery', tx_low_battery) TX_CONFIG['low_battery'] = TX_CONFIG.pop('low_battery', tx_low_battery)
class Tx(TxAbstract): class Tx(TxAbstract):
def inject(self, state='on'):
pass
def __init__(self, **kwargs): def __init__(self, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
...@@ -33,12 +59,20 @@ class Tx(TxAbstract): ...@@ -33,12 +59,20 @@ class Tx(TxAbstract):
self._adc_gain = 1. self._adc_gain = 1.
class Pin(object):
def __init__(self, val):
self.value = val
self.pin0 = Pin(False)
self.pin1 = Pin(False)
self.polarity = 0 self.polarity = 0
self.turn_on()
time.sleep(TX_CONFIG['dps_switch_on_warm_up']) time.sleep(TX_CONFIG['dps_switch_on_warm_up'])
self.exec_logger.info(f'TX battery: {self.tx_bat:.1f} V') self.exec_logger.info(f'TX battery: {self.tx_bat:.1f} V')
self.turn_off()
def inject(self, polarity=1, injection_duration=None, switch_pwr=False):
self.polarity = polarity
# TxAbstract.inject(self, polarity=polarity, injection_duration=injection_duration, switch_pwr=switch_pwr)
@property @property
def adc_gain(self): def adc_gain(self):
...@@ -53,6 +87,9 @@ class Tx(TxAbstract): ...@@ -53,6 +87,9 @@ class Tx(TxAbstract):
gain = 1. gain = 1.
self.exec_logger.debug(f'Setting TX ADC gain automatically to {gain}') self.exec_logger.debug(f'Setting TX ADC gain automatically to {gain}')
self.adc_gain = gain self.adc_gain = gain
def gain_auto(self):
self._adc_gain_auto()
def current_pulse(self, **kwargs): def current_pulse(self, **kwargs):
super().current_pulse(**kwargs) super().current_pulse(**kwargs)
...@@ -92,6 +129,24 @@ class Tx(TxAbstract): ...@@ -92,6 +129,24 @@ class Tx(TxAbstract):
if tx_bat < 12.: if tx_bat < 12.:
self.soh_logger.debug(f'Low TX Battery: {tx_bat:.1f} V') self.soh_logger.debug(f'Low TX Battery: {tx_bat:.1f} V')
return tx_bat return tx_bat
@property
def polarity(self):
return self._polarity
@polarity.setter
def polarity(self, polarity):
assert polarity in [-1, 0, 1]
self._polarity = polarity
if polarity == 1:
self.pin0.value = True
self.pin1.value = False
elif polarity == -1:
self.pin0.value = False
self.pin1.value = True
else:
self.pin0.value = False
self.pin1.value = False
def voltage_pulse(self, voltage=TX_CONFIG['default_voltage'], length=None, polarity=None): def voltage_pulse(self, voltage=TX_CONFIG['default_voltage'], length=None, polarity=None):
""" Generates a square voltage pulse """ Generates a square voltage pulse
......
...@@ -85,6 +85,7 @@ class OhmPiHardware: ...@@ -85,6 +85,7 @@ class OhmPiHardware:
if isinstance(ctl_mod, str): if isinstance(ctl_mod, str):
ctl_mod = importlib.import_module(f'ohmpi.hardware_components.{ctl_mod}') ctl_mod = importlib.import_module(f'ohmpi.hardware_components.{ctl_mod}')
HARDWARE_CONFIG['rx']['ctl'] = ctl_mod.Ctl(**HARDWARE_CONFIG['rx']['ctl']) HARDWARE_CONFIG['rx']['ctl'] = ctl_mod.Ctl(**HARDWARE_CONFIG['rx']['ctl'])
print(HARDWARE_CONFIG['rx'])
HARDWARE_CONFIG['rx'].update({'connection': HARDWARE_CONFIG['rx'].update({'connection':
HARDWARE_CONFIG['rx'].pop('connection', HARDWARE_CONFIG['rx'].pop('connection',
HARDWARE_CONFIG['rx']['ctl'].interfaces[ HARDWARE_CONFIG['rx']['ctl'].interfaces[
......
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