Commit 880635c8 authored by Olivier Kaufmann's avatar Olivier Kaufmann
Browse files

Updates configs and tests to work on mb_2024

Showing with 94 additions and 659 deletions
+94 -659
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'
}
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'
}
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'
}
......@@ -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.}
}
}
......
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
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()
# 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} %')
......@@ -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')
......
......@@ -2,30 +2,30 @@ 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
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
stand_alone_mux = False
part_of_hardware_system = True
within_ohmpi = False
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_05'
first = 8
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(2)
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(8)
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)],
......@@ -49,17 +49,27 @@ 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([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.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()
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')
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
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)
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
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