diff --git a/configs/config_mb_2024_0_2__8_mux_2023_dps5005.py b/configs/config_mb_2024_0_2__8_mux_2023_dps5005.py new file mode 100644 index 0000000000000000000000000000000000000000..4565d6d2896bec9d3a4ef8550e595578b4d34707 --- /dev/null +++ b/configs/config_mb_2024_0_2__8_mux_2023_dps5005.py @@ -0,0 +1,162 @@ +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', + 'coef_p2': 1.00, # 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 + '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_A2': + {'model': 'mux_2023_0_X', + 'mux_tca_address': 0x74, + 'roles': {'A': 'X'}, + 'cabling': {(i, j): ('mux_A2', i) for j in ['A'] for i in range(65, 129)}, + 'voltage_max': 12.}, + 'mux_B2': + {'model': 'mux_2023_0_X', + 'mux_tca_address': 0x75, + 'roles': {'B': 'X'}, + 'cabling': {(i, j): ('mux_B2', i) for j in ['B'] for i in range(65, 129)}, + 'voltage_max': 12.}, + 'mux_M2': + {'model': 'mux_2023_0_X', + 'mux_tca_address': 0x76, + 'roles': {'M': 'X'}, + 'cabling': {(i, j): ('mux_M2', i) for j in ['M'] for i in range(65, 129)}, + 'voltage_max': 12.}, + 'mux_N2': + {'model': 'mux_2023_0_X', + 'mux_tca_address': 0x77, + 'roles': {'N': 'X'}, + 'cabling': {(i, j): ('mux_N2', i) for j in ['N'] for i in range(65, 129)}, + 'voltage_max': 12.}, + }, + '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/ohmpi/hardware_system.py b/ohmpi/hardware_system.py index e91e58e3b89a88486864e9c072b2f3d114eff5ff..cb7dd11c1643d1ef96d703d7fa1aa5aec95b51d0 100644 --- a/ohmpi/hardware_system.py +++ b/ohmpi/hardware_system.py @@ -326,7 +326,7 @@ class OhmPiHardware: iab_std = np.std(iab) vmn_mean = np.mean(vmn) vmn_std = np.std(vmn) - print(f'iab: ({iab_mean:.5f}, {iab_std:5f}), vmn: ({vmn_mean:.4f}, {vmn_std:.4f})') + # print(f'iab: ({iab_mean:.5f}, {iab_std:5f}), vmn: ({vmn_mean:.4f}, {vmn_std:.4f})') # bounds on iab iab_upper_bound = iab_mean + 2 * iab_std iab_lower_bound = np.max([0.00001, iab_mean - 2 * iab_std]) @@ -343,18 +343,18 @@ class OhmPiHardware: cond_vmn_max = rab_lower_bound / r_upper_bound * vmn_max cond_p_max = np.sqrt(p_max * rab_lower_bound) cond_iab_max = rab_lower_bound * iab_max - print(f'Rab: [{rab_lower_bound:.1f}, {rab_upper_bound:.1f}], R: [{r_lower_bound:.1f},{r_upper_bound:.1f}]') - print(f'{k}: [{vab_max:.1f}, {cond_vmn_max:.1f}, {cond_p_max:.1f}, {cond_iab_max:.1f}]') + # print(f'Rab: [{rab_lower_bound:.1f}, {rab_upper_bound:.1f}], R: [{r_lower_bound:.1f},{r_upper_bound:.1f}]') + # print(f'{k}: [{vab_max:.1f}, {cond_vmn_max:.1f}, {cond_p_max:.1f}, {cond_iab_max:.1f}]') new_vab = np.min([vab_max, cond_vmn_max, cond_p_max, cond_iab_max]) if new_vab == vab_max: - print('Vab bounded by Vab max') + print(f'Vab {new_vab} bounded by Vab max') elif new_vab == cond_p_max: - print('Vab bounded by P max') + print(f'Vab {vab } bounded by P max') elif new_vab == cond_iab_max: - print('Vab bounded by Iab max') + print(f'Vab {vab} bounded by Iab max') else: assert new_vab == cond_vmn_max - print('Vab bounded by Vmn max') + print(f'Vab {vab} bounded by Vmn max') return new_vab @@ -404,7 +404,7 @@ class OhmPiHardware: if self.tx.pwr.voltage_adjustable: if vmn_max is None: vmn_max = self.rx._voltage_max / 1000. - print(f'Vmn max: {vmn_max}') + # print(f'Vmn max: {vmn_max}') if p_max is None: p_max = vab_max * iab_max @@ -442,7 +442,7 @@ class OhmPiHardware: new_vab = self._find_vab(vab_list[k], iab, vmn, p_max, vab_max, iab_max, vmn_max) diff_vab = np.abs(new_vab - vab_list[k]) vabs.append(new_vab) - print(f'new_vab: {new_vab}, diff_vab: {diff_vab}\n') + # print(f'new_vab: {new_vab}, diff_vab: {diff_vab}\n') if diff_vab < diff_vab_lim: print('stopped on vab increase too small') else: