Skip to content

Created GUI layout and real time graph generator #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions GUI/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__author__ = 'sherryliao_1'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this file serve a purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. init.py is required for indexing python projects. So it is needed for things like import.

61 changes: 61 additions & 0 deletions GUI/graphGenerator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
__author__ = 'sherryliao_1'

import numpy
import matplotlib
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import threading

##
# Graph
#
# Creates a constant time graph
#
# adapted from http://hardsoftlucid.wordpress.com/various-stuff/realtime-plotting/
#
# Note: Dependencies needed include numpy, matplotlib.
##

class Graph(object):
def __init__(self, title, xLabel, yLabel, yMin, yMax, root):
# configure graph details
self.xAchse = numpy.arange(0, 100, 1)
self.yAchse = numpy.array([0]*100)
self.yMin = yMin
self.yMax = yMax
self.fig = matplotlib.figure.Figure((3,3))
self.ax = self.fig.add_subplot(111)
self.ax.grid(True)
self.ax.set_title(title)
self.ax.set_xlabel(xLabel)
self.ax.set_ylabel(yLabel)
self.line1 = self.ax.plot(self.xAchse, self.yAchse, '-')

# configure values for graph to display
self.values = [0 for x in range(100)]

# configure parent object and canvas
self.parent = root
self.canvas = FigureCanvasTkAgg(self.fig, master=root)

# bind event listener for updating data TODO: needs to listen to data from arduino
self.fig.canvas.mpl_connect('key_press_event', self.dataInputHandler)

# listens to input from keyboard and adds input value to array for plotting
def dataInputHandler(self, event):
if event.key in ['0','1','2','3','4','5','6','7','8','9']:
self.values.append(event.key)

# keeps data moving at constant time, fills in "0" for input if no new data is available
def inputGenerator(self):
self.values.append(0)
self.parent.after(50, self.inputGenerator)

# plot the values to graph
def realTimePlotter(self):
numVisibleDataPoints = min(len(self.values), 1000)
currentXAxis = numpy.arange(len(self.values) - numVisibleDataPoints, len(self.values), 1)

self.line1[0].set_data(currentXAxis, numpy.array(self.values[-numVisibleDataPoints:]))
self.ax.axis([currentXAxis.min(), currentXAxis.max(), self.yMin, self.yMax])
self.canvas.draw()
self.parent.after(50, self.realTimePlotter)
55 changes: 55 additions & 0 deletions GUI/tkGUI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
__author__ = 'sherryliao_1'


from Tkinter import *
from PIL import ImageTk, Image
import graphGenerator as gg

# initialize frame
root = Tk()
root.wm_title("Robotics UI")

# initialize graphs
sgGraph = gg.Graph("Strain Gauge", "Time", "Force", 0, 10, root)

# <------------------fill up GUI-------------------------->
# _______________________________________________
# | | |
# | Const.Image | Map |
# | | |
# |__________________|___________________________|
# | | |
# | | |
# | State Machine | Graphs |
# | | |
# |__________________|___________________________|
#
# <------------------------------------------------------->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this comment.


# add picture of what robot sees
path = '../pictureLibrary/rover.jpg' #TODO - this must be updated to the picture taken by cam
constantTimeImage = ImageTk.PhotoImage(Image.open(path))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should research whether or not the ImageTk images are compatible with OpenCV images, or if we'll have to convert.

label = Label(image=constantTimeImage)
label.image = constantTimeImage
label.grid(row=0, columnspan=2)

# add map of where robot thinks it is
mapPath = '../pictureLibrary/rover2.jpg' #TODO - this must be updated draw image from sensor data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We maybe want to rename this to "map_placeholder.jpg" or something similar / more accurate / more descriptive?

mapImage = ImageTk.PhotoImage(Image.open(mapPath))
label2 = Label(image=mapImage)
label2.image = mapImage
label2.grid(row=0, column=2, columnspan=4, sticky=W+E+N+S)

# add state machine information
label3 = Label(root, text="State machine information")
label3.grid(row=1, column=0, columnspan=2, sticky=W+E+N+S)

# draw strain gauge graph
sgGraph.canvas.show()
sgGraph.canvas.get_tk_widget().grid(row=1, column=2, columnspan=2, sticky=W+E+N+S)

# update graphs
root.after(50, sgGraph.inputGenerator)
root.after(50, sgGraph.realTimePlotter)

mainloop()
4 changes: 4 additions & 0 deletions pictureLibrary/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__author__ = 'sherryliao_1'



Binary file added pictureLibrary/rover.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictureLibrary/rover2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.