Commit 6c4ab2a0 authored by Olivier Kaufmann's avatar Olivier Kaufmann
Browse files

Updates _vab_pulse

No related merge requests found
Showing with 252 additions and 53 deletions
+252 -53
......@@ -14,54 +14,29 @@ logging_suffix = ''
# OhmPi configuration
OHMPI_CONFIG = {
'id': ohmpi_id, # Unique identifier of the OhmPi board (string)
# 'R_shunt': 2, # Shunt resistance in Ohms
# 'Imax': 4800 / 50 / 2, # Maximum current
# '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...
# 'version': 2, # Is this still needed?
# 'max_elec': 64,
# 'board_addresses': {'A': 0x73, 'B': 0x72, 'M': 0x71, 'N': 0x70}, # CHECK IF YOUR BOARDS HAVE THESE ADDRESSES
'settings': 'ohmpi_settings.json', # INSERT YOUR FAVORITE SETTINGS FILE HERE
# 'board_version': 'mb.2023.0.0',#,'22.10',
# 'mcp_board_address': 0x20
} # TODO: add a dictionary with INA models and associated gain values
}
"""HARDWARE_CONFIG = {
HARDWARE_CONFIG = {
'controller': {'model' : 'raspberry_pi_3'
},
'tx' : {'model' : 'mb_2024_rev_0_0',
'tx' : {'model' : 'ohmpi_card_3_15',
'mcp_board_address': 0x20,
'Imax': 4800 / 50 / 2, # Maximum current
'R_shunt': 2 # Shunt resistance in Ohms
'current_max': 4800 / 50 / 2, # Maximum current
'r_shunt': 2 # Shunt resistance in Ohms
},
'rx' : {'model': 'mb_2024_rev_0_0',
'rx' : {'model': 'ohmpi_card_3_15',
'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': {'model' : 'mux_2021',
'mux': {'model' : 'ohmpi_i2c_mux64_v1.01',
'max_elec': 64,
'board_addresses': {'A': 0x73, 'B': 0x72, 'M': 0x71, 'N': 0x70}, # CHECK IF YOUR BOARDS HAVE THESE ADDRESSES
'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...
}
}"""
HARDWARE_CONFIG = {
'controller': {'model' : 'dummy_controller'
},
'tx' : {'model' : 'dummy_tx',
'current_max': 4800 / 50 / 2, # Maximum current mA
'r_shunt': 2, # Shunt resistance in Ohms
'low_battery': 12. # Volts
},
'rx' : {'model': 'dummy_rx',
},
'mux': {'model' : 'dummy_mux',
'max_elec': 64,
'voltage_max' : 100,
'current_max' : 3
'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 = {
......
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 = {
'controller': {'model' : 'dummy_controller'
},
'tx' : {'model' : 'dummy_tx',
'current_max': 4800 / 50 / 2, # Maximum current mA
'r_shunt': 2, # Shunt resistance in Ohms
'low_battery': 12. # Volts
},
'rx' : {'model': 'dummy_rx',
},
'mux': {'model' : 'dummy_mux',
'max_elec': 64,
'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,
'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'
}
......@@ -14,17 +14,8 @@ logging_suffix = ''
# OhmPi configuration
OHMPI_CONFIG = {
'id': ohmpi_id, # Unique identifier of the OhmPi board (string)
# 'R_shunt': 2, # Shunt resistance in Ohms
# 'Imax': 4800 / 50 / 2, # Maximum current
# '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...
# 'version': 2, # Is this still needed?
# 'max_elec': 64,
# 'board_addresses': {'A': 0x73, 'B': 0x72, 'M': 0x71, 'N': 0x70}, # CHECK IF YOUR BOARDS HAVE THESE ADDRESSES
'settings': 'ohmpi_settings.json', # INSERT YOUR FAVORITE SETTINGS FILE HERE
# 'board_version': 'mb.2023.0.0',#,'22.10',
# 'mcp_board_address': 0x20
} # TODO: add a dictionary with INA models and associated gain values
}
HARDWARE_CONFIG = {
'controller': {'model' : 'raspberry_pi_3'
......@@ -32,7 +23,7 @@ HARDWARE_CONFIG = {
'tx' : {'model' : 'mb_2024_rev_0_0',
'mcp_board_address': 0x20,
'current_max': 4800 / 50 / 2, # Maximum current
'R_shunt': 2 # Shunt resistance in Ohms
'r_shunt': 2 # Shunt resistance in Ohms
},
'rx' : {'model': 'mb_2024_rev_0_0',
'coef_p2': 2.50, # slope for current conversion for ADS.P2, measurement in V/V
......
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 = {
'controller': {'model' : 'raspberry_pi_3'
},
'tx' : {'model' : 'ohmpi_card_3_15',
'mcp_board_address': 0x20,
'current_max': 4800 / 50 / 2, # Maximum current
'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
'nb_samples': 20, # Max value 10 # was named integer before...
},
'mux': {'model' : 'ohmpi_i2c_mux64_v1.01',
'max_elec': 64,
'board_addresses': {'A': 0x73, 'B': 0x72, 'M': 0x71, 'N': 0x70}, # CHECK IF YOUR BOARDS HAVE THESE ADDRESSES
'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,
'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'
}
......@@ -48,18 +48,18 @@ class OhmPiHardware:
def _vab_pulse(self, vab, length, polarity=None):
""" Gets VMN and IAB from a single voltage pulse
"""
def inject(length):
def inject(duration):
self.tx_sync.set()
self.tx.voltage_pulse(length=length)
self.tx.voltage_pulse(length=duration)
self.tx_sync.clear()
def read_values():
readings = []
_readings = []
self.tx_sync.wait()
start_time = time.gmtime()
while self.tx_sync.is_set():
readings.append([time.gmtime() - start_time, self.tx.current, self.rx.voltage])
return np.array(readings)
_readings.append([time.gmtime() - start_time, self.tx.current, self.rx.voltage])
return np.array(_readings)
if polarity is not None and polarity != self.tx.polarity:
self.tx.polarity = polarity
......
......@@ -28,3 +28,11 @@ 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} %')
from OhmPi.measure import OhmPiHardware
from utils import change_config
change_config('config_ohmpi_card_3_15.py')
k = OhmPiHardware()
k._vab_pulse(vab=12, length=2., polarity=1)
change_config('config_default.py')
\ No newline at end of file
import io
import os
import shutil
def get_platform():
"""Gets platform name and checks if it is a raspberry pi
......@@ -17,4 +18,12 @@ def get_platform():
on_pi = True
except FileNotFoundError:
pass
return platform, on_pi
\ No newline at end of file
return platform, on_pi
def change_config(config_file):
cwd = os.getcwd()
try:
shutil.copyfile(f'{cwd}/OhmPi/config.py', f'{cwd}/OhmPi/config_tmp.py')
shutil.copyfile(f'{cwd}/OhmPi/{config_file}', f'{cwd}/OhmPi/config.py')
except Exception as error:
print(f'Could not change config file to {cwd}/OhmPi/{config_file}:\n{error}')
\ 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