Commit 52b3c44c authored by Olivier Kaufmann's avatar Olivier Kaufmann
Browse files

Stores state before working in class branch

Showing with 811 additions and 302 deletions
+811 -302
...@@ -19,7 +19,7 @@ try: ...@@ -19,7 +19,7 @@ try:
except: except:
pass pass
from pandas import DataFrame # from pandas import DataFrame
from datetime import datetime from datetime import datetime
import time import time
import numpy as np import numpy as np
...@@ -230,28 +230,23 @@ def run_measurement(nb_stack, injection_deltat, r_shunt, coefp2, coefp3): ...@@ -230,28 +230,23 @@ def run_measurement(nb_stack, injection_deltat, r_shunt, coefp2, coefp3):
#print(['time stop=',((2*(end_delay-start_delay)-(end_calc-start_delay)))]) #print(['time stop=',((2*(end_delay-start_delay)-(end_calc-start_delay)))])
# return averaged values # return averaged values
# cpu= CPUTemperature() # cpu= CPUTemperature()
output = DataFrame({ output = {
"time": [datetime.now()], "time": datetime.now(),
"A": [(1)], "A": (1),
"B": [(2)], "B": (2),
"M": [(3)], "M": (3),
"N": [(4)], "N": (4),
"inj time [ms]": (end_delay - start_delay) * 1000, "inj time [ms]": (end_delay - start_delay) * 1000,
"Vmn [mV]": [(sum_vmn / (3 + 2 * nb_stack - 1))], "Vmn [mV]": (sum_vmn / (3 + 2 * nb_stack - 1)),
"I [mA]": [(injection_current / (3 + 2 * nb_stack - 1))], "I [mA]": (injection_current / (3 + 2 * nb_stack - 1)),
"R [ohm]": [(sum_vmn / (3 + 2 * nb_stack - 1) / (injection_current / (3 + 2 * nb_stack - 1)))], "R [ohm]": (sum_vmn / (3 + 2 * nb_stack - 1) / (injection_current / (3 + 2 * nb_stack - 1))),
"Ps [mV]": [(sum_ps / (3 + 2 * nb_stack - 1))], "Ps [mV]": (sum_ps / (3 + 2 * nb_stack - 1)),
"nbStack": [nb_stack], "nbStack": nb_stack,
"CPU temp [°C]": [cpu.temperature], "CPU temp [°C]": cpu.temperature,
"Time [s]": [(-start_time + time.time())], "Time [s]": (-start_time + time.time()),
"Integer [-]": [integer] "Integer [-]": integer}
# output = output.round(2)
print(output) # .to_string())
# Dead time equivalent to the duration of the current injection pulse
})
output = output.round(2)
print(output.to_string())
time.sleep(1) time.sleep(1)
return output return output
...@@ -260,13 +255,14 @@ def append_and_save(data_path, last_measurement): ...@@ -260,13 +255,14 @@ def append_and_save(data_path, last_measurement):
"""Save data""" """Save data"""
if path.isfile(data_path): if path.isfile(data_path):
# Load data file and append data to it # Load data file and append data to it
with open(data_path, 'a') as f: # with open(data_path, 'a') as f:
last_measurement.to_csv(f, header=False) # last_measurement.to_csv(f, header=False)
pass
else: else:
# create data file and add headers # create data file and add headers
with open(data_path, 'a') as f: # with open(data_path, 'a') as f:
last_measurement.to_csv(f, header=True) # last_measurement.to_csv(f, header=True)
pass
""" """
Main loop Main loop
...@@ -275,7 +271,7 @@ for g in range(0, pardict.get("nbr_meas")): # for time-lapse monitoring ...@@ -275,7 +271,7 @@ for g in range(0, pardict.get("nbr_meas")): # for time-lapse monitoring
current_measurement = run_measurement(pardict.get("stack"), pardict.get("injection_duration"), current_measurement = run_measurement(pardict.get("stack"), pardict.get("injection_duration"),
OHMPI_CONFIG['R_shunt'], OHMPI_CONFIG['coef_p2'], OHMPI_CONFIG['coef_p3']) OHMPI_CONFIG['R_shunt'], OHMPI_CONFIG['coef_p2'], OHMPI_CONFIG['coef_p3'])
append_and_save(pardict.get("export_path"), current_measurement) append_and_save(pardict.get("export_path"), current_measurement)
msg = f'Resitivity: {current_measurement.iloc[-1]["R [ohm]"]:.2f} ohm' msg = f'Resitivity: {current_measurement["R [ohm]"]:.2f} ohm'
msg_logger.info(msg) msg_logger.info(msg)
mqtt_client.publish(measurement_topic, msg) mqtt_client.publish(measurement_topic, msg)
time.sleep(pardict.get("sequence_delay")) # waiting next measurement (time-lapse) time.sleep(pardict.get("sequence_delay")) # waiting next measurement (time-lapse)
...@@ -4,17 +4,20 @@ url = "https://pypi.org/simple" ...@@ -4,17 +4,20 @@ url = "https://pypi.org/simple"
verify_ssl = true verify_ssl = true
[dev-packages] [dev-packages]
jupyterlab = "*"
sphinx-rtd-theme = "*"
recommonmark = "*"
sphinx-pdj-theme = "*"
[packages] [packages]
paho-mqtt = "*"
numpy = "*" numpy = "*"
pandas = "*" # cython = "*"
# pandas = "*"
paho-mqtt = "*"
pytz = "*" pytz = "*"
six = "*" six = "*"
gpiozero = "*"
adafruit-blinka = "*"
adafruit-circuitpython-ads1x15 = "*"
adafruit-circuitpython-tca9548a = "*"
adafruit-circuitpython-mcp230xx = "*"
termcolor ="*"
[requires] [requires]
python_version = "3.8" python_version = "3.9"
%% Cell type:markdown id:606c11c0-3a80-4138-ac50-1da0bd01bef8 tags: %% Cell type:markdown id:606c11c0-3a80-4138-ac50-1da0bd01bef8 tags:
# A small code to test MQTT interface for ohmpi # A small code to test MQTT interface for ohmpi
%% Cell type:code id:daf2041b-1df9-42de-a385-f450a826c96f tags: %% Cell type:code id:daf2041b-1df9-42de-a385-f450a826c96f tags:
``` python ``` python
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
import time import time
``` ```
%% Cell type:code id:14c42035 tags: %% Cell type:code id:14c42035 tags:
``` python ``` python
client_id = 'ohmpi_console_sn_0001' client_id = 'ohmpi_sn_001'
measurements_topic = 'measurements_ohmpi_sn_0001' control_topic = 'cmd_ohmpi_sn_001'
measurements_topic = 'measurements_ohmpi_sn_001'
``` ```
%% Cell type:code id:391c6373-f7db-485e-b3dd-b1e04a37473a tags: %% Cell type:code id:391c6373-f7db-485e-b3dd-b1e04a37473a tags:
``` python ``` python
broker_address="mg3d-dev.umons.ac.be" broker_address="mg3d-dev.umons.ac.be"
``` ```
%% Cell type:code id:8fc857ba-bbcf-4f99-a30f-84fd14ddb2d0 tags: %% Cell type:code id:8fc857ba-bbcf-4f99-a30f-84fd14ddb2d0 tags:
``` python ``` python
client = mqtt.Client(client_id, protocol=4) #create new instance client = mqtt.Client(client_id, protocol=4) #create new instance
``` ```
%% Cell type:code id:24926751-62c6-4833-8d68-99279192d4e0 tags: %% Cell type:code id:24926751-62c6-4833-8d68-99279192d4e0 tags:
``` python ``` python
def on_message(client, userdata, message): def on_message(client, userdata, message):
m = str(message.payload.decode("utf-8")) m = str(message.payload.decode("utf-8"))
print(f'message received {m}') print(f'message received {m}')
print(f'topic: {message.topic}') print(f'topic: {message.topic}')
print(f'qos: {message.qos}') print(f'qos: {message.qos}')
print(f'retain flag: {message.retain}') print(f'retain flag: {message.retain}')
client.publish(measurements_topic, f'{m} 45 ohm.m')
``` ```
%% Cell type:code id:06e424ff-cd1d-4756-bf53-cfbca4628e73 tags: %% Cell type:code id:06e424ff-cd1d-4756-bf53-cfbca4628e73 tags:
``` python ``` python
client.connect(broker_address) #connect to broker client.connect(broker_address) #connect to broker
``` ```
%% Output %% Output
0 0
%% Cell type:code id:f0b06a71-b0bf-4551-a044-94b1100a3a5d tags: %% Cell type:code id:f0b06a71-b0bf-4551-a044-94b1100a3a5d tags:
``` python ``` python
client.on_message = on_message client.on_message = on_message
client.loop_start() client.loop_start()
``` ```
%% Cell type:code id:8e168d2d-25fa-49ac-9d03-dd0da5e61841 tags: %% Cell type:code id:8e168d2d-25fa-49ac-9d03-dd0da5e61841 tags:
``` python ``` python
print("Subscribing to topic", measurements_topic) print("Subscribing to topic", control_topic)
client.subscribe(measurements_topic) client.subscribe(control_topic)
``` ```
%% Output %% Output
Subscribing to topic measurements_ohmpi_sn_0001 Subscribing to topic cmd_ohmpi_sn_001
(0, 1) (0, 1)
%% Cell type:code id:eaa7d034-5383-4ece-a824-f763ce214760 tags: %% Cell type:code id:eaa7d034-5383-4ece-a824-f763ce214760 tags:
``` python ``` python
time.sleep(60) time.sleep(45)
``` ```
%% Output %% Output
message received Resitivity: 215.22 ohm message received 21:26:23 : measure resistivity 0 with array 1 4 2 3
topic: measurements_ohmpi_sn_0001 topic: cmd_ohmpi_sn_001
qos: 0 qos: 0
retain flag: 0 retain flag: 0
message received Resitivity: 214.94 ohm message received 21:26:24 : measure resistivity 1 with array 2 5 3 4
topic: measurements_ohmpi_sn_0001 topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:25 : measure resistivity 2 with array 3 6 4 5
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:26 : measure resistivity 3 with array 4 7 5 6
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:27 : measure resistivity 4 with array 5 8 6 7
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:28 : measure resistivity 5 with array 6 9 7 8
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:29 : measure resistivity 6 with array 7 10 8 9
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:30 : measure resistivity 7 with array 8 11 9 10
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:31 : measure resistivity 8 with array 9 12 10 11
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:32 : measure resistivity 9 with array 10 13 11 12
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:33 : measure resistivity 10 with array 11 14 12 13
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:34 : measure resistivity 11 with array 12 15 13 14
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:35 : measure resistivity 12 with array 13 16 14 15
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:36 : measure resistivity 13 with array 14 17 15 16
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:37 : measure resistivity 14 with array 15 18 16 17
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:38 : measure resistivity 15 with array 16 19 17 18
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:39 : measure resistivity 16 with array 17 20 18 19
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:40 : measure resistivity 17 with array 18 21 19 20
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:41 : measure resistivity 18 with array 19 22 20 21
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:42 : measure resistivity 19 with array 20 23 21 22
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:43 : measure resistivity 20 with array 21 24 22 23
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:44 : measure resistivity 21 with array 22 25 23 24
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:45 : measure resistivity 22 with array 23 26 24 25
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:46 : measure resistivity 23 with array 24 27 25 26
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:47 : measure resistivity 24 with array 25 28 26 27
topic: cmd_ohmpi_sn_001
qos: 0
retain flag: 0
message received 21:26:48 : measure resistivity 25 with array 26 29 27 28
topic: cmd_ohmpi_sn_001
qos: 0 qos: 0
retain flag: 0 retain flag: 0
%% Cell type:code id:9bd768aa-c4d3-429e-b667-6e981bd28353 tags: %% Cell type:code id:9bd768aa-c4d3-429e-b667-6e981bd28353 tags:
``` python ``` python
client.loop_stop() client.loop_stop()
``` ```
%% Cell type:code id:f9a0333a-c1ec-42a8-bd24-3dc466c51bb4 tags: %% Cell type:code id:f9a0333a-c1ec-42a8-bd24-3dc466c51bb4 tags:
``` python ``` python
``` ```
......
This diff is collapsed.
{ {
"nb_electrodes": 64, "nb_electrodes": 64,
"injection_duration": 4, "injection_duration": 1,
"nbr_meas": 100, "nbr_meas": 100,
"sequence_delay": 1, "sequence_delay": 1,
"stack": 1, "stack": 1,
......
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