Commit ddc069bd authored by Guillaume Blanchy's avatar Guillaume Blanchy
Browse files

Add calibration .py from hackathon 2024 (so we can remove calibration branch)

No related merge requests found
Showing with 202 additions and 0 deletions
+202 -0
import logging
from ohmpi.utils import *
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': 'settings/default.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': {'model': 'pwr_dph5005', 'voltage': 3., 'pwr_discharge_latency': 2.}, #, 'current_max':0.05,'current_overload':0.002}, # 'pwr_batt', 'voltage': 12.}, #
'tx': {'model': 'mb_2024_1_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',
'vmn_hardware_offset': 2500.
},
'rx': {'model': 'mb_2024_1_X',
'latency': 0.010, # latency in seconds in continuous mode
'sampling_rate': 800, # number of samples per second
'interface_name': 'i2c',
},
'mux': {'boards':
{'mux_01':
{'model': 'mux_2024_0_X',
'roles': ['A', 'B'],
'electrodes': mux_2023_to_mux_2024_takeouts(range(1, 17)),
'addr1': 'up',
'addr2': 'up',
'i2c_ext_tca_address': 0x70,
'i2c_ext_tca_channel': 0,
},
'mux_02':
{'model': 'mux_2024_0_X',
'roles': ['M', 'N'],
'electrodes': mux_2023_to_mux_2024_takeouts(range(1, 17)),
'addr1': 'down',
'addr2': 'down',
'i2c_ext_tca_address': 0x70,
'i2c_ext_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.DEBUG,
'log_file_logging_level': logging.DEBUG,
'logging_to_console': True,
'file_name': f'exec{logging_suffix}.log',
'max_bytes': 3355443,
'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.INFO,
'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': EXEC_LOGGING_CONFIG['logging_level'],
'data_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/data',
'data_logging_level': DATA_LOGGING_CONFIG['logging_level'],
'soh_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/soh',
'soh_logging_level': SOH_LOGGING_CONFIG['logging_level']
}
# MQTT control configuration parameters
MQTT_CONTROL_CONFIG = {
'hostname': mqtt_broker,
'port': 1883,
'qos': 2,
'retain': False,
'keepalive': 60,
'will': None,
'auth': {'username': 'mqtt_user', 'password': 'mqtt_password'},
'tls': None,
'protocol': MQTTv31,
'transport': 'tcp',
'client_id': f'{OHMPI_CONFIG["id"]}',
'ctrl_topic': f'ohmpi_{OHMPI_CONFIG["id"]}/ctrl'
}
import os
import numpy as np
import time
os.chdir("/home/pi/OhmPi")
from ohmpi.ohmpi import OhmPi
#from ohmpi.tests import contact_resistance_test_board
#######################
strategy = 'constant'
min_agg = True
r_ground = 5
vab_min = None
vab_req = 5.
vab_max = 12.
iab_min = 0.0025
iab_req = 0.005
iab_max = None
vmn_min = 0.75
vmn_req = 2.
vmn_max = None
pab_min = 0.0125
pab_req = 0.0625
pab_max = None
#######################
# Define object from class OhmPi
k = OhmPi()
k.reset_mux()
# Set or load sequence
sequence = np.array([np.array([1,2,3,4])+k for k in range(29)]) # [[1,2,3,4],[2,3,4,5]...] but can actually make other combinations of AB to increase number of contact resistance tested
sequence = np.vstack([sequence,np.array([[30,31,2,1],[31,32,3,2]])])
#sequence = sequence[:2]
#k.sequence = contact_resistance_test_board(sequence) # checks if sequence contains potential shortcut quads (AB odd odd or even even)
k.sequence = sequence
if strategy == 'vmin':
k.update_settings({'strategy': strategy, 'vmn_req': vmn_req})
k.update_settings({'export_path':f'data/r{r_ground}_{strategy}_{vmn_req:.1f}.csv'})
elif strategy == 'vmax':
k.update_settings({'strategy': strategy})
k.update_settings({'export_path':f'data/r{r_ground}_{strategy}.csv'})
elif strategy == 'flex':
k.update_settings({'strategy': strategy})
k.update_settings({'vab_min': vab_min, 'vab_req': vab_req, 'vab_max': vab_max, 'iab_min': iab_min, 'iab_req': iab_req, 'iab_max': iab_max,
'vmn_min': vmn_min, 'vmn_req': vmn_req, 'vmn_max': vmn_max, 'pab_min': pab_min, 'pab_req': pab_req, 'pab_max': pab_max, 'min_agg': min_agg})
k.update_settings({'export_path':f'data/r{r_ground}_{strategy}_vab-{vab_min}-{vab_req}-{vab_max}_iab-{iab_min}-{iab_req}-{iab_max}_vmn-{vmn_min}-{vmn_req}-{vmn_max}_pab-{pab_min}-{pab_req}-{pab_max}_{min_agg}.csv'})
elif strategy == "constant":
k.update_settings({'strategy': strategy})
k.update_settings({'vab_min': vab_min, 'vab_req': vab_req, 'vab_max': vab_max})
k.update_settings({'export_path':f'data/r{r_ground}_{strategy}_vab_req-{vab_req}-vab_max-{vab_max}.csv'})
print(f'Settings: {k.settings}')
# Run contact resistance check
#k.rs_check()
#print('TX',k._hw.tx.specs, 'PWR', k._hw.pwr.specs, 'RX', k._hw.rx.specs)
#print(k._hw.vab_min)
# Run sequence
#kwargs = {'vab_square_wave':{'append':False}}
k.run_sequence(nb_stack=2, injection_duration=.5, duty_cycle=1.,save_strategy_fw=True)
#k.plot_last_fw()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment