diff --git a/configs/config_mb_2023__1_mux_2024.py b/configs/config_mb_2023__1_mux_2024_4roles.py similarity index 100% rename from configs/config_mb_2023__1_mux_2024.py rename to configs/config_mb_2023__1_mux_2024_4roles.py diff --git a/configs/config_mb_2023__4_mux_2024_4roles.py b/configs/config_mb_2023__4_mux_2024_4roles.py new file mode 100644 index 0000000000000000000000000000000000000000..4d6b2f2e46c15f46b694d9e6c509e7f5abcefad9 --- /dev/null +++ b/configs/config_mb_2023__4_mux_2024_4roles.py @@ -0,0 +1,149 @@ +import logging +from ohmpi.utils import get_platform +from paho.mqtt.client import MQTTv31 # noqa + +_, 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 +} + +r_shunt = 2. +HARDWARE_CONFIG = { + 'ctl': {'model': 'raspberry_pi'}, + 'pwr': {'model': 'pwr_batt', 'voltage': 12., 'interface_name': 'none'}, + 'tx': {'model': 'mb_2023_0_X', + 'voltage_max': 50., # Maximum voltage supported by the TX board [V] + 'current_max': 4.80/(50*r_shunt), # Maximum voltage read by the current ADC on the TX board [A] + 'r_shunt': r_shunt, # 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 + 'sampling_rate': 50., # number of samples per second + 'interface_name': 'i2c', + }, + 'mux': {'boards': + {'mux_01': + {'model': 'mux_2024_0_X', + 'roles': ['A', 'B'], + 'electrodes': range(1, 17), + 'addr2': 'down', + 'addr1': 'down', + 'tca_address': None, + 'tca_channel': 0 + }, + 'mux_02': + {'model': 'mux_2024_0_X', + 'roles': ['A', 'B'], + 'electrodes': range(17, 33), + 'addr1': 'up', + 'addr2': 'dpwn', + 'tca_address': None, + 'tca_channel': 0 + }, + 'mux_03': + {'model': 'mux_2024_0_X', + 'roles': ['M', 'N'], + 'electrodes': range(1, 17), + 'tca_address': None, + 'tca_channel': 0, + 'addr1': 'down', + 'addr2': 'down', + 'interface_name': 'i2c'}, + 'mux_04': + {'model': 'mux_2024_0_X', + 'roles': ['M', 'N'], + 'electrodes': range(17, 33), + 'addr1': 'down', + 'addr2': 'up', + 'tca_address': None, + 'tca_channel': 0, + } + }, + 'default': {'interface_name': 'i2c_ext', + '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_dps5005.py b/configs/config_mb_2023_dps5005.py new file mode 100644 index 0000000000000000000000000000000000000000..53a5d77a665c84d07d3c10dc5989506a2d71e08e --- /dev/null +++ b/configs/config_mb_2023_dps5005.py @@ -0,0 +1,115 @@ +import logging +from ohmpi.utils import get_platform + +from paho.mqtt.client import MQTTv31 # noqa + +_, 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 +} + +r_shunt = 2. +HARDWARE_CONFIG = { + 'ctl': {'model': 'raspberry_pi'}, + 'pwr': {'model': 'pwr_batt', 'voltage': 12., 'interface_name': 'none'}, + 'tx': {'model': 'mb_2023_0_X', + 'voltage_max': 50., # Maximum voltage supported by the TX board [V] + 'current_max': 4.80/(50*r_shunt), # Maximum voltage read by the current ADC on the TX board [A] + 'r_shunt': r_shunt, # 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 + 'sampling_rate': 50., # number of samples per second + 'interface_name': 'i2c', + }, + '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': {}, + 'default': {} + } +} + +# SET THE LOGGING LEVELS, MQTT BROKERS AND MQTT OPTIONS ACCORDING TO YOUR NEEDS +# Execution logging configuration +EXEC_LOGGING_CONFIG = { + 'logging_level': logging.DEBUG, # TODO: set logging level back to 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_2024_0_2__1_mux_2024_2roles.py b/configs/config_mb_2024_0_2__1_mux_2024_2roles.py new file mode 100644 index 0000000000000000000000000000000000000000..e9069614900c2890a06f43eb98e277866eb0a814 --- /dev/null +++ b/configs/config_mb_2024_0_2__1_mux_2024_2roles.py @@ -0,0 +1,122 @@ +import logging +from ohmpi.utils import get_platform +from paho.mqtt.client import MQTTv31 # noqa + +_, 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 +} + +r_shunt = 2. +HARDWARE_CONFIG = { + 'ctl': {'model': 'raspberry_pi'}, + 'pwr': {'model': 'pwr_dps5005', 'voltage': 3., 'interface_name': 'modbus'}, + 'tx': {'model': 'mb_2024_0_2', + 'voltage_max': 50., # Maximum voltage supported by the TX board [V] + 'current_max': 4.80/(50*r_shunt), # Maximum voltage read by the current ADC on the TX board [A] + 'r_shunt': r_shunt, # Shunt resistance in Ohms + 'interface_name': 'i2c' + }, + 'rx': {'model': 'mb_2024_0_2', + 'latency': 0.010, # latency in seconds in continuous mode + 'sampling_rate': 50, # number of samples per second + 'interface_name': 'i2c' + }, + 'mux': {'boards': + {'mux_01': + {'model': 'mux_2024_0_X', + 'roles': ['A', 'B'], + 'electrodes': range(1, 17), + 'addr1': 'down', + 'addr2': 'up', + 'tca_address': None, + 'tca_channel': 0 + } + }, + 'default': {'interface_name': 'i2c_ext', + 'voltage_max': 50., + '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_2024_0_2__1_mux_2024_2roles_dps5005.py b/configs/config_mb_2024_0_2__1_mux_2024_2roles_dps5005.py new file mode 100644 index 0000000000000000000000000000000000000000..3cc87c29de2a87a3220b71d2a6c2a3505ccd04cf --- /dev/null +++ b/configs/config_mb_2024_0_2__1_mux_2024_2roles_dps5005.py @@ -0,0 +1,131 @@ +import logging +from ohmpi.utils import get_platform +from paho.mqtt.client import MQTTv31 # noqa + +_, 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 +} + +r_shunt = 2. +HARDWARE_CONFIG = { + 'ctl': {'model': 'raspberry_pi'}, + 'pwr': {'model': 'pwr_dps5005', 'voltage': 3., 'interface_name': 'modbus'}, + 'tx': {'model': 'mb_2024_0_2', + 'voltage_max': 50., # Maximum voltage supported by the TX board [V] + 'current_max': 4.80/(50*r_shunt), # Maximum voltage read by the current ADC on the TX board [A] + 'r_shunt': r_shunt, # Shunt resistance in Ohms + 'interface_name': 'i2c' + }, + 'rx': {'model': 'mb_2024_0_2', + 'latency': 0.010, # latency in seconds in continuous mode + 'sampling_rate': 50, # number of samples per second + 'interface_name': 'i2c' + }, + 'mux': {'boards': + {'mux_01': + {'model': 'mux_2024_0_X', + 'roles': ['A', 'B'], + 'electrodes': range(1, 17), + 'addr1': 'down', + 'addr2': 'up', + 'tca_address': None, + 'tca_channel': 0 + }, + 'mux_02': + {'model': 'mux_2024_0_X', + 'roles': ['M', 'N'], + 'electrodes': range(1, 17), + 'addr1': 'up', + 'addr2': 'down', + 'tca_address': None, + 'tca_channel': 0 + } + }, + 'default': {'interface_name': 'i2c_ext', + 'voltage_max': 50., + '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_2024_0_2__1_mux_2024.py b/configs/config_mb_2024_0_2__1_mux_2024_4roles.py similarity index 100% rename from configs/config_mb_2024_0_2__1_mux_2024.py rename to configs/config_mb_2024_0_2__1_mux_2024_4roles.py diff --git a/configs/config_mb_2024_0_2__1_mux_2024_dps5005.py b/configs/config_mb_2024_0_2__1_mux_2024_4roles_dps5005.py similarity index 100% rename from configs/config_mb_2024_0_2__1_mux_2024_dps5005.py rename to configs/config_mb_2024_0_2__1_mux_2024_4roles_dps5005.py diff --git a/configs/config_mb_2024_0_2__3_mux_2024_2roles_dps5005.py b/configs/config_mb_2024_0_2__3_mux_2024_2roles_dps5005.py new file mode 100644 index 0000000000000000000000000000000000000000..b566a8bceb4a0701a58164f73abc0164be84ce05 --- /dev/null +++ b/configs/config_mb_2024_0_2__3_mux_2024_2roles_dps5005.py @@ -0,0 +1,149 @@ +import logging +from ohmpi.utils import get_platform +from paho.mqtt.client import MQTTv31 # noqa + +_, 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 +} + +r_shunt = 2. +HARDWARE_CONFIG = { + 'ctl': {'model': 'raspberry_pi'}, + 'pwr': {'model': 'pwr_dps5005', 'voltage': 3., 'interface_name': 'modbus'}, + 'tx': {'model': 'mb_2024_0_2', + 'voltage_max': 50., # Maximum voltage supported by the TX board [V] + 'current_max': 4.80/(50*r_shunt), # Maximum voltage read by the current ADC on the TX board [A] + 'r_shunt': r_shunt, # Shunt resistance in Ohms + 'interface_name': 'i2c' + }, + 'rx': {'model': 'mb_2024_0_2', + 'latency': 0.010, # latency in seconds in continuous mode + 'sampling_rate': 50, # number of samples per second + 'interface_name': 'i2c' + }, + 'mux': {'boards': + {'mux_01': + {'model': 'mux_2024_0_X', + 'roles': ['A', 'B'], + 'electrodes': range(1, 17), + 'addr1': 'up', + 'addr2': 'up', + 'tca_address': None, + 'tca_channel': 0 + }, + 'mux_02': + {'model': 'mux_2024_0_X', + 'roles': ['M', 'N'], + 'electrodes': range(1, 17), + 'addr1': 'down', + 'addr2': 'up', + 'tca_address': None, + 'tca_channel': 0 + }, + 'mux_03': + {'model': 'mux_2024_0_X', + 'roles': ['A', 'B'], + 'electrodes': range(17, 33), + 'tca_address': None, + 'tca_channel': 0, + 'addr1': 'up', + 'addr2': 'down', + 'interface_name': 'i2c'}, + 'mux_04': + {'model': 'mux_2024_0_X', + 'roles': ['M', 'N'], + 'electrodes': range(17, 33), + 'addr1': 'down', + 'addr2': 'down', + 'tca_address': None, + 'tca_channel': 0, + } + }, + 'default': {'interface_name': 'i2c_ext', + 'voltage_max': 50., + '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_2024_0_2__3_mux_2024_dps5005.py b/configs/config_mb_2024_0_2__3_mux_2024_4roles_dps5005.py similarity index 100% rename from configs/config_mb_2024_0_2__3_mux_2024_dps5005.py rename to configs/config_mb_2024_0_2__3_mux_2024_4roles_dps5005.py diff --git a/configs/config_mb_2024_0_2__4_mux_2024_4roles.py b/configs/config_mb_2024_0_2__4_mux_2024_4roles.py new file mode 100644 index 0000000000000000000000000000000000000000..60a7bd643297eb805f2a14fbdb21ea208f74eaa9 --- /dev/null +++ b/configs/config_mb_2024_0_2__4_mux_2024_4roles.py @@ -0,0 +1,146 @@ +import logging +from ohmpi.utils import get_platform +from paho.mqtt.client import MQTTv31 # noqa + +_, 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 +} +r_shunt = 2. +HARDWARE_CONFIG = { + 'ctl': {'model': 'raspberry_pi'}, + 'pwr': {'model': 'pwr_dps5005', 'voltage': 3., 'interface_name': 'modbus'}, + 'tx': {'model': 'mb_2024_0_2', + 'voltage_max': 50., # Maximum voltage supported by the TX board [V] + 'current_max': 4.8/(50*r_shunt), # Maximum voltage read by the current ADC on the TX board [A] + 'r_shunt': r_shunt, # Shunt resistance in Ohms + 'interface_name': 'i2c', + 'vmn_hardware_offset': 2501. + }, + 'rx': {'model': 'mb_2024_0_2', + 'latency': 0.010, # latency in seconds in continuous mode + 'sampling_rate': 50, # number of samples per second + 'interface_name': 'i2c' + }, + 'mux': {'boards': + {'mux_01': + {'model': 'mux_2024_0_X', + 'electrodes': range(1, 9), + 'roles': ['A', 'B', 'M', 'N'], + 'addr1': 'up', + 'addr2': 'up', + 'tca_address': None, + 'tca_channel': 0}, + 'mux_02': + {'model': 'mux_2024_0_X', + 'electrodes': range(9, 17), + 'roles': ['A', 'B', 'M', 'N'], + 'addr1': 'down', + 'addr2': 'up', + 'tca_address': None, + 'tca_channel': 0}, + 'mux_03': + {'model': 'mux_2024_0_X', + 'electrodes': range(17, 25), + 'roles': ['A', 'B', 'M', 'N'], + 'addr1': 'up', + 'addr2': 'down', + 'tca_address': None, + 'tca_channel': 0}, + 'mux_04': + {'model': 'mux_2024_0_X', + 'electrodes': range(25, 33), + 'roles': ['A', 'B', 'M', 'N'], + 'addr1': 'down', + 'addr2': 'down', + 'tca_address': None, + 'tca_channel': 0}, + }, + 'default': {'interface_name': 'i2c_ext', + 'voltage_max': 50., + '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_2024_0_2_dps5005.py b/configs/config_mb_2024_0_2_dps5005.py new file mode 100644 index 0000000000000000000000000000000000000000..e0516838ee69444ee7862fd5d42a9337a99df8f5 --- /dev/null +++ b/configs/config_mb_2024_0_2_dps5005.py @@ -0,0 +1,110 @@ +import logging +from ohmpi.utils import get_platform +from paho.mqtt.client import MQTTv31 # noqa + +_, 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 +} + +r_shunt = 2. +HARDWARE_CONFIG = { + 'ctl': {'model': 'raspberry_pi'}, + 'pwr': {'model': 'pwr_batt', 'voltage': 12., 'interface_name': 'none'}, + 'tx': {'model': 'mb_2024_0_2', + 'voltage_max': 50., # Maximum voltage supported by the TX board [V] + 'current_max': 4.80/(50*r_shunt), # Maximum voltage read by the current ADC on the TX board [A] + 'r_shunt': r_shunt, # Shunt resistance in Ohms + 'interface_name': 'i2c' + }, + 'rx': {'model': 'mb_2024_0_2', + 'latency': 0.010, # latency in seconds in continuous mode + 'sampling_rate': 50, # number of samples per second + 'interface_name': 'i2c' + }, + 'mux': {'boards': {}, + 'default': {} + } + } + +# 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': 1048576, + '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/dev/test_mb_2024_1_mux_2024.py b/dev/test_mb_2024_1_mux_2024.py index 2d086183953fa43503ca156c11ad7b6cfa19d09f..95b21f4fae0bee33863fca7d4b538d39665ad006 100644 --- a/dev/test_mb_2024_1_mux_2024.py +++ b/dev/test_mb_2024_1_mux_2024.py @@ -1,7 +1,7 @@ import matplotlib matplotlib.use('TkAgg') from ohmpi.utils import change_config -change_config('../configs/config_mb_2024_0_2__1_mux_2024_dps5005.py', verbose=False) +change_config('../configs/config_mb_2024_0_2__1_mux_2024_4roles_dps5005.py', verbose=False) import importlib import time import logging diff --git a/dev/test_mb_2024_3_mux_2024.py b/dev/test_mb_2024_3_mux_2024.py index 5d3a5e748cadb832e1e34626aa285f8719525ee9..c71984694f0de520a8d0199f64578d379cdcdf9e 100644 --- a/dev/test_mb_2024_3_mux_2024.py +++ b/dev/test_mb_2024_3_mux_2024.py @@ -1,7 +1,7 @@ import matplotlib matplotlib.use('TkAgg') from ohmpi.utils import change_config -change_config('../configs/config_mb_2024_0_2__3_mux_2024_dps5005.py', verbose=False) +change_config('../configs/config_mb_2024_0_2__3_mux_2024_4roles_dps5005.py', verbose=False) import importlib import time import logging diff --git a/examples/example_sequence_inv.py b/examples/example_sequence_inv.py new file mode 100644 index 0000000000000000000000000000000000000000..245ddf5939b8e853423063bc1face73ca8ff79a9 --- /dev/null +++ b/examples/example_sequence_inv.py @@ -0,0 +1,48 @@ +import warnings +import os +import numpy as np +import time +import matplotlib.pyplot as plt +warnings.filterwarnings('ignore') +os.chdir("/home/pi/OhmPi") +from ohmpi.ohmpi import OhmPi + +### Define object from class OhmPi +k = OhmPi() +print('update parameters') +### Update settings if needed +k.update_settings({"injection_duration":0.250}) +k.update_settings({"nb_stack":1}) +k.update_settings({"nbr_electrode":64}) +k.update_settings({"voltage_max":50}) +#load sequence +k.load_sequence('sequences/ABMN.txt') +#Run contact resistance check +k.rs_check(tx_volt=2) +# ### Run sequence +#k.run_sequence(tx_volt =5. , strategy = 'vmax', dutycycle=0.95, vab_max = 50.,) +print('end') +#inversion +xzv = k.run_inversion(['/home/pi/OhmPi/data/measurements_20240127T085200.csv'], reg_mode=0, elec_spacing = 1.) +#plot +fig, axs = plt.subplots(len(xzv), 1, sharex=True, sharey=True, figsize=(10, 3)) +axs = [axs] if len(xzv) == 1 else axs + +for i, dic in enumerate(xzv): + ax = axs[i] + x, z = np.meshgrid(dic['x'], dic['z']) + #cax = ax.contourf(x, z, np.log10(dic['rho']),cmap='jet') + cax = ax.pcolormesh(x, z, np.log10(dic['rho']),cmap='jet') + fig.colorbar(cax, ax=ax, label=r'$\log_{10}(\rho)$ [$\Omega$.m]') + +a=np.zeros((16,2)) +esp=0 +for i in range(0,16): + a[i,0]=esp + esp=esp+0.03 + +ax.plot(a[:,0],a[:,1],'*r') + +plt.show(block=True) + + diff --git a/examples/example_simple_measurement.py b/examples/example_simple_measurement.py index 6ad76c50e3f24a9644f45b97f80e7bcce3cfe3a6..0ebfc3aec9d62a1832dd1ecfe08f939642e5d38f 100644 --- a/examples/example_simple_measurement.py +++ b/examples/example_simple_measurement.py @@ -2,20 +2,20 @@ import os import numpy as np import time os.chdir("/home/pi/OhmPi") -from ohmpi import OhmPi +from ohmpi.ohmpi import OhmPi -### Define object from class OhmPi +# Define object from class OhmPi k = OhmPi() -### Update settings if needed +# Update settings if needed k.update_settings({"injection_duration":0.2}) -### Set or load sequence -k.sequence = np.array([[1,2,3,4]]) #Â set numpy array of shape (n,4) +# Set or load sequence +k.sequence = np.array([[1,2,3,4]]) # set numpy array of shape (n,4) # k.load_sequence('sequences/ABMN.txt') # load sequence from a local file -### Run contact resistance check -#Â k.rs_check() +# Run contact resistance check +# k.rs_check() -### Run sequence +# Run sequence k.run_sequence() diff --git a/generate_preset_configs.py b/generate_preset_configs.py new file mode 100644 index 0000000000000000000000000000000000000000..9efef9d8c1bd3dd34af50914f3aa14a0926ae51a --- /dev/null +++ b/generate_preset_configs.py @@ -0,0 +1,283 @@ +configs_to_generate = ['config_mb_2023.py', 'config_mb_2023__4_mux_2023.py', + 'config_mb_2023__1_mux_2024_4roles.py', 'config_mb_2023__2_mux_2024_4roles.py', + 'config_mb_2023__3_mux_2024_4roles.py', 'config_mb_2023__4_mux_2024_4roles.py', + 'config_mb_2023__2_mux_2024_2roles.py', 'config_mb_2023__4_mux_2024_2roles.py', + 'config_mb_2024_0_2.py', 'config_mb_2024_0_2_dps5005.py', + 'config_mb_2024_0_2__4_mux_2023.py', 'config_mb_2024_0_2__4_mux_2023_dps5005.py', + 'config_mb_2024_0_2__1_mux_2024_4roles.py', 'config_mb_2024_0_2__1_mux_2024_4roles_dps5005.py', + 'config_mb_2024_0_2__2_mux_2024_4roles.py', 'config_mb_2024_0_2__2_mux_2024_4roles_dps5005.py', + 'config_mb_2024_0_2__2_mux_2024_2roles.py', 'config_mb_2024_0_2__2_mux_2024_2roles_dps5005.py', + 'config_mb_2024_0_2__3_mux_2024_4roles.py', 'config_mb_2024_0_2__3_mux_2024_4roles_dps5005.py', + 'config_mb_2024_0_2__4_mux_2024_4roles.py', 'config_mb_2024_0_2__4_mux_2024_4roles_dps5005.py', + 'config_mb_2024_0_2__4_mux_2024_2roles.py', 'config_mb_2024_0_2__4_mux_2024_2roles_dps5005.py' + ] + +header = """import logging +from ohmpi.utils import get_platform +from paho.mqtt.client import MQTTv31 # noqa + +_, 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 +} + +r_shunt = 2. + +# default properties of system components that will be +# overwritten by properties defined in each the board dict below. +# if bounds are 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 + +HARDWARE_CONFIG = { + 'ctl': {'model': 'raspberry_pi'}, + 'pwr': """ + +r_shunt = 2. +options = {'pwr': {'battery': """{'model': 'pwr_batt', 'voltage': 12., 'interface_name': 'none'},""", + 'dps5005': """{'model': 'pwr_dps5005', 'voltage': 3., 'interface_name': 'modbus'},""" + }, + 'mb': {'mb_2024_0_2': {'tx': """{'model': 'mb_2024_0_2', + 'voltage_max': 50., # Maximum voltage supported by the TX board [V] + 'current_max': 4.80/(50*r_shunt), # Maximum voltage read by the current ADC on the TX board [A] + 'r_shunt': r_shunt, # Shunt resistance in Ohms + 'interface_name': 'i2c' + }""", + 'rx': """"{'model': 'mb_2024_0_2', + 'latency': 0.010, # latency in seconds in continuous mode + 'sampling_rate': 50, # number of samples per second + 'interface_name': 'i2c' + }"""}, + 'mb_2023': {'tx': """{'model': 'mb_2023_0_X', + 'voltage_max': 50., # Maximum voltage supported by the TX board [V] + 'current_max': 4.80/(50*r_shunt), # Maximum voltage read by the current ADC on the TX board [A] + 'r_shunt': r_shunt, # 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 + 'sampling_rate': 50., # number of samples per second + 'interface_name': 'i2c', + }"""} + }, + 'mux': {'mux_2023': + [""" 'mux_A': + {'model': 'mux_2023_0_X', + 'mux_tca_address': 0x70, + 'roles': 'A', + 'electrodes': range(1, 65), + },""", + """\n 'mux_B': + {'model': 'mux_2023_0_X', + 'mux_tca_address': 0x71, + 'roles': 'B', + 'electrodes': range(1, 65), + },""", + """\n 'mux_M': + {'model': 'mux_2023_0_X', + 'mux_tca_address': 0x72, + 'roles': 'M', + 'electrodes': range(1, 65), + },""", + """\n 'mux_N': + {'model': 'mux_2023_0_X', + 'mux_tca_address': 0x73, + 'roles': 'N', + 'electrodes': range(1, 65), + }"""], + 'mux_2024_2roles': + [""" 'mux_01': + {'model': 'mux_2024_0_X', + 'roles': ['A', 'B'], + 'electrodes': range(1, 17), + 'addr1': 'down', + 'addr2': 'up', + 'tca_address': None, + 'tca_channel': 0, + },""", + """\n 'mux_02': + {'model': 'mux_2024_0_X', + 'roles': ['M', 'N'], + 'electrodes': range(1, 17), + 'addr1': 'up', + 'addr2': 'down', + 'tca_address': None, + 'tca_channel': 0, + },""", + """\n 'mux_03': + {'model': 'mux_2024_0_X', + 'roles': ['A', 'B'], + 'electrodes': range(17, 33), + 'addr1': 'up', + 'addr2': 'down', + 'tca_address': None, + 'tca_channel': 0,},""", + """\n 'mux_04': + {'model': 'mux_2024_0_X', + 'roles': ['M', 'N'], + 'electrodes': range(17, 33), + 'addr1': 'down', + 'addr2': 'down', + 'tca_address': None, + 'tca_channel': 0, + }"""], + 'mux_2024_4roles': [ + """ {'mux_01': + {'model': 'mux_2024_0_X', + 'electrodes': range(1, 9), + 'roles': ['A', 'B', 'M', 'N'], + 'addr1': 'up', + 'addr2': 'up', + 'tca_address': None, + 'tca_channel': 0,},""", + """\n 'mux_02': + {'model': 'mux_2024_0_X', + 'electrodes': range(9, 17), + 'roles': ['A', 'B', 'M', 'N'], + 'addr1': 'down', + 'addr2': 'up', + 'tca_address': None, + 'tca_channel': 0,},""", + """\n 'mux_03': + {'model': 'mux_2024_0_X', + 'electrodes': range(17, 25), + 'roles': ['A', 'B', 'M', 'N'], + 'addr1': 'up', + 'addr2': 'down', + 'tca_address': None, + 'tca_channel': 0,},""", + """\n 'mux_04': + {'model': 'mux_2024_0_X', + 'electrodes': range(25, 33), + 'roles': ['A', 'B', 'M', 'N'], + 'addr1': 'down', + 'addr2': 'down', + 'tca_address': None, + 'tca_channel': 0,},"""] + } + } +mux_footer = {'mb_2023': """\n }, + 'default': {'interface_name': 'i2c', + 'voltage_max': 50., + 'current_max': 3.} + }\n}\n""", + 'mb_2024_0_2': """\n }, + 'default': {'interface_name': 'i2c_ext', + 'voltage_max': 50., + 'current_max': 3.} + }\n}\n"""} + +footer = """# 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' +} +""" + +for mb, v_mb in options['mb'].items(): + for n in range(0, 5): + for mux, v_mux in options['mux'].items(): + for pwr, v_pwr in options['pwr'].items(): + config_filename = f'config_{mb}' + if n > 0: + config_filename += f'__{n}_{mux}' + if pwr != 'battery': + config_filename += f'_{pwr}' + config_filename += '.py' + if config_filename in configs_to_generate: + s = header + s += v_pwr + s += f"\n 'tx': {v_mb['tx']},\n 'rx': {v_mb['rx']},\n" + if n > 0: + s += """ 'mux': {'boards':\n""" + for i in range(n): + print(n, i) + s += v_mux[i] + s += mux_footer[mb] + else: + s = s + """ 'mux': {'boards': {}, + 'default': {} + }\n}""" + '\n' + + s += footer + print(f'*** Preparing {config_filename} ***') + print(f'\n{s}') + with open(f'tmp_to_be_deleted/{config_filename}', mode='wt') as config_file: + config_file.write(s) + else: + print(f'### skipping {config_filename} ###') diff --git a/ohmpi/ABMN.txt b/ohmpi/ABMN.txt deleted file mode 100644 index 840667b5356192590f7517ce8d21b80b874ed643..0000000000000000000000000000000000000000 --- a/ohmpi/ABMN.txt +++ /dev/null @@ -1,100 +0,0 @@ -1 16 6 11 -1 15 6 10 -1 13 5 9 -1 16 7 10 -1 14 6 9 -1 12 5 8 -1 10 4 7 -1 15 7 9 -1 13 6 8 -1 11 5 7 -1 9 4 6 -1 7 3 5 -1 12 6 7 -1 10 5 6 -1 8 4 5 -1 6 3 4 -1 4 2 3 -2 16 7 11 -2 14 6 10 -2 15 7 10 -2 13 6 9 -2 11 5 8 -2 16 8 10 -2 14 7 9 -2 12 6 8 -2 10 5 7 -2 8 4 6 -2 13 7 8 -2 11 6 7 -2 9 5 6 -2 7 4 5 -2 5 3 4 -3 15 7 11 -3 16 8 11 -3 14 7 10 -3 12 6 9 -3 15 8 10 -3 13 7 9 -3 11 6 8 -3 9 5 7 -3 14 8 9 -3 12 7 8 -3 10 6 7 -3 8 5 6 -3 6 4 5 -4 16 8 12 -4 15 8 11 -4 13 7 10 -4 16 9 11 -4 14 8 10 -4 12 7 9 -4 10 6 8 -4 15 9 10 -4 13 8 9 -4 11 7 8 -4 9 6 7 -4 7 5 6 -5 16 9 12 -5 14 8 11 -5 15 9 11 -5 13 8 10 -5 11 7 9 -5 16 10 11 -5 14 9 10 -5 12 8 9 -5 10 7 8 -5 8 6 7 -6 15 9 12 -6 16 10 12 -6 14 9 11 -6 12 8 10 -6 15 10 11 -6 13 9 10 -6 11 8 9 -6 9 7 8 -7 16 10 13 -7 15 10 12 -7 13 9 11 -7 16 11 12 -7 14 10 11 -7 12 9 10 -7 10 8 9 -8 16 11 13 -8 14 10 12 -8 15 11 12 -8 13 10 11 -8 11 9 10 -9 15 11 13 -9 16 12 13 -9 14 11 12 -9 12 10 11 -10 16 12 14 -10 15 12 13 -10 13 11 12 -11 16 13 14 -11 14 12 13 -12 15 13 14 -13 16 14 15 - - diff --git a/ohmpi/ABMN2.txt b/ohmpi/ABMN2.txt deleted file mode 100644 index cb0d6c084c836bbc41e1770bf6188b73be4d0407..0000000000000000000000000000000000000000 --- a/ohmpi/ABMN2.txt +++ /dev/null @@ -1,10 +0,0 @@ -1 16 6 11 -1 15 6 10 -1 13 5 9 -1 16 7 10 -1 14 6 9 -1 12 5 8 -1 10 4 7 -1 15 7 9 -1 13 6 8 -1 11 5 7 \ No newline at end of file diff --git a/ohmpi/config.py b/ohmpi/config.py index d4cad9f9851bbc5f283ff02f6430e2b44a6a20b4..60a7bd643297eb805f2a14fbdb21ea208f74eaa9 100644 --- a/ohmpi/config.py +++ b/ohmpi/config.py @@ -15,16 +15,16 @@ OHMPI_CONFIG = { 'id': ohmpi_id, # Unique identifier of the OhmPi board (string) 'settings': 'ohmpi_settings.json', # INSERT YOUR FAVORITE SETTINGS FILE HERE } - r_shunt = 2. HARDWARE_CONFIG = { 'ctl': {'model': 'raspberry_pi'}, 'pwr': {'model': 'pwr_dps5005', 'voltage': 3., 'interface_name': 'modbus'}, 'tx': {'model': 'mb_2024_0_2', 'voltage_max': 50., # Maximum voltage supported by the TX board [V] - 'current_max': 4.80/(50*r_shunt), # Maximum voltage read by the current ADC on the TX board [A] + 'current_max': 4.8/(50*r_shunt), # Maximum voltage read by the current ADC on the TX board [A] 'r_shunt': r_shunt, # Shunt resistance in Ohms - 'interface_name': 'i2c' + 'interface_name': 'i2c', + 'vmn_hardware_offset': 2501. }, 'rx': {'model': 'mb_2024_0_2', 'latency': 0.010, # latency in seconds in continuous mode @@ -32,34 +32,43 @@ HARDWARE_CONFIG = { 'interface_name': 'i2c' }, 'mux': {'boards': - {'mux_A': - {'model': 'mux_2023_0_X', - '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': 'mux_2023_0_X', - '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': 'mux_2023_0_X', - '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': 'mux_2023_0_X', - '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.}, + {'mux_01': + {'model': 'mux_2024_0_X', + 'electrodes': range(1, 9), + 'roles': ['A', 'B', 'M', 'N'], + 'addr1': 'up', + 'addr2': 'up', + 'tca_address': None, + 'tca_channel': 0}, + 'mux_02': + {'model': 'mux_2024_0_X', + 'electrodes': range(9, 17), + 'roles': ['A', 'B', 'M', 'N'], + 'addr1': 'down', + 'addr2': 'up', + 'tca_address': None, + 'tca_channel': 0}, + 'mux_03': + {'model': 'mux_2024_0_X', + 'electrodes': range(17, 25), + 'roles': ['A', 'B', 'M', 'N'], + 'addr1': 'up', + 'addr2': 'down', + 'tca_address': None, + 'tca_channel': 0}, + 'mux_04': + {'model': 'mux_2024_0_X', + 'electrodes': range(25, 33), + 'roles': ['A', 'B', 'M', 'N'], + 'addr1': 'down', + 'addr2': 'down', + 'tca_address': None, + 'tca_channel': 0}, }, 'default': {'interface_name': 'i2c_ext', - 'voltage_max': 100., - 'current_max': 3.} + 'voltage_max': 50., + 'current_max': 3. + } } } diff --git a/setup_config.py b/setup_config.py index 209abbf788b08cfeb7ee845188f99d32111290ab..7f9a391dba4472593c5f716b5aad2d7e78eccd2e 100644 --- a/setup_config.py +++ b/setup_config.py @@ -1,5 +1,11 @@ +import os +import shutil -print('This assistent helps you configure a basic system with a measurement board and from 0 to 4 mux of the same type. For more complex configuration with multiple mux of different types, please have a look in the configs/ folder.') +check_r_shunt = True +check_jumpers_msg = False +print('This assistant helps you configure a basic system with a measurement board and from 0 to 4 mux of the same type.' + '\nFor more complex configurations including a combination of mux boards with different types or roles, ' + 'please have a look in the configs folder for examples and write your customized configuration file.') mb = None while True: @@ -18,6 +24,15 @@ while True: else: mux = input('Choose a mux boards: [v2023/v2024]: ') +roles = None +if mux == 'v2024': + while True: + if roles in ['2roles', '4roles']: + break + else: + roles = input('How are your mux boards configured: [2roles/4roles]: ') + check_jumpers_msg = True + nb_mux = None while True: if nb_mux in ['0', '1', '2', '3', '4']: @@ -32,16 +47,46 @@ while True: else: pwr = input('Tx power: [battery/dps5005]:') -config = 'config_mb_' + mb[1:] + '_' + nb_mux + '_mux_' + mux[1:] + '.py' +config = ('config_mb_' + mb[1:] + '_' + nb_mux + '_mux_' + mux[1:]) +if roles is not None: + config = (config + '_' + roles + '.py') +else: + config = (config + '.py') + if pwr != 'battery': config = config.replace('.py', '_' + pwr + '.py') print('Using this configuration: ' + config) -import os -import shutil if os.path.exists('configs/' + config): shutil.copyfile('configs/' + config, 'ohmpi/config.py') + from ohmpi.config import HARDWARE_CONFIG, r_shunt, ohmpi_id + print(f'Your configuration has been set. Your OhmPi id is set to {ohmpi_id}.') + print('You should now carefully verify that the configuration file fits your hardware setup.\n') + k = 1 + if check_r_shunt: + print(f'{k}. Check that the value of the shunt resistor value is {r_shunt} Ohm as stated in the config file.') + k += 1 + if check_jumpers_msg: + print(f'\n{k}. Make sure to check that all your mux boards {mux} are configured in {roles} and that' + ' the jumpers are set as stated below:') + for mux, c in HARDWARE_CONFIG['mux']['boards'].items(): + print(f' Mux board {mux}: jumper addr1: {c["addr1"]},\t jumper addr2: {c["addr2"]}') + k += 1 + print(f'\n{k}. If you experience problems while starting or operation your OhmPi, analyse the logs and/or try ' + f'setting your the loggers "logging_level" to logging.DEBUG.') + k +=1 + + # print('\n' + '_'*100) + # with open('ohmpi/config.py', mode='rt') as f: + # for line in f.readlines(): + # print(line, end='') + # print('\n'+'_'*100) + print('\n'+'*' * 93) + print('*** You may customize the configuration of your OhmPi by editing the ohmpi/config.py file ***') + print('*** Make sure you understand what you are doing to avoid damaging to your system ***') + print('*' * 93) + else: - print('configuration not found') + print('Error: configuration not found')