diff --git a/V0/legacy_plot_graph.py b/V0/legacy_plot_graph.py old mode 100644 new mode 100755 diff --git a/cage_controller.py b/cage_controller.py index e000e9a..d49086f 100755 --- a/cage_controller.py +++ b/cage_controller.py @@ -16,15 +16,15 @@ def __init__(self, port_device, input_delay=utils.INPUT_DELAY, baudrate=9600, pa def toggle_supply(self, mode): utils.log(0, 'Setting ' + self.name + ' active to: ' + str(mode)) - self.write("Aso" + mode + "\n") + self.write("Aso" + str(mode) + "\n") def set_voltage(self, voltage): utils.log(0, 'Setting ' + self.name + ' voltage to: ' + str(voltage) + ' volts.') - self.write("Asu" + voltage * 100 + "\n") + self.write("Asu" + str(voltage * 100) + "\n") def set_current(self, amperage): utils.log(0, 'Setting ' + self.name + ' current to: ' + str(amperage) + ' amps.') - self.write("Asi" + amps * 1000 + "\n") + self.write("Asi" + str(amps * 1000) + "\n") def check_temperatures(self): utils.log(0, 'Checking ' + self.name + ' temperatures...') diff --git a/graph.py b/graph.py index 270e6b9..3427bc2 100755 --- a/graph.py +++ b/graph.py @@ -1,63 +1,7 @@ import sys import pyqtgraph as pg -import numpy as np -import math import utilities as utils from PyQt5 import QtGui, QtCore -from PyQt5.QtCore import QTimer - -# Generate array of y = x numbers up to max -def generate_y_x_sequence(max): - y = [] - for i in range(0, max): - y.append(i) - return y - -def generate_horz_line(max, num): - y = [] - for i in range(0, max): - y.append(num) - return y - -# Generate array of 2^x numbers up to max -def generate_pow_2_x_sequence(max): - y =[] - for i in range(0, max): - y.append(math.pow(2,i)) - return y - -# Generate array of fibbonacci numbers up to max -def generate_fib_sequence(max): - y =[] - for i in range(0, max): - if(i <= 1): new_num = fibbonacci(i) - else: new_num = fibbonacci(i, j=(i-2), a=y[i - 2], b=y[i - 1]) - y.append(new_num) - return y - -def generate_sin_sequence(max): - y = [] - for i in range(0, max): - y.append(math.sin(i)) - return y - -def generate_cos_sequence(max): - y = [] - for i in range(0, max): - y.append(math.cos(i)) - return y - -# A simple function for generating numbers in the fibbonacci sequence -def fibbonacci(i, j=0, a=0, b=1): - if(i == 0): sum = 0 - elif(i == 1): sum = 1 - else: sum = a + b - - if(utils.DEBUG): utils.log(2, ("i: " + str(i) + "\tj: " + str(j), "\ta: " + str(a) + "\tb: " + str(b) + "\tsum: " + str(sum))) - - if(j < i): - sum = fibbonacci(i, (j + 1), a=b, b=sum) - return sum class Line(pg.PlotItem): def __init__(self, color='r', data=None, data_size=0, parent=None): @@ -73,14 +17,10 @@ class Graph(QtGui.QWidget): def __init__(self, parent, graph_range=utils.GRAPH_RANGE): QtGui.QWidget.__init__(self, parent=parent) self.resize(640, 640) - self.setWindowTitle('') self.counter = 0 self.graph_range = graph_range self.lines = [] - self.timer = QTimer() - self.timer.timeout.connect(self.tick) - self.timer.start(utils.TICK_TIME) self.layout = QtGui.QGridLayout() self.setLayout(self.layout) @@ -88,24 +28,17 @@ def __init__(self, parent, graph_range=utils.GRAPH_RANGE): self.plot = pg.PlotWidget(title='Magnetic Field Levels') self.layout.addWidget(self.plot) - self.button = QtGui.QPushButton('Add point', self) - self.button.clicked.connect(self.update_graph) - self.layout.addWidget(self.button, 2, 0) - - def tick(self): - self.update_graph() - def add_line(self, line): self.lines.append(line) def update_graph(self): self.counter += 1 - self.lines[0].data = generate_sin_sequence(self.counter) + self.lines[0].data = utils.generate_sin_sequence(self.counter) self.lines[0].data_size = self.counter - self.lines[1].data = generate_cos_sequence(self.counter) + self.lines[1].data = utils.generate_cos_sequence(self.counter) self.lines[1].data_size = self.counter - self.lines[2].data = generate_horz_line(self.counter, 1) + self.lines[2].data = utils.generate_horz_line(self.counter, 1) self.lines[2].data_size = self.counter self.plot.clear() @@ -116,22 +49,3 @@ def update_graph(self): for i in self.lines: self.plot.plot() self.plot.plot(i.data, pen=i.color) - -def main(): - utils.log(0, 'Graph demo') - app = pg.mkQApp() - - x = Line(color='r', data=generate_sin_sequence(1)) - y = Line(color='g', data=generate_cos_sequence(1)) - z = Line(color='b', data=generate_horz_line(1, 1)) - - graph = Graph(None) - graph.add_line(x) - graph.add_line(y) - graph.add_line(z) - graph.show() - - sys.exit(app.exec_()) - -if __name__ == '__main__': - main() diff --git a/img/icon.png b/img/icon.png new file mode 100755 index 0000000..ec1e86e Binary files /dev/null and b/img/icon.png differ diff --git a/utilities.py b/utilities.py index e38b691..6764e43 100755 --- a/utilities.py +++ b/utilities.py @@ -1,6 +1,8 @@ +import math + DEBUG = False TICK_TIME = 4 -GRAPH_RANGE = 10 +GRAPH_RANGE = 100 INPUT_DELAY = 0.2 POWER_SUPPLIES = [] PSU_ADDRS = [ 'ttyUSB0', 'ttyUSB1', 'ttyUSB2' ] @@ -30,5 +32,64 @@ def log(mode, message): except: return False +# Returns whether or not a power suplly has been initialized and added to the global list +# Used for safe checking and some error handling def supply_available(): return (len(POWER_SUPPLIES) > 0) + +# +# Math things +# + +# Generate array of y = x numbers up to max +def generate_y_x_sequence(max): + y = [] + for i in range(0, max): + y.append(i) + return y + +def generate_horz_line(max, num): + y = [] + for i in range(0, max): + y.append(num) + return y + +# Generate array of 2^x numbers up to max +def generate_pow_2_x_sequence(max): + y =[] + for i in range(0, max): + y.append(math.pow(2,i)) + return y + +# Generate array of fibbonacci numbers up to max +def generate_fib_sequence(max): + y =[] + for i in range(0, max): + if(i <= 1): new_num = fibbonacci(i) + else: new_num = fibbonacci(i, j=(i-2), a=y[i - 2], b=y[i - 1]) + y.append(new_num) + return y + +def generate_sin_sequence(max): + y = [] + for i in range(0, max): + y.append(math.sin(i)) + return y + +def generate_cos_sequence(max): + y = [] + for i in range(0, max): + y.append(math.cos(i)) + return y + +# A simple function for generating numbers in the fibbonacci sequence +def fibbonacci(i, j=0, a=0, b=1): + if(i == 0): sum = 0 + elif(i == 1): sum = 1 + else: sum = a + b + + if(utils.DEBUG): utils.log(2, ("i: " + str(i) + "\tj: " + str(j), "\ta: " + str(a) + "\tb: " + str(b) + "\tsum: " + str(sum))) + + if(j < i): + sum = fibbonacci(i, (j + 1), a=b, b=sum) + return sum diff --git a/window.py b/window.py index 1fd7f99..35eaab2 100755 --- a/window.py +++ b/window.py @@ -1,9 +1,11 @@ -from PyQt5 import QtCore, QtGui, QtWidgets +import sys import graph as g import utilities as utils import cage_controller as cc +from PyQt5 import QtCore, QtGui, QtWidgets +from PyQt5.QtCore import QTimer -class Ui_window(object): +class ControllerWindow(object): def setupUi(self, window): window.setObjectName("window") window.resize(640, 320) @@ -61,9 +63,9 @@ def setupUi(self, window): self.psu_3_label.setGeometry(QtCore.QRect(10, 105, 45, 20)) self.psu_3_label.setObjectName("psu_3_label") self.graph = g.Graph(self.widget) - self.graph.add_line(g.Line(color='r', data=g.generate_sin_sequence(1))) - self.graph.add_line(g.Line(color='g', data=g.generate_cos_sequence(1))) - self.graph.add_line(g.Line(color='b', data=g.generate_y_x_sequence(1))) + self.graph.add_line(g.Line(color='r')) + self.graph.add_line(g.Line(color='g')) + self.graph.add_line(g.Line(color='b')) self.graph.setGeometry(QtCore.QRect(300, 30, 320, 320)) self.graph.setAutoFillBackground(True) self.graph.setObjectName("graph") @@ -88,6 +90,10 @@ def setupUi(self, window): self.retranslateUi(window) QtCore.QMetaObject.connectSlotsByName(window) + self.timer = QTimer() + self.timer.timeout.connect(self.tick) + self.timer.start(utils.TICK_TIME) + def retranslateUi(self, window): _translate = QtCore.QCoreApplication.translate window.setWindowTitle(_translate("window", "Helmholtz Cage Controller")) @@ -108,6 +114,9 @@ def retranslateUi(self, window): self.save_graph_menu.setText(_translate("window", "Save Graph")) self.shut_down_menu.setText(_translate("window", "Shut Down Cage")) + def tick(self): + self.graph.update_graph() + def save_data(self): for i in range(0, 3): utils.log(0, str(self.graph.lines[i])) @@ -126,10 +135,9 @@ def update_power_supplies(self): utils.log(3, 'No supplies are available for updating!\n\tThrowing away button press event.') def interface(): - import sys app = QtWidgets.QApplication(sys.argv) window = QtWidgets.QMainWindow() - ui = Ui_window() + ui = ControllerWindow() ui.setupUi(window) window.show() sys.exit(app.exec_())