Commit d077b047 authored by Pedro Henrique Kopper's avatar Pedro Henrique Kopper
Browse files

Prevenir que o GC mate o gráfico

parent 7ee0c7fe
...@@ -3,13 +3,11 @@ device: ...@@ -3,13 +3,11 @@ device:
type: mock type: mock
location: "/dev/ttyACM0" location: "/dev/ttyACM0"
channels: channels:
- id: "PWR" - id: "A0"
name: "Potência" name: "Amostra"
color: "#FF0000" color: "#FF0000"
unit: "W" unit: "V"
- id: "TC" - id: "A3"
name: "Temperatura" name: "Pressão"
color: "#0000FF" color: "#0000FF"
unit: "ºC" unit: "bar"
tc: 18
type: "R"
from random import random from random import random
from time import sleep
from sacada import SACADA as _SACADA from sacada import SACADA as _SACADA
class SACADA(object): class SACADA(object):
def __init__(self, logger, location, channels): def __init__(self, logger, location, channels):
self.channels = channels self.channels = channels
self.s = _SACADA(location) self.s = _SACADA(location)
self.s.sendSCPICommand("IN:SCALE A0,V0256")
logger("[SACADA]", "Opening SACADA at {}".format(location)) logger("[SACADA]", "Opening SACADA at {}".format(location))
logger("[SACADA]", str(self.s.identify())) logger("[SACADA]", str(self.s.identify()))
logger("[SACADA]", "Valor do zero: {}".format(self.s.zero())) logger("[SACADA]", "Valor do zero: {}".format(self.s.zero()))
...@@ -18,6 +20,8 @@ class SACADA(object): ...@@ -18,6 +20,8 @@ class SACADA(object):
return 0 return 0
if channel["id"] == "PWR": if channel["id"] == "PWR":
return self.s.readVoltage("A3") * self.s.readVoltage("A4") return self.s.readVoltage("A3") * self.s.readVoltage("A4")
if channel["id"] == "A3":
return self.s.readVoltage("A3") * (250.0/10.0)
return self.s.readVoltage(channel["id"]) return self.s.readVoltage(channel["id"])
def readAll(self): def readAll(self):
......
...@@ -258,7 +258,7 @@ font: 10pt &quot;Liberation Mono&quot;;</string> ...@@ -258,7 +258,7 @@ font: 10pt &quot;Liberation Mono&quot;;</string>
<string notr="true"/> <string notr="true"/>
</property> </property>
<property name="title"> <property name="title">
<string>Temperatura</string> <string>Amostra</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignBottom|Qt::AlignRight|Qt::AlignTrailing</set> <set>Qt::AlignBottom|Qt::AlignRight|Qt::AlignTrailing</set>
...@@ -298,7 +298,7 @@ font: 10pt &quot;Liberation Mono&quot;;</string> ...@@ -298,7 +298,7 @@ font: 10pt &quot;Liberation Mono&quot;;</string>
<string notr="true"/> <string notr="true"/>
</property> </property>
<property name="title"> <property name="title">
<string>Potência</string> <string>Pressão</string>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0"> <layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0">
<item alignment="Qt::AlignRight"> <item alignment="Qt::AlignRight">
......
from datetime import datetime
from PyQt5.QtCore import QTimer from PyQt5.QtCore import QTimer
from pyqtgraph import AxisItem, InfiniteLine, mkColor, mkPen, setConfigOption from pyqtgraph import AxisItem, InfiniteLine, mkColor, mkPen, setConfigOption
from interfaces import * from interfaces import *
...@@ -17,6 +18,9 @@ class Graph(): ...@@ -17,6 +18,9 @@ class Graph():
self.axis = [] self.axis = []
self.config = Config().data self.config = Config().data
self.device = self.config["device"] self.device = self.config["device"]
today = datetime.now().strftime("%Y-%m-%d-%H:%M:%S")
self.logFile = open("/home/phckopper/logs/{}-calib.csv".format(today), "w")
self._configurePlots() self._configurePlots()
self.lastupdated = 0 self.lastupdated = 0
...@@ -30,14 +34,18 @@ class Graph(): ...@@ -30,14 +34,18 @@ class Graph():
self.graph.setBackground((240, 240, 240)) self.graph.setBackground((240, 240, 240))
def updateGraphs(self): def updateGraphs(self):
self.logFile.write("\n")
for i, channel in enumerate(self.device["channels"]): for i, channel in enumerate(self.device["channels"]):
self.dataX[i].append(self.dataX[i][-1] + self.interval/1000.0) self.dataX[i].append(self.dataX[i][-1] + self.interval/1000.0)
self.dataY[i].append(self.interface.read(self.device["channels"][i])) self.dataY[i].append(self.interface.read(self.device["channels"][i]))
self.plots[i].getViewBox().setRange(xRange=(self.dataX[0][-1] - 10, self.dataX[0][-1])) #self.plots[i].getViewBox().setRange(xRange=(self.dataX[0][-1] - 10, self.dataX[0][-1]))
self.plots[i].setData(self.dataX[i], self.dataY[i], clear=True) self.plots[i].setData(self.dataX[i], self.dataY[i])
self.logFile.write("{},".format(self.dataY[i][-1]))
self.logFile.write("{}".format(self.dataX[0][-1]))
self.logFile.flush()
self.ui.forceLabel.setText("{:.4f} U".format(self.dataY[0][-1])) self.ui.forceLabel.setText("{:.2f} bar".format(self.dataY[1][-1]))
self.ui.calibratorLabel.setText("{:.2f} ºC".format(self.dataY[1][-1])) self.ui.calibratorLabel.setText("{:.4f} mV".format(self.dataY[0][-1] * 1000))
pg.QtGui.QApplication.processEvents() pg.QtGui.QApplication.processEvents()
def setInterval(self, interval): def setInterval(self, interval):
...@@ -62,10 +70,14 @@ class Graph(): ...@@ -62,10 +70,14 @@ class Graph():
self.plots.append(plot) self.plots.append(plot)
plotItem.setClipToView(True) plotItem.setClipToView(True)
plotItem.showGrid(True) plotItem.showGrid(True)
plotItem.getViewBox().setMouseEnabled(False, False) #plotItem.getViewBox().setMouseEnabled(False, False)
plotItem.getViewBox().enableAutoRange(plotItem.getViewBox().YAxis) plotItem.getViewBox().enableAutoRange(plotItem.getViewBox().YAxis)
#plotItem.getViewBox().setAutoPan(x=True) #plotItem.getViewBox().setAutoPan(x=True)
self.dataX.append([0]) self.dataX.append([0])
self.dataY.append([0]) self.dataY.append([0])
plotItem.setLabel("left", text=channel["name"], units=channel["unit"]) plotItem.setLabel("left", text=channel["name"], units=channel["unit"])
self.logger("[GRAPH]", "Added channel {}".format(channel["name"])) self.logger("[GRAPH]", "Added channel {}".format(channel["name"]))
self.logFile.write("{},".format(channel["name"]))
self.logFile.write("timestamp")
from datetime import datetime from datetime import datetime
from time import sleep from time import sleep, time
from sys import exit from sys import exit
from PyQt5.QtCore import QThread, QTimer from PyQt5.QtCore import QThread, QTimer
from PyQt5.QtWidgets import QMessageBox, QApplication from PyQt5.QtWidgets import QMessageBox, QApplication
...@@ -8,36 +8,36 @@ from config import Config ...@@ -8,36 +8,36 @@ from config import Config
from util.Timer import Timer from util.Timer import Timer
class MainThread(): class MainThread():
def __init__(self, ui, parent=None): def __init__(self, ui, timer):
#super(MainThread, self).__init__(parent) #super(MainThread, self).__init__(parent)
self.ui = ui self.ui = ui
self.data = [] self.data = []
self.graph = Graph(self.ui, 100, self._log) self.graph = Graph(self.ui, 250, self._log)
#self.upTimer = Timer() #self.upTimer = Timer()
#self.downTimer = Timer(delay=10) #self.downTimer = Timer(delay=10)
try: try:
self.config = Config() self.config = Config()
except FileNotFoundError: except FileNotFoundError:
self._fatal("Arquivo de configuração não encontrado!") self._fatal("Arquivo de configuração não encontrado!")
self.graphTimer = QTimer(ui.mainGraph) self.graphTimer = timer
self.graphTimer.timeout.connect(self.graph.updateGraphs) self.graphTimer.timeout.connect(self.graph.updateGraphs)
self.graphTimer.start(self.graph.interval) self.graphTimer.start(self.graph.interval)
self.ui.samplingCBox.currentIndexChanged.connect(self._updateSamplingRate) self.ui.samplingCBox.currentIndexChanged.connect(self._updateSamplingRate)
def run(self): def run(self):
pass
#self.ui.startTimerButton.pressed.connect(self._startTimer) #self.ui.startTimerButton.pressed.connect(self._startTimer)
#self.ui.stopTimerButton.pressed.connect(self._stopTimer) #self.ui.stopTimerButton.pressed.connect(self._stopTimer)
#self.ui.startRegTimerButton.pressed.connect(self._startTimer) #self.ui.startRegTimerButton.pressed.connect(self._startTimer)
#self.ui.stopRegTimerButton.pressed.connect(self._stopTimer) #self.ui.stopRegTimerButton.pressed.connect(self._stopTimer)
#self.ui.playPauseButton.aboutToShow.connect(self._playPause) #self.ui.playPauseButton.aboutToShow.connect(self._playPause)
#self.ui.finalizeButton.aboutToShow.connect(self._finalize) #self.ui.finalizeButton.aboutToShow.connect(self._finalize)
#while True: while True:
#self._updateTimers() #self._updateTimers()
#if self.graph.running: #if self.graph.running:
# self.graph.updateGraphs() # self.graph.updateGraphs()
#QApplication.processEvents() QApplication.processEvents()
#sleep(self.graph.interval/1000.0) # Updates at 30FPS print(time())
sleep(self.graph.interval/1000.0) # Updates at 30FPS
def _updateSamplingRate(self): def _updateSamplingRate(self):
MAP = [100, 200, 500, 1000, 1500, 2000, 2500, 5000, 10000] MAP = [100, 200, 500, 1000, 1500, 2000, 2500, 5000, 10000]
......
...@@ -269,9 +269,9 @@ class Ui_Generico(object): ...@@ -269,9 +269,9 @@ class Ui_Generico(object):
self.samplingCBox.setItemText(7, _translate("Generico", "5 seg")) self.samplingCBox.setItemText(7, _translate("Generico", "5 seg"))
self.samplingCBox.setItemText(8, _translate("Generico", "10 seg")) self.samplingCBox.setItemText(8, _translate("Generico", "10 seg"))
self.absValGBox.setTitle(_translate("Generico", "Valores Absolutos")) self.absValGBox.setTitle(_translate("Generico", "Valores Absolutos"))
self.calibratorGBox.setTitle(_translate("Generico", "Temperatura")) self.calibratorGBox.setTitle(_translate("Generico", "Amostra"))
self.calibratorLabel.setText(_translate("Generico", "0 mV")) self.calibratorLabel.setText(_translate("Generico", "0 mV"))
self.forceGBox.setTitle(_translate("Generico", "Potência")) self.forceGBox.setTitle(_translate("Generico", "Pressão"))
self.forceLabel.setText(_translate("Generico", "0 Tonf")) self.forceLabel.setText(_translate("Generico", "0 Tonf"))
self.fileMenu.setTitle(_translate("Generico", "Arquivo")) self.fileMenu.setTitle(_translate("Generico", "Arquivo"))
self.stageMenu.setTitle(_translate("Generico", "Etapa")) self.stageMenu.setTitle(_translate("Generico", "Etapa"))
......
import sys import sys
from PyQt5 import QtWidgets, QtCore from PyQt5 import QtWidgets, QtCore
from PyQt5.QtCore import QTimer
from .GenericoW import Ui_Generico from .GenericoW import Ui_Generico
from threads.MainThread import MainThread from threads.MainThread import MainThread
...@@ -17,8 +18,9 @@ class Ui_MainWindow(object): ...@@ -17,8 +18,9 @@ class Ui_MainWindow(object):
self.ui.setupUi(self.dialog) self.ui.setupUi(self.dialog)
print(self.ui) print(self.ui)
main_thread = MainThread(self.ui)
#main_thread.finished.connect(self.app.exit)
#main_thread.start()
self.timer = QTimer(self.app)
self.main_thread = MainThread(self.ui, self.timer)
self.dialog.showMaximized() self.dialog.showMaximized()
#main_thread.finished.connect(self.app.exit)
#main_thread.start()
Markdown is supported
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