diff --git a/configs/config_mb_2023_4_mux_2023.py b/configs/config_mb_2023_4_mux_2023.py deleted file mode 100644 index 7d7fa2fda28ae3cddbf33f04bdcf9b4c240960f5..0000000000000000000000000000000000000000 --- a/configs/config_mb_2023_4_mux_2023.py +++ /dev/null @@ -1,139 +0,0 @@ -import logging -from ohmpi.utils import get_platform - -from paho.mqtt.client import MQTTv31 - -_, on_pi = get_platform() -# DEFINE THE ID OF YOUR OhmPi -ohmpi_id = '0001' if on_pi else 'XXXX' -# DEFINE YOUR MQTT BROKER (DEFAULT: 'localhost') -mqtt_broker = 'localhost' if on_pi else 'NAME_YOUR_BROKER_WHEN_IN_SIMULATION_MODE_HERE' -# DEFINE THE SUFFIX TO ADD TO YOUR LOGS FILES -logging_suffix = '' - -# OhmPi configuration -OHMPI_CONFIG = { - 'id': ohmpi_id, # Unique identifier of the OhmPi board (string) - 'settings': 'ohmpi_settings.json', # INSERT YOUR FAVORITE SETTINGS FILE HERE -} - -HARDWARE_CONFIG = { - 'ctl': {'model': 'raspberry_pi'}, - 'pwr': {'model': 'pwr_batt', 'voltage': 12.}, - 'tx': {'model': 'mb_2023_0_X', - 'mcp_board_address': 0x20, - 'voltage_max': 12., # Maximum voltage supported by the TX board [V] - 'current_max': 4800 / 50 / 2, # Maximum current supported by the TX board [mA] - 'r_shunt': 2 # Shunt resistance in Ohms - }, - 'rx': {'model': 'mb_2023_0_X', - '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... - }, - 'mux': # default properties are system properties that will be - # overwritten by board properties defined at the board level within the board model file - # both will be overwritten by properties specified in the board dict below. Use with caution... - {'boards': - {'mux_1': - {'model': 'mux_2023_0_X', # 'ohmpi_i2c_mux64_v1.01', - 'tca_address': 0x70, - 'roles': {'A': 'X'}, - 'cabling': {(i, j): ('mux_1', i) for j in ['A'] for i in range(1, 65)}, - 'voltage_max': 12.}, - 'mux_2': - {'model': 'mux_2023_0_X', # 'ohmpi_i2c_mux64_v1.01', - 'tca_address': 0x71, - 'roles': {'B': 'X'}, - 'cabling': {(i, j): ('mux_2', i) for j in ['B'] for i in range(1, 65)}, - 'voltage_max': 12.}, - 'mux_3': - {'model': 'mux_2023_0_X', # 'ohmpi_i2c_mux64_v1.01', - 'tca_address': 0x72, - 'roles': {'M': 'X'}, - 'cabling': {(i, j): ('mux_3', i) for j in ['M'] for i in range(1, 65)}, - 'voltage_max': 12.}, - 'mux_4': - {'model': 'mux_2023_0_X', # 'ohmpi_i2c_mux64_v1.01', - 'tca_address': 0x73, - 'roles': {'N': 'X'}, - 'cabling': {(i, j): ('mux_4', i) for j in ['N'] for i in range(1, 65)}, - 'voltage_max': 12.}, - }, - 'default': {'connection': 'i2c', - 'voltage_max': 100., - 'current_max': 3.} - } -} - -# 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, - 'logging_to_console': True, - 'log_file_logging_level': logging.DEBUG, - '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' -} diff --git a/configs/config_mb_2023_4_mux_2024.py b/configs/config_mb_2023_4_mux_2024.py deleted file mode 100644 index 23689580c1aa06dbf6e962c85f926ca5e27f54ce..0000000000000000000000000000000000000000 --- a/configs/config_mb_2023_4_mux_2024.py +++ /dev/null @@ -1,151 +0,0 @@ -import logging -from ohmpi.utils import get_platform - -from paho.mqtt.client import MQTTv31 - -_, on_pi = get_platform() -# DEFINE THE ID OF YOUR OhmPi -ohmpi_id = '0001' if on_pi else 'XXXX' -# DEFINE YOUR MQTT BROKER (DEFAULT: 'localhost') -mqtt_broker = 'localhost' if on_pi else 'NAME_YOUR_BROKER_WHEN_IN_SIMULATION_MODE_HERE' -# DEFINE THE SUFFIX TO ADD TO YOUR LOGS FILES -logging_suffix = '' - -# OhmPi configuration -OHMPI_CONFIG = { - 'id': ohmpi_id, # Unique identifier of the OhmPi board (string) - 'settings': 'ohmpi_settings.json', # INSERT YOUR FAVORITE SETTINGS FILE HERE -} - -HARDWARE_CONFIG = { - 'ctl': {'model': 'raspberry_pi'}, - 'pwr': {'model': 'pwr_batt', 'voltage': 12.}, - 'tx': {'model': 'mb_2023_0_X', - 'mcp_board_address': 0x20, - 'voltage_max': 12., # Maximum voltage supported by the TX board [V] - 'current_max': 4800 / 50 / 2, # Maximum current supported by the TX board [mA] - 'r_shunt': 2 # Shunt resistance in Ohms - }, - 'rx': {'model': 'mb_2023_0_X', - 'coef_p2': 2.50, # slope for conversion for ADS, measurement in V/V - 'latency': 0.010, # latency in seconds in continuous mode - 'sampling_rate': 50 # number of samples per second - }, - 'mux': # default properties are system properties that will be - # overwritten by board properties defined at the board level within the board model file - # both will be overwritten by properties specified in the board dict below. Use with caution... - {'boards': - {'mux_02': - {'model': 'mux_2024_0_X', # 'ohmpi_i2c_mux64_v1.01', - 'tca_address': 0x77, - 'tca_channel': 0, - 'mcp_0': '0x22', # NOTE: Check pos of jumper on MUX board (refer to doc) - 'mcp_1': '0x23', # NOTE: Check pos of jumper on MUX board (refer to doc) - 'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, - 'cabling': {(i+8, j): ('mux_02', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, # TODO: avoid redundency of mux_id - 'voltage_max': 12.}, - 'mux_05': - {'model': 'mux_2024_0_X', # 'ohmpi_i2c_mux64_v1.01', - 'tca_address': 0x77, - 'tca_channel': 0, - 'mcp_0': '0x26', # NOTE: Check pos of jumper on MUX board (refer to doc) - 'mcp_1': '0x27', # NOTE: Check pos of jumper on MUX board (refer to doc) - 'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, - 'cabling': {(i+16, j): ('mux_05', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, - 'voltage_max': 12.}, - 'mux_04': - {'model': 'mux_2024_0_X', # 'ohmpi_i2c_mux64_v1.01', - 'tca_address': 0x77, - 'tca_channel': 1, - 'mcp_0': '0x24', # NOTE: Check pos of jumper on MUX board (refer to doc) - 'mcp_1': '0x25', # NOTE: Check pos of jumper on MUX board (refer to doc) - 'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, - 'cabling': {(i+24, j): ('mux_04', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, - 'voltage_max': 12.}, - 'mux_03': - {'model': 'mux_2024_0_X', # 'ohmpi_i2c_mux64_v1.01', - 'tca_address': 0x77, - 'tca_channel': 1, - 'mcp_0': '0x26', # NOTE: Check pos of jumper on MUX board (refer to doc) - 'mcp_1': '0x27', # NOTE: Check pos of jumper on MUX board (refer to doc) - 'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, - 'cabling': {(i+32, j): ('mux_03', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, - 'voltage_max': 12.} - }, - 'default': {'voltage_max': 100., - 'current_max': 3.} - } -} - -# 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, - 'logging_to_console': True, - 'log_file_logging_level': logging.DEBUG, - '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' -} diff --git a/configs/config_mb_2023_mux_2024.py b/configs/config_mb_2023_mux_2024.py deleted file mode 100644 index e78a44a6ebd3839240ca7d56d03b1ff13e80936a..0000000000000000000000000000000000000000 --- a/configs/config_mb_2023_mux_2024.py +++ /dev/null @@ -1,123 +0,0 @@ -import logging -from ohmpi.utils import get_platform - -from paho.mqtt.client import MQTTv31 - -_, on_pi = get_platform() -# DEFINE THE ID OF YOUR OhmPi -ohmpi_id = '0001' if on_pi else 'XXXX' -# DEFINE YOUR MQTT BROKER (DEFAULT: 'localhost') -mqtt_broker = 'localhost' if on_pi else 'NAME_YOUR_BROKER_WHEN_IN_SIMULATION_MODE_HERE' -# DEFINE THE SUFFIX TO ADD TO YOUR LOGS FILES -logging_suffix = '' - -# OhmPi configuration -OHMPI_CONFIG = { - 'id': ohmpi_id, # Unique identifier of the OhmPi board (string) - 'settings': 'ohmpi_settings.json', # INSERT YOUR FAVORITE SETTINGS FILE HERE -} - -HARDWARE_CONFIG = { - 'ctl': {'model' : 'raspberry_pi' - }, - 'pwr': {'model' : 'pwr_batt', 'voltage': 12.}, - 'tx' : {'model' : 'mb_2023_0_X', - 'mcp_board_address': 0x20, - 'voltage_max': 12., # Maximum voltage supported by the TX board [V] - 'current_max': 4800 / 50 / 2, # Maximum current supported by the TX board [mA] - 'r_shunt': 2 # Shunt resistance in Ohms - }, - 'rx': {'model': 'mb_2023_0_X', - 'coef_p2': 2.50, # slope for current conversion for ADS.P2, measurement in V/V - 'sampling_rate': 100., # Hz - 'nb_samples': 20, # Max value 10 # was named integer before... - }, - 'mux': # default properties are system properties that will be - # overwritten by board properties defined at the board level within the board model file - # both will be overwritten by properties specified in the board dict below. Use with caution... - {'boards': - {'mux_1': - {'model' : 'mux_2024_0_X', # 'ohmpi_i2c_mux64_v1.01', - 'tca_address': None, - 'tca_channel': 0, - 'mcp_0' : '0x22', # TODO : Replace this with pos of jumper on MUX board (address doesn't mean anything for the average user... - 'mcp_1' : '0x23', # TODO : Replace this with pos of jumper on MUX board (address doesn't mean anything for the average user...) - 'roles' : {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, - 'voltage_max': 12. - } - }, - 'default': {'voltage_max': 100., 'current_max': 3.}} -} - -# 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, - 'logging_to_console': True, - 'log_file_logging_level': logging.DEBUG, - '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' -} diff --git a/configs/config_mb_2023_2_mux_2024.py b/configs/config_mb_2024_1_mux_2024.py similarity index 68% rename from configs/config_mb_2023_2_mux_2024.py rename to configs/config_mb_2024_1_mux_2024.py index 74645aafee9880eecf27d67c321cfb5ce98dadf5..1ce2e8cc26dc5034cee0a8329166543bb4ca2a73 100644 --- a/configs/config_mb_2023_2_mux_2024.py +++ b/configs/config_mb_2024_1_mux_2024.py @@ -21,40 +21,33 @@ HARDWARE_CONFIG = { 'ctl': {'model': 'raspberry_pi'}, 'pwr': {'model': 'pwr_batt', 'voltage': 12.}, 'tx': {'model': 'mb_2023_0_X', - 'mcp_board_address': 0x20, 'voltage_max': 12., # Maximum voltage supported by the TX board [V] - 'current_max': 4800 / 50 / 2, # Maximum current supported by the TX board [mA] - 'r_shunt': 2 # Shunt resistance in Ohms + 'adc_voltage_max': 4800., # Maximum voltage read by the current ADC on the TX board [mA] + 'r_shunt': 2., # Shunt resistance in Ohms + 'interface_name': 'i2c', }, 'rx': {'model': 'mb_2023_0_X', - 'coef_p2': 2.50, # slope for conversion for ADS, measurement in V/V - 'latency': 0.010, # latency in seconds in continuous mode - 'sampling_rate': 50 # number of samples per second + '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': # default properties are system properties that will be - # overwritten by board properties defined at the board level within the board model file - # both will be overwritten by properties specified in the board dict below. Use with caution... + 'mux': # default properties given in config are system properties that will be + # overwritten by properties defined in each the board dict below. + # if defined in board specs, values out of specs will be bounded to remain in specs + # omitted properties in config will be set to board specs default values if they exist {'boards': - {'mux_1': - {'model': 'mux_2024_0_X', # 'ohmpi_i2c_mux64_v1.01', + {'mux_00': + {'model': 'mux_2024_0_X', 'tca_address': None, 'tca_channel': 0, - 'mcp_0': '0x22', # TODO : Replace this with pos of jumper on MUX board (address doesn't mean anything for the average user... - 'mcp_1': '0x23', # TODO : Replace this with pos of jumper on MUX board (address doesn't mean anything for the average user...) - 'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, - 'cabling': {(i+8, j): ('mux_1', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, - 'voltage_max': 12.}, - 'mux_2': - {'model': 'mux_2024_0_X', # 'ohmpi_i2c_mux64_v1.01', - 'tca_address': None, - 'tca_channel': 0, - 'mcp_0': '0x24', # TODO : Replace this with pos of jumper on MUX board (address doesn't mean anything for the average user... + 'mcp_0': '0x24', # TODO : Replace this with pos of jumper on MUX board (address doesn't mean anything for the average user...) 'mcp_1': '0x25', # TODO : Replace this with pos of jumper on MUX board (address doesn't mean anything for the average user...) 'roles': {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, - 'cabling': {(i+16, j): ('mux_2', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, - 'voltage_max': 12.} - }, - 'default': {'voltage_max': 100., + 'cabling': {(i+0, j): ('mux_00', i) for j in ['A', 'B', 'M', 'N'] for i in range(1, 9)}, + 'voltage_max': 12.}, + }, + 'default': {'interface_name': 'i2c', + 'voltage_max': 100., 'current_max': 3.} } } diff --git a/dev/test_2_mux_2024.py b/dev/test_2_mux_2024.py deleted file mode 100644 index a033c7199327f94589ceeafe276a654a9280861d..0000000000000000000000000000000000000000 --- a/dev/test_2_mux_2024.py +++ /dev/null @@ -1,60 +0,0 @@ -import time -from ohmpi.utils import change_config -from ohmpi.plots import plot_exec_log -import logging -change_config('../configs/config_mb_2023_2_mux_2024.py', verbose=False) -from ohmpi.hardware_components.mux_2024_0_X import Mux, MUX_CONFIG -from ohmpi.hardware_components import raspberry_pi as ctl_module -# from ohmpi.config import HARDWARE_CONFIG - -stand_alone_mux = False -part_of_hardware_system = False -within_ohmpi = True -# Stand alone mux -if stand_alone_mux: - MUX_CONFIG['ctl'] = ctl_module.Ctl() - MUX_CONFIG['id'] = 'mux_1' - MUX_CONFIG['cabling'] = {(i+8, j) : ('mux_1', i) for j in ['A', 'B', 'M', 'N'] for i in range(1,9)} - mux = Mux(**MUX_CONFIG) - mux.switch_one(elec=9, role='M', state='on') - time.sleep(2) - mux.switch_one(elec=9, role='M', state='off') - mux.switch({'A': [9], 'B': [12], 'M': [10], 'N': [11]}, state='on') - time.sleep(8) - # mux.switch({'A': [1], 'B': [4], 'M': [2], 'N': [3]}, state='off') - mux.reset() - mux.test({'A': [9, 10, 11, 12, 13, 14, 15, 16], 'B': [9, 10, 11, 12, 13, 14, 15, 16], - 'M': [9, 10, 11, 12, 13, 14, 15, 16], 'N': [9, 10, 11, 12, 13, 14, 15, 16]}, activation_time=.1) - -# mux as part of a OhmPiHardware system -if part_of_hardware_system: - from ohmpi.hardware_system import OhmPiHardware - print('Starting test of mux as part of a OhmPiHardware system.') - - 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') - -if within_ohmpi: - from ohmpi.ohmpi import OhmPi - print('Starting test of mux within OhmPi.') - k = OhmPi() - k.reset_mux() - k._hw.switch_mux([9, 12, 10, 11], state='on') - k._hw.vab_square_wave(3.,1) - k._hw.switch_mux([9, 12, 10, 11], state='off') - k._hw.calibrate_rx_bias() # electrodes 1 4 2 3 should be connected to a reference circuit - # 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() - k._hw.switch_mux([9, 12, 10, 11], state='on') - k._hw.vab_square_wave(3.,1) - k._hw.switch_mux([9, 12, 10, 11], state='off') - 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() - plot_exec_log('ohmpi/logs/exec.log') -change_config('../configs/config_default.py', verbose=False) \ No newline at end of file diff --git a/dev/test_4_mux_2024.py b/dev/test_4_mux_2024.py deleted file mode 100644 index 1798a59c8757e118c3402f7c679399146d299449..0000000000000000000000000000000000000000 --- a/dev/test_4_mux_2024.py +++ /dev/null @@ -1,65 +0,0 @@ -import time -from ohmpi.utils import change_config -from ohmpi.plots import plot_exec_log -import logging -change_config('../configs/config_mb_2023_4_mux_2024.py', verbose=False) -from ohmpi.hardware_components.mux_2024_0_X import Mux, MUX_CONFIG -from ohmpi.hardware_components import raspberry_pi as ctl_module -from ohmpi.config import HARDWARE_CONFIG - -stand_alone_mux = False -part_of_hardware_system = True -within_ohmpi = False - - -# Stand alone mux -if stand_alone_mux: - mux_id = 'mux_05' - first = 8 - print(MUX_CONFIG) - MUX_CONFIG.update(HARDWARE_CONFIG['mux']['boards'][mux_id]) - MUX_CONFIG.update({'id': mux_id}) - MUX_CONFIG['ctl'] = ctl_module.Ctl() - mux = Mux(**MUX_CONFIG) - mux.switch_one(elec=1+first, role='M', state='on') - time.sleep(2) - mux.switch_one(elec=1+first, role='M', state='off') - mux.switch({'A': [1], 'B': [2], 'M': [3], 'N': [4]}, state='on') - time.sleep(8) - # mux.switch({'A': [1], 'B': [4], 'M': [2], 'N': [3]}, state='off') - mux.reset() - mux.test({'A': [i+first for i in range(1, 9)], 'B': [i+first for i in range(1, 9)], - 'M': [i+first for i in range(1, 9)], 'N': [i+first for i in range(1, 9)]}, activation_time=.1) - -# mux as part of a OhmPiHardware system -if part_of_hardware_system: - from ohmpi.hardware_system import OhmPiHardware - print('Starting test of mux as part of a OhmPiHardware system.') - - 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') - -if within_ohmpi: - from ohmpi.ohmpi import OhmPi - print('Starting test of mux within OhmPi.') - k = OhmPi() - k.reset_mux() - k._hw.switch_mux([1, 4, 2, 3], state='on') - k._hw.vab_square_wave(3.,1) - k._hw.switch_mux([1, 4, 2, 3], state='off') - k._hw.calibrate_rx_bias() # electrodes 1 4 2 3 should be connected to a reference circuit - # 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() - k._hw.switch_mux([1, 4, 2, 3], state='on') - k._hw.vab_square_wave(3.,1) - k._hw.switch_mux([1, 4, 2, 3], state='off') - 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() - plot_exec_log('ohmpi/logs/exec.log') -change_config('../configs/config_default.py', verbose=False) \ No newline at end of file diff --git a/dev/test_fullwave.py b/dev/test_fullwave.py deleted file mode 100644 index 6d9eb03ca3b5b34a49ec4a484e01ee4b1636b6fa..0000000000000000000000000000000000000000 --- a/dev/test_fullwave.py +++ /dev/null @@ -1,28 +0,0 @@ -import numpy as np -import pandas as pd -import matplotlib.pyplot as plt -import os - -fnames = sorted(os.listdir('data')) -df = pd.read_csv('out.csv', engine='python') -df - -ct = df.columns[df.columns.str.match('t\d+')] -ci = df.columns[df.columns.str.match('i\d+')] -cu = df.columns[df.columns.str.match('u\d+')] - -fig, axs = plt.subplots(2, 1, sharex=True) -for i in range(df.shape[0]): - print(i) - data = np.c_[df.loc[i, ct], df.loc[i, ci], df.loc[i, cu]].astype(float) - inan = ~(np.isnan(data).any(1)) - label = ', '.join(df.loc[i, ['A', 'B', 'M', 'N']].astype(str).to_list()) - ax = axs[0] - ax.plot(data[inan,0], data[inan,1], '.-', label=label) - ax.set_ylabel('Current AB [mA]') - ax.legend() - ax = axs[1] - ax.plot(data[inan,0], data[inan,2], '.-', label=label) - ax.set_ylabel('Voltage MN [mV]') - ax.set_xlabel('Time [s]') -plt.show() diff --git a/dev/test_mb_2023_0_X.py b/dev/test_mb_2023_0_X.py deleted file mode 100644 index 67878d2fd4ab1d66a3ff2d6a1c944e44cdf48068..0000000000000000000000000000000000000000 --- a/dev/test_mb_2023_0_X.py +++ /dev/null @@ -1,29 +0,0 @@ -# import sys -# sys.path.extend(['/home/su530201/PycharmProjects/ohmpi_reversaal/OhmPi']) -from ohmpi.hardware_components.mb_2023_0_X import Tx -from ohmpi.hardware_components.mb_2023_0_X import Rx -from ohmpi.logging_setup import create_stdout_logger -import numpy as np - -exec_logger = create_stdout_logger(name='exec') -soh_logger = create_stdout_logger(name='soh') - -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) - -print(f'TX current: {tx.current:.3f} mA') -print(f'RX voltage: {rx.voltage:.3f} mV') - -tx.inject(state='on', polarity=1) -tx._adc_gain_auto() -rx._adc_gain_auto() -r = [] -for i in range(30): - r.append(rx.voltage/tx.current) - print(f'Resistance: {r[-1]:.3f}') -r = np.array(r) -print(f'Mean resistance: {np.mean(r):.3f} Ohms') -print(f'Resistance std: {np.std(r):.3f} Ohms') -print(f'Dev. {100. * np.std(r)/np.mean(r):.1} %') diff --git a/dev/test_3_mux_2024.py b/dev/test_mb_2023_3_mux_2024.py similarity index 97% rename from dev/test_3_mux_2024.py rename to dev/test_mb_2023_3_mux_2024.py index c928b087c6f95a556ca03ee000633287044bd829..1dff700581f78f3198ff07ed65e77898de7151d0 100644 --- a/dev/test_3_mux_2024.py +++ b/dev/test_mb_2023_3_mux_2024.py @@ -58,7 +58,7 @@ if within_ohmpi: #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 = (28, 25, 27, 26) + A, B, M, N = (1, 4, 2, 3) # 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') diff --git a/dev/test_mb_2024_1_mux_2024.py b/dev/test_mb_2024_1_mux_2024.py new file mode 100644 index 0000000000000000000000000000000000000000..509c923b3045e915e5edffcd8bbc0d145ac33310 --- /dev/null +++ b/dev/test_mb_2024_1_mux_2024.py @@ -0,0 +1,75 @@ +import time +from ohmpi.utils import change_config +from ohmpi.plots import plot_exec_log +import logging +change_config('../configs/config_mb_2024_1_mux_2024.py', verbose=False) +from ohmpi.hardware_components.mux_2024_0_X import Mux +from ohmpi.hardware_components import raspberry_pi as ctl_module +from ohmpi.config import HARDWARE_CONFIG +MUX_CONFIG = HARDWARE_CONFIG['mux'] + + +stand_alone_mux = False +part_of_hardware_system = False +within_ohmpi = True +# Stand alone mux +if stand_alone_mux: + mux_id = 'mux_00' + first = 24 + print(MUX_CONFIG) + MUX_CONFIG.update(HARDWARE_CONFIG['mux']['boards'][mux_id]) + MUX_CONFIG.update({'id': mux_id}) + MUX_CONFIG['ctl'] = ctl_module.Ctl() + mux = Mux(**MUX_CONFIG) + mux.switch_one(elec=1+first, role='M', state='on') + time.sleep(1) + mux.switch_one(elec=1+first, role='M', state='off') + mux.switch({'A': [1], 'B': [2], 'M': [3], 'N': [4]}, state='on') + time.sleep(2) + # mux.switch({'A': [1], 'B': [4], 'M': [2], 'N': [3]}, state='off') + mux.reset() + mux.test({'A': [i+first for i in range(1, 9)], 'B': [i+first for i in range(1, 9)], + 'M': [i+first for i in range(1, 9)], 'N': [i+first for i in range(1, 9)]}, activation_time=.1) + +# mux as part of a OhmPiHardware system +if part_of_hardware_system: + from ohmpi.hardware_system import OhmPiHardware + print('Starting test of mux as part of a OhmPiHardware system.') + + 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') + +if within_ohmpi: + from ohmpi.ohmpi import OhmPi + print('Starting test of mux within OhmPi.') + k = OhmPi() + #A, B, M, N = (32, 29, 31, 30) + k.reset_mux() + #k._hw.switch_mux([A, B, M, N], state='on') + #k._hw.vab_square_wave(12.,1., cycles=2) + #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 = (28, 25, 27, 26) + # 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_rho :.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) \ No newline at end of file diff --git a/dev/test_measure_with_mb_2023_0_X.py b/dev/test_measure_with_mb_2023_0_X.py deleted file mode 100644 index e20f4802e2398c9c939fdb2822ada152e89a3b61..0000000000000000000000000000000000000000 --- a/dev/test_measure_with_mb_2023_0_X.py +++ /dev/null @@ -1,53 +0,0 @@ -import numpy as np -import logging -import matplotlib.pyplot as plt -from ohmpi.utils import change_config -change_config('../configs/config_mb_2023_mux_2024.py', verbose=False) -from ohmpi.hardware_system import OhmPiHardware - -k = OhmPiHardware() -k.exec_logger.setLevel(logging.INFO) - -# Test _vab_pulse: -print('Testing positive _vab_pulse') -k._vab_pulse(vab=12, duration=1., sampling_rate=k.rx.sampling_rate, polarity=1) -r = k.readings[:,4]/k.readings[:,3] -print(f'Mean resistance: {np.mean(r):.3f} Ohms, Dev. {100*np.std(r)/np.mean(r):.1f} %') -print(f'sampling rate: {k.rx.sampling_rate:.1f} ms, mean sample spacing: {np.mean(np.diff(k.readings[:,0]))*1000.:.1f} ms') -print('\nTesting negative _vab_pulse') -k._vab_pulse(vab=12, duration=1., sampling_rate=k.rx.sampling_rate, polarity=-1) -r = k.readings[:,4]/k.readings[:,3] -print(f'Mean resistance: {np.mean(r):.3f} Ohms, Dev. {100*np.std(r)/np.mean(r):.1f} %') -print(f'sampling rate: {k.rx.sampling_rate:.1f} ms, mean sample spacing: {np.mean(np.diff(k.readings[:,0]))*1000.:.1f} ms') - -# Test vab_square_wave: -print('\n\nTesting vab_square_wave') -cycles=3 -cycle_length = 1. -k.vab_square_wave(vab=12, cycle_length=cycle_length, sampling_rate=k.rx.sampling_rate, cycles=cycles) -r = k.readings[:,4]/k.readings[:,3] -print(f'Mean resistance: {np.mean(r):.3f} Ohms, Dev. {100*np.std(r)/np.mean(r):.1f} %') -print(f'sampling rate: {k.rx.sampling_rate:.1f} ms, mean sample spacing: {np.mean(np.diff(k.readings[:,0]))*1000.:.1f} ms') -print(f'length of array: {len(r)}, expected length: {cycle_length*cycles*1000./k.rx.sampling_rate}') - -# Plot graphs -fig, ax = plt.subplots() -ax.plot(k.readings[:,0], k.readings[:,3], '-r', marker='.', label='iab') -ax.set_ylabel('Iab [mA]') -ax2 = ax.twinx() -ax2.plot(k.readings[:,0], k.readings[:,2]*k.readings[:,4], '-b', marker='.', label='vmn') -ax2.set_ylabel('Vmn [mV]') -fig.legend() -plt.show() - -# Compute resistances corrected for SP -print(f'SP: {k.sp} mV') -r = ((k.readings[:,4]-k.readings[:,2]*k.sp)/k.readings[:,3]) -print(f'Mean resistance with sp correction : {np.mean(r):.3f} Ohms, Dev. {100*np.std(r)/np.mean(r):.1f} %') -print('\nTesting with pulses') -r = [np.abs((k.pulses[i]['polarity']*k.pulses[i]['vmn']-k.sp)/k.pulses[i]['iab']) for i in k.pulses.keys()] -for i in range(len(r)): - print(f'Mean resistance with sp correction for pulse{i}: {np.mean(r[i]):.3f} Ohms, Dev. {100*np.std(r[i])/np.mean(r[i]):.1f} %') - -change_config('../configs/config_default.py', verbose=False) - diff --git a/dev/test_mux_2024.py b/dev/test_mux_2024.py deleted file mode 100644 index da950eb9ccabb20c8071678eaecd9a0c98f20c9a..0000000000000000000000000000000000000000 --- a/dev/test_mux_2024.py +++ /dev/null @@ -1,50 +0,0 @@ -import time -from ohmpi.utils import change_config -import logging -change_config('../configs/config_mb_2023_mux_2024.py', verbose=False) -from ohmpi.hardware_components.mux_2024_0_X import Mux, MUX_CONFIG -from ohmpi.hardware_components import raspberry_pi as ctl_module -# from ohmpi.config import HARDWARE_CONFIG - -stand_alone_mux = False # Testing hardware component alone -part_of_hardware_system = False # Testing hardware component as a part of the hardware system -within_ohmpi = True # Testing hardware component as a part of the hardware system through the ohmpi object -# Stand alone mux -if stand_alone_mux: - MUX_CONFIG['ctl'] = ctl_module.Ctl() - MUX_CONFIG['id'] = 'mux_1' - MUX_CONFIG['cabling'] = {(i+8, j) : ('mux_1', i) for j in ['A', 'B', 'M', 'N'] for i in range(1,9)} - mux = Mux(**MUX_CONFIG) - mux.switch_one(elec=9, role='M', state='on') - time.sleep(2) - mux.switch_one(elec=9, role='M', state='off') - mux.switch({'A': [9], 'B': [12], 'M': [10], 'N': [11]}, state='on') - time.sleep(8) - # mux.switch({'A': [1], 'B': [4], 'M': [2], 'N': [3]}, state='off') - mux.reset() - mux.test({'A': [9, 10, 11, 12, 13, 14, 15, 16], 'B': [9, 10, 11, 12, 13, 14, 15, 16], - 'M': [9, 10, 11, 12, 13, 14, 15, 16], 'N': [9, 10, 11, 12, 13, 14, 15, 16]}, activation_time=.1) - -# mux as part of a OhmPiHardware system -if part_of_hardware_system: - from ohmpi.hardware_system import OhmPiHardware - print('Starting test of mux as part of a OhmPiHardware system.') - - 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') - -if within_ohmpi: - from ohmpi.ohmpi import OhmPi - print('Starting test of mux within OhmPi.') - k = OhmPi() - k.switch_mux_on([1, 4, 2, 3]) - time.sleep(1.) - k.reset_mux() - -change_config('../configs/config_default.py', verbose=False) \ No newline at end of file