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

Add instruction README for modifying pythonpath + add pwr_state for pwr

Showing with 54 additions and 1389 deletions
+54 -1389
...@@ -23,6 +23,8 @@ We strongly recommend users to create a virtual environment to run the code and ...@@ -23,6 +23,8 @@ We strongly recommend users to create a virtual environment to run the code and
* you should run you code within the virtual environment * you should run you code within the virtual environment
* to leave the virtual environment simply type: `deactivate` * to leave the virtual environment simply type: `deactivate`
To enable to Python module, we need to add the 'ohmpi' folder to the python path. This can be done by `source .env` or manually by adding `export PYTHONPATH=$PYTHONPATH:/home/<username>/OhmPi` to /home/<username>/.bashrc.
## First run with four electrodes ## First run with four electrodes
In the examples folder, you will find the code "simple_measurement.py". In the examples folder, you will find the code "simple_measurement.py".
......
This diff is collapsed.
This diff is collapsed.
import logging import logging
from ohmpi.utils import get_platform from ohmpi.utils import get_platform
from paho.mqtt.client import MQTTv31 # noqa from paho.mqtt.client import MQTTv31
_, on_pi = get_platform() _, on_pi = get_platform()
# DEFINE THE ID OF YOUR OhmPi # DEFINE THE ID OF YOUR OhmPi
...@@ -18,34 +18,25 @@ OHMPI_CONFIG = { ...@@ -18,34 +18,25 @@ OHMPI_CONFIG = {
} }
HARDWARE_CONFIG = { HARDWARE_CONFIG = {
'ctl': {'model': 'raspberry_pi'}, 'ctl': {'model' : 'dummy_ctl'
'pwr': {'model': 'pwr_batt', 'voltage': 12., 'interface_name': 'none'}, },
'tx': {'model': 'mb_2023_0_X', 'tx' : {'model' : 'dummy_tx',
'voltage_max': 12., # Maximum voltage supported by the TX board [V] 'current_max': 4800 / 50 / 2, # Maximum current mA
'adc_voltage_max': 4800., # Maximum voltage read by the current ADC on the TX board [mA] 'r_shunt': 2, # Shunt resistance in Ohms
'r_shunt': 2., # Shunt resistance in Ohms 'low_battery': 12. # Volts
'interface_name': 'i2c',
}, },
'rx': {'model': 'mb_2023_0_X', 'rx' : {'model': 'dummy_rx',
'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 given in config are system properties that will be 'mux': {'model' : 'dummy_mux',
# overwritten by properties defined in each the board dict below. 'max_elec': 64,
# if defined in board specs, values out of specs will be bounded to remain in specs 'voltage_max' : 100,
# omitted properties in config will be set to board specs default values if they exist 'current_max' : 3
{'boards': {}, }
'default': {'interface_name': 'i2c',
'voltage_max': 100.,
'current_max': 3.}
}
} }
# SET THE LOGGING LEVELS, MQTT BROKERS AND MQTT OPTIONS ACCORDING TO YOUR NEEDS # SET THE LOGGING LEVELS, MQTT BROKERS AND MQTT OPTIONS ACCORDING TO YOUR NEEDS
# Execution logging configuration # Execution logging configuration
EXEC_LOGGING_CONFIG = { EXEC_LOGGING_CONFIG = {
'logging_level': logging.DEBUG, # TODO: set logging level back to INFO 'logging_level': logging.INFO,
'log_file_logging_level': logging.DEBUG, 'log_file_logging_level': logging.DEBUG,
'logging_to_console': True, 'logging_to_console': True,
'file_name': f'exec{logging_suffix}.log', 'file_name': f'exec{logging_suffix}.log',
...@@ -69,8 +60,8 @@ DATA_LOGGING_CONFIG = { ...@@ -69,8 +60,8 @@ DATA_LOGGING_CONFIG = {
# State of Health logging configuration (For a future release) # State of Health logging configuration (For a future release)
SOH_LOGGING_CONFIG = { SOH_LOGGING_CONFIG = {
'logging_level': logging.INFO, 'logging_level': logging.INFO,
'logging_to_console': True,
'log_file_logging_level': logging.DEBUG, 'log_file_logging_level': logging.DEBUG,
'logging_to_console': True,
'file_name': f'soh{logging_suffix}.log', 'file_name': f'soh{logging_suffix}.log',
'max_bytes': 16777216, 'max_bytes': 16777216,
'backup_count': 1024, 'backup_count': 1024,
......
...@@ -167,6 +167,22 @@ class OhmPiHardware: ...@@ -167,6 +167,22 @@ class OhmPiHardware:
self._start_time = None # time of the beginning of a readings acquisition self._start_time = None # time of the beginning of a readings acquisition
self._pulse = 0 # pulse number self._pulse = 0 # pulse number
self.exec_logger.event(f'OhmPiHardware\tinit\tend\t{datetime.datetime.utcnow()}') self.exec_logger.event(f'OhmPiHardware\tinit\tend\t{datetime.datetime.utcnow()}')
self._pwr_state = 'off'
@property
def pwr_state(self):
return self._pwr_state
@pwr_state.setter
def pwr_state(self, state):
if state == 'on':
self.tx.pwr_state = 'on'
self._pwr_state = 'on'
self.exec_logger.debug(f'{self.model} cannot be switched on')
elif state == 'off':
self.tx.pwr_state = 'off'
self._pwr_state = 'off'
self.exec_logger.debug(f'{self.model} cannot be switched off')
def _clear_values(self): def _clear_values(self):
self.readings = np.array([]) self.readings = np.array([])
...@@ -420,8 +436,8 @@ class OhmPiHardware: ...@@ -420,8 +436,8 @@ class OhmPiHardware:
append=False): append=False):
self.exec_logger.event(f'OhmPiHardware\tvab_square_wave\tbegin\t{datetime.datetime.utcnow()}') self.exec_logger.event(f'OhmPiHardware\tvab_square_wave\tbegin\t{datetime.datetime.utcnow()}')
switch_pwr_off, switch_tx_pwr_off = False, False switch_pwr_off, switch_tx_pwr_off = False, False
if self.tx.pwr_state == 'off': if self.pwr_state == 'off':
self.tx.pwr_state = 'on' self.pwr_state = 'on'
switch_tx_pwr_off = True switch_tx_pwr_off = True
# if self.tx.pwr.pwr_state == 'off': # if self.tx.pwr.pwr_state == 'off':
# self.tx.pwr.pwr_state = 'on' # self.tx.pwr.pwr_state = 'on'
...@@ -442,7 +458,7 @@ class OhmPiHardware: ...@@ -442,7 +458,7 @@ class OhmPiHardware:
if switch_pwr_off: if switch_pwr_off:
self.tx.pwr.pwr_state = 'off' self.tx.pwr.pwr_state = 'off'
if switch_tx_pwr_off: if switch_tx_pwr_off:
self.tx.pwr_state = 'off' self.pwr_state = 'off'
def _vab_pulse(self, vab=None, duration=1., sampling_rate=None, polarity=1, append=False): def _vab_pulse(self, vab=None, duration=1., sampling_rate=None, polarity=1, append=False):
""" Gets VMN and IAB from a single voltage pulse """ Gets VMN and IAB from a single voltage pulse
...@@ -466,8 +482,8 @@ class OhmPiHardware: ...@@ -466,8 +482,8 @@ class OhmPiHardware:
def _vab_pulses(self, vab, durations, sampling_rate, polarities=None, append=False): def _vab_pulses(self, vab, durations, sampling_rate, polarities=None, append=False):
switch_pwr_off, switch_tx_pwr_off = False, False switch_pwr_off, switch_tx_pwr_off = False, False
if self.tx.pwr_state == 'off': if self.pwr_state == 'off':
self.tx.pwr_state = 'on' self.pwr_state = 'on'
switch_pwr_off = True switch_pwr_off = True
n_pulses = len(durations) n_pulses = len(durations)
self.exec_logger.debug(f'n_pulses: {n_pulses}') self.exec_logger.debug(f'n_pulses: {n_pulses}')
...@@ -492,7 +508,8 @@ class OhmPiHardware: ...@@ -492,7 +508,8 @@ class OhmPiHardware:
if switch_pwr_off: if switch_pwr_off:
self.tx.pwr.pwr_state = 'off' self.tx.pwr.pwr_state = 'off'
if switch_tx_pwr_off: if switch_tx_pwr_off:
self.tx.pwr_state = 'off' self.pwr_state = 'off'
def switch_mux(self, electrodes, roles=None, state='off', **kwargs): def switch_mux(self, electrodes, roles=None, state='off', **kwargs):
"""Switches on multiplexer relays for given quadrupole. """Switches on multiplexer relays for given quadrupole.
......
...@@ -451,6 +451,12 @@ class OhmPi(object): ...@@ -451,6 +451,12 @@ class OhmPi(object):
cmd_id : str, optional cmd_id : str, optional
Unique command identifier Unique command identifier
""" """
# check pwr is on, if not, let's turn it on
switch_power_off = False
if self._hw.pwr_state == 'off':
self._hw.pwr_state = 'on'
switch_power_off = True
self.exec_logger.debug('Starting measurement') self.exec_logger.debug('Starting measurement')
self.exec_logger.debug('Waiting for data') self.exec_logger.debug('Waiting for data')
...@@ -532,6 +538,11 @@ class OhmPi(object): ...@@ -532,6 +538,11 @@ class OhmPi(object):
else: else:
self.exec_logger.info(f'Skipping {quad}') self.exec_logger.info(f'Skipping {quad}')
self.switch_mux_off(quad, cmd_id) self.switch_mux_off(quad, cmd_id)
# if power was off before measurement, let's turn if off
if switch_power_off:
self._hw.pwr_state = 'off'
return d return d
def run_multiple_sequences(self, cmd_id=None, sequence_delay=None, nb_meas=None, **kwargs): # NOTE : could be renamed repeat_sequence def run_multiple_sequences(self, cmd_id=None, sequence_delay=None, nb_meas=None, **kwargs): # NOTE : could be renamed repeat_sequence
...@@ -588,6 +599,8 @@ class OhmPi(object): ...@@ -588,6 +599,8 @@ class OhmPi(object):
cmd_id : str, optional cmd_id : str, optional
Unique command identifier Unique command identifier
""" """
# switch power on
self._hw.pwr_state = 'on'
self.status = 'running' self.status = 'running'
self.exec_logger.debug(f'Status: {self.status}') self.exec_logger.debug(f'Status: {self.status}')
self.exec_logger.debug(f'Measuring sequence: {self.sequence}') self.exec_logger.debug(f'Measuring sequence: {self.sequence}')
...@@ -669,7 +682,7 @@ class OhmPi(object): ...@@ -669,7 +682,7 @@ class OhmPi(object):
self.append_and_save(filename, acquired_data) self.append_and_save(filename, acquired_data)
self.exec_logger.debug(f'quadrupole {i + 1:d}/{n:d}') self.exec_logger.debug(f'quadrupole {i + 1:d}/{n:d}')
# self.switch_dps('off') self._hw.pwr_state = 'off'
self.status = 'idle' self.status = 'idle'
def run_sequence_async(self, cmd_id=None, **kwargs): def run_sequence_async(self, cmd_id=None, **kwargs):
......
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