From 48326ecf30341a526f0e7dcf6ea6f16fdf978eb2 Mon Sep 17 00:00:00 2001 From: su530201 <olivier.kaufmann@umons.ac.be> Date: Mon, 28 Aug 2023 10:25:44 +0200 Subject: [PATCH] Updates configs --- configs/config_mb_2023_2_mux_2024.py | 4 +- configs/config_mb_2023_4_mux_2023.py | 10 +- configs/config_mb_2023_mux_2024.py | 2 +- configs/config_mb_2023_mux_2024_2_roles_AB.py | 122 ++++++++++++++++++ configs/config_mb_2023_mux_2024_2_roles_MN.py | 122 ++++++++++++++++++ ohmpi/hardware_components/mux_2024_rev_0_0.py | 4 +- ohmpi/ohmpi.py | 2 +- 7 files changed, 255 insertions(+), 11 deletions(-) create mode 100644 configs/config_mb_2023_mux_2024_2_roles_AB.py create mode 100644 configs/config_mb_2023_mux_2024_2_roles_MN.py diff --git a/configs/config_mb_2023_2_mux_2024.py b/configs/config_mb_2023_2_mux_2024.py index dc3a5f00..7146a1b4 100644 --- a/configs/config_mb_2023_2_mux_2024.py +++ b/configs/config_mb_2023_2_mux_2024.py @@ -28,8 +28,8 @@ HARDWARE_CONFIG = { }, 'rx': {'model': 'ohmpi_card_3_15', 'coef_p2': 2.50, # slope for conversion for ADS, measurement in V/V - 'latency': 0.010 # latency in seconds in continuous mode - # 'nb_samples': 20, # Max value 10 # was named integer before... + '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 diff --git a/configs/config_mb_2023_4_mux_2023.py b/configs/config_mb_2023_4_mux_2023.py index 20f11d32..6546b118 100644 --- a/configs/config_mb_2023_4_mux_2023.py +++ b/configs/config_mb_2023_4_mux_2023.py @@ -45,19 +45,19 @@ HARDWARE_CONFIG = { '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.} + 'voltage_max': 12.}, 'mux_3': {'model': 'mux_2023_rev_0_0', # 'ohmpi_i2c_mux64_v1.01', 'tca_address': 0x72, 'roles': {'M': 'X'}, - 'cabling': {(i, j): ('mux_2', i) for j in ['M'] for i in range(1, 65)}, - 'voltage_max': 12.} + 'cabling': {(i, j): ('mux_3', i) for j in ['M'] for i in range(1, 65)}, + 'voltage_max': 12.}, 'mux_4': {'model': 'mux_2023_rev_0_0', # 'ohmpi_i2c_mux64_v1.01', 'tca_address': 0x73, 'roles': {'N': 'X'}, - 'cabling': {(i, j): ('mux_2', i) for j in ['N'] for i in range(1, 65)}, - 'voltage_max': 12.} + 'cabling': {(i, j): ('mux_4', i) for j in ['N'] for i in range(1, 65)}, + 'voltage_max': 12.}, }, 'default': {'voltage_max': 100., 'current_max': 3.} diff --git a/configs/config_mb_2023_mux_2024.py b/configs/config_mb_2023_mux_2024.py index e514c59f..186729ad 100644 --- a/configs/config_mb_2023_mux_2024.py +++ b/configs/config_mb_2023_mux_2024.py @@ -42,7 +42,7 @@ HARDWARE_CONFIG = { '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'}, + 'roles' : {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'}, 'voltage_max': 12. }}, 'default': {'voltage_max': 100., 'current_max': 3.}} diff --git a/configs/config_mb_2023_mux_2024_2_roles_AB.py b/configs/config_mb_2023_mux_2024_2_roles_AB.py new file mode 100644 index 00000000..cab686fe --- /dev/null +++ b/configs/config_mb_2023_mux_2024_2_roles_AB.py @@ -0,0 +1,122 @@ +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_i2c' + }, + 'pwr': {'model' : 'pwr_batt', 'voltage': 12.}, + 'tx' : {'model' : 'ohmpi_card_3_15', + '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': 'ohmpi_card_3_15', + '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_rev_0_0', # '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'}, + '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_2_roles_MN.py b/configs/config_mb_2023_mux_2024_2_roles_MN.py new file mode 100644 index 00000000..7ca25dec --- /dev/null +++ b/configs/config_mb_2023_mux_2024_2_roles_MN.py @@ -0,0 +1,122 @@ +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_i2c' + }, + 'pwr': {'model' : 'pwr_batt', 'voltage': 12.}, + 'tx' : {'model' : 'ohmpi_card_3_15', + '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': 'ohmpi_card_3_15', + '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_rev_0_0', # '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' : {'M': 'X', 'N': 'Y'}, + '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/ohmpi/hardware_components/mux_2024_rev_0_0.py b/ohmpi/hardware_components/mux_2024_rev_0_0.py index 250a5852..bca50f76 100644 --- a/ohmpi/hardware_components/mux_2024_rev_0_0.py +++ b/ohmpi/hardware_components/mux_2024_rev_0_0.py @@ -30,7 +30,7 @@ inner_cabling = {'4_roles' : {(1, 'X'): {'MCP': 0, 'MCP_GPIO': 0}, (1, 'Y'): {'M (6, 'XX'): {'MCP': 1, 'MCP_GPIO': 2}, (6, 'YY'): {'MCP': 1, 'MCP_GPIO': 10}, (7, 'XX'): {'MCP': 1, 'MCP_GPIO': 1}, (7, 'YY'): {'MCP': 1, 'MCP_GPIO': 9}, (8, 'XX'): {'MCP': 1, 'MCP_GPIO': 0}, (8, 'YY'): {'MCP': 1, 'MCP_GPIO': 8}}, - '2_roles': # TODO: WARNING check 2_roles table, it has not been verified yet !!! + '2_roles': # TODO: WARNING check 2_roles table, it has not been verified yet !!! {(1, 'X'): {'MCP': 0, 'MCP_GPIO': 0}, (1, 'Y'): {'MCP': 0, 'MCP_GPIO': 8}, (2, 'X'): {'MCP': 0, 'MCP_GPIO': 1}, (2, 'Y'): {'MCP': 0, 'MCP_GPIO': 9}, (3, 'X'): {'MCP': 0, 'MCP_GPIO': 2}, (3, 'Y'): {'MCP': 0, 'MCP_GPIO': 10}, @@ -67,7 +67,7 @@ class Mux(MuxAbstract): tca_channel = kwargs.pop('tca_channel', 0) self._roles = kwargs.pop('roles', None) if self._roles is None: - self._roles = {'A': 'X', 'B': 'Y', 'M' : 'XX', 'N' : 'YY'} # NOTE: defaults to 4-roles + self._roles = {'A': 'X', 'B': 'Y', 'M': 'XX', 'N': 'YY'} # NOTE: defaults to 4-roles if np.alltrue([j in self._roles.values() for j in set([i[1] for i in list(inner_cabling['4_roles'].keys())])]): self._mode = '4_roles' elif np.alltrue([j in self._roles.values() for j in set([i[1] for i in list(inner_cabling['2_roles'].keys())])]): diff --git a/ohmpi/ohmpi.py b/ohmpi/ohmpi.py index 57a7a56b..24e6d96f 100644 --- a/ohmpi/ohmpi.py +++ b/ohmpi/ohmpi.py @@ -463,7 +463,7 @@ class OhmPi(object): "inj time [ms]": injection_duration, # NOTE: check this # "Vmn [mV]": sum_vmn / (2 * nb_stack), # "I [mA]": sum_i / (2 * nb_stack), - # "R [ohm]": sum_vmn / sum_i, + "R [ohm]": np.mean(self._hw.readings[:, 2]*self._hw.readings[:, 4])/np.median(self._hw.readings[:, 3]), "Ps [mV]": self._hw.sp, "nbStack": nb_stack, "Tx [V]": tx_volt, -- GitLab