Skip to content

Commit

Permalink
moved things, cleaned things.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitri-mcguckin committed Apr 25, 2019
1 parent ee39bd2 commit debccbb
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 100 deletions.
Empty file modified V0/legacy_plot_graph.py
100644 → 100755
Empty file.
6 changes: 3 additions & 3 deletions cage_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...')
Expand Down
92 changes: 3 additions & 89 deletions graph.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -73,39 +17,28 @@ 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)

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()
Expand All @@ -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()
Binary file added img/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 62 additions & 1 deletion utilities.py
Original file line number Diff line number Diff line change
@@ -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' ]
Expand Down Expand Up @@ -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
22 changes: 15 additions & 7 deletions window.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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")
Expand All @@ -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"))
Expand All @@ -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]))
Expand All @@ -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_())

0 comments on commit debccbb

Please sign in to comment.