-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUI.py
303 lines (252 loc) · 10.9 KB
/
GUI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
import tkinter as tk
from tkinter import ttk
from tkinter import *
from PIL import Image
from PIL import ImageTk
from itertools import count
import pandas as pd
#from cartopy import config
#import cartopy.crs as ccrs
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from matplotlib.figure import Figure
from matplotlib.animation import FuncAnimation
import time, sys, struct, copy, os#, serial
#import decoder_rrc_v2_2
#ser = serial.Serial('/dev/ttyACM0', 9600) # change for actual devices
#decoder_rrc_v2_2()
#Screensize
window = Tk()
window.resizable(0, 0) # this prevents from resizing the window
window.title("Ground Station GUI")
window.configure(background='LightSkyBlue1')
screenX = 800
screenY = 500
#Styles
COLOR1 = 'LightSkyBlue1'
COLOR2 = 'light goldenrod'
COLOR3 = 'blue'
s = ttk.Style()
s.configure('RRC.Label', background=COLOR1, anchor="center")
s.configure('RRC2.Label', background=COLOR2, anchor="center")
s.configure('RRC.TPanedwindow', background=COLOR1)
s.configure('RRC2.TPanedwindow', background=COLOR2)
s.configure('RRC3.TPanedwindow', background=COLOR3)
s.configure('RRC.TNotebook', background=COLOR3, bordercolor=COLOR3)
# Import the Notebook.tab element from the default theme
s.element_create('Plain.Notebook.tab', "from", 'default')
# Redefine the TNotebook Tab layout to use the new element
s.layout("TNotebook.Tab",
[('Plain.Notebook.tab', {'children':
[('Notebook.padding', {'side': 'top', 'children':
[('Notebook.focus', {'side': 'top', 'children':
[('Notebook.label', {'side': 'top', 'sticky': ''})],
'sticky': 'nswe'})],
'sticky': 'nswe'})],
'sticky': 'nswe'})])
s.configure("TNotebook.Tab", background=COLOR2)
#organization = toolbar[options], window[data notebook[overview, graphs], map, logo],statusbar
window.panes = tk.ttk.PanedWindow(orient="vertical", width = screenX, height=screenY,style="RRC2.TPanedwindow")
panes = window.panes
panes.pack(fill="both",expand=1)
#toolbar = tk.PanedWindow(panes, orient="horizontal")
#options = tk.Button(toolbar, text="options")
#toolbar.add(options)
#options2 = tk.Button(toolbar, text="options")
#toolbar.add(options2)
#options3 = tk.Button(toolbar, text="options")
#toolbar.add(options3)
#optionsEmpty = tk.Label(toolbar) #Without this the buttons will stretch to fill the space
#toolbar.add(optionsEmpty)
#panes.add(toolbar,minsize=25)
interface = tk.ttk.PanedWindow(panes, orient="horizontal", height=475, style="RRC3.TPanedwindow")
data = tk.ttk.Notebook(interface, style="RRC.TNotebook", width=400)
overview = tk.ttk.PanedWindow(data, orient="horizontal", style="RRC.TPanedwindow")
overview1 = tk.ttk.PanedWindow(overview, orient="vertical", width=200,style="RRC.TPanedwindow")
latitudeLabel = ttk.Label(overview1, text="Latitude",style="RRC.Label")
overview1.add(latitudeLabel)
latitude = ttk.Label(overview1, text="0.0",style="RRC.Label")
overview1.add(latitude)
longitudeLabel = ttk.Label(overview1, text="Longitude",style="RRC.Label")
overview1.add(longitudeLabel)
longitude = ttk.Label(overview1, text="0.0",style="RRC.Label")
overview1.add(longitude)
temperatureLabel = ttk.Label(overview1, text="Temperature",style="RRC.Label")
overview1.add(temperatureLabel)
temperature = ttk.Label(overview1, text="0",style="RRC.Label")
overview1.add(temperature)
pressureLabel = ttk.Label(overview1, text="Pressure",style="RRC.Label")
overview1.add(pressureLabel)
pressure = ttk.Label(overview1, text="0.0",style="RRC.Label")
overview1.add(pressure)
flighttimeLabel = ttk.Label(overview1, text="Flight Time",style="RRC.Label")
overview1.add(flighttimeLabel)
flighttime = ttk.Label(overview1, text="0",style="RRC.Label")
overview1.add(flighttime)
spacer1 = ttk.Label(overview1, text="",style="RRC.Label")
overview1.add(spacer1)
overview.add(overview1)
overview2 = tk.ttk.PanedWindow(overview, orient="vertical",style="RRC.TPanedwindow")
speedLabel = ttk.Label(overview2, text="Speed",style="RRC.Label")
overview2.add(speedLabel)
speed = ttk.Label(overview2, text="0",style="RRC.Label")
overview2.add(speed)
altitudeLabel = ttk.Label(overview2, text="Altitude",style="RRC.Label")
overview2.add(altitudeLabel)
altitude = ttk.Label(overview2, text="0",style="RRC.Label")
overview2.add(altitude)
accelxLabel = ttk.Label(overview2, text="AccelX",style="RRC.Label")
overview2.add(accelxLabel)
accelx = ttk.Label(overview2, text="0",style="RRC.Label")
overview2.add(accelx)
accelyLabel = ttk.Label(overview2, text="AccelY",style="RRC.Label")
overview2.add(accelyLabel)
accely = ttk.Label(overview2, text="0",style="RRC.Label")
overview2.add(accely)
accelzLabel = ttk.Label(overview2, text="AccelZ",style="RRC.Label")
overview2.add(accelzLabel)
accelz = ttk.Label(overview2, text="0",style="RRC.Label")
overview2.add(accelz)
spacer2 = ttk.Label(overview2, text="",style="RRC.Label")
overview2.add(spacer2)
overview.add(overview2)
data.add(overview, text="Overview")
#Atmospheric Data
x = [0]
y = [0]
index = count()
atmos = tk.PanedWindow(data, orient="vertical")
pressureGraph = tk.Frame(atmos)
plt.ion()
pressureFigure = plt.figure(figsize=(3,3), dpi=100)
pressurePlot = pressureFigure.add_subplot(111)
pressurePlot.plot(x,y)
pressureCanvas = FigureCanvasTkAgg(pressureFigure, pressureGraph)
pressureCanvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
atmos.add(pressureGraph)
data.add(atmos, text="Pressure")
atmos2 = tk.PanedWindow(data, orient="vertical")
temperatureGraph = tk.Frame(atmos2)
plt.ion()
temperatureFigure = plt.figure(figsize=(3,3), dpi=100)
temperaturePlot = temperatureFigure.add_subplot(111)
temperaturePlot.plot(x,y)
temperatureCanvas = FigureCanvasTkAgg(temperatureFigure, temperatureGraph)
temperatureCanvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
atmos2.add(temperatureGraph)
data.add(atmos2, text="Temperature")
#Flight data
flightdata = tk.PanedWindow(data, orient="vertical")
altitudeGraph = tk.Frame(flightdata)
plt.ion()
altitudeFigure = plt.figure(figsize=(3,3), dpi=100)
altitudePlot = altitudeFigure.add_subplot(111)
altitudePlot.plot(x,y)
altitudeCanvas = FigureCanvasTkAgg(altitudeFigure, altitudeGraph)
altitudeCanvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
flightdata.add(altitudeGraph)
data.add(flightdata, text="Altitude")
flightdata2 = tk.PanedWindow(data, orient="vertical")
speedGraph = tk.Frame(flightdata2)
plt.ion()
speedFigure = plt.figure(figsize=(3,3), dpi=100)
speedPlot = speedFigure.add_subplot(111)
speedPlot.plot(x,y)
speedCanvas = FigureCanvasTkAgg(speedFigure, speedGraph)
speedCanvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
flightdata2.add(speedGraph)
data.add(flightdata2, text="Speed")
#Acceleration
accel = tk.PanedWindow(data, orient="vertical")
accelGraph = tk.Frame(accel)
plt.ion()
accelFigure = plt.figure(figsize=(3,3), dpi=100)
accelPlot = accelFigure.add_subplot(111)
accelPlot.plot(x,y)
accelCanvas = FigureCanvasTkAgg(accelFigure, accelGraph)
accelCanvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
accel.add(accelGraph)
data.add(accel, text="Acceleration")
interface.add(data)
rightInterface = tk.ttk.PanedWindow(interface, orient="vertical", width=400, style="RRC.TPanedwindow")
gpsBackground = tk.Frame(rightInterface, height=300)
gps = plt.figure(figsize=(3, 4))
fname = "Images/Large_Map.png"
img_extent = (-106.967445, -106.858726, 32.925260, 32.979024)
img = plt.imread(fname)
'''
ax = plt.axes(projection=ccrs.PlateCarree())
ax.imshow(img, origin='upper', extent=img_extent, transform=ccrs.PlateCarree())
'''
gpsCanvas = FigureCanvasTkAgg(gps, gpsBackground)
gpsCanvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
rightInterface.add(gpsBackground)
'''
ax.plot([-106.967445, -106.858726], [32.925260, 32.979024],
color='blue', linewidth=2, marker='o',
transform=ccrs.Geodetic(),
)
'''
belowGPS = tk.ttk.PanedWindow(rightInterface, orient="horizontal",height=300, style="RRC.TPanedwindow")
belowGPSData = tk.ttk.PanedWindow(belowGPS, orient="vertical", width=290, style="RRC.TPanedwindow")
clock = ttk.Label(belowGPSData, text="current time",style="RRC.Label")
time_string = time.strftime('%H:%M:%S')
clock.config(text=time_string)
belowGPSData.add(clock)
altitudeGroup = tk.ttk.PanedWindow(belowGPSData, orient="horizontal", style="RRC.TPanedwindow")
altitudeLabel2 = ttk.Label(belowGPSData, text="Altitude", width=20, justify="center", style="RRC.Label")
altitudeGroup.add(altitudeLabel2)
altitude2 = ttk.Label(belowGPSData, text="0",style="RRC.Label")
altitudeGroup.add(altitude2)
belowGPSData.add(altitudeGroup)
speedGroup = tk.ttk.PanedWindow(belowGPSData, orient="horizontal", style="RRC.TPanedwindow")
speedLabel2 = ttk.Label(belowGPSData, text="Speed", width=20, justify="center", style="RRC.Label")
speedGroup.add(speedLabel2)
speed2 = ttk.Label(belowGPSData, text="0",style="RRC.Label")
speedGroup.add(speed2)
belowGPSData.add(speedGroup)
spacer3 = ttk.Label(belowGPSData, text="",style="RRC.Label")
belowGPSData.add(spacer3)
belowGPS.add(belowGPSData)
logo = ImageTk.PhotoImage(Image.open('Images/logo.png').resize((80, 80), Image.ANTIALIAS)) #loads image
logoElement = tk.ttk.Label(belowGPS, text="logo",image=logo, background=COLOR1) #actually adds the image
logoElement.image = logo #for some reason, needs this to actually render
belowGPS.add(logoElement)
rightInterface.add(belowGPS)
interface.add(rightInterface)
panes.add(interface)
statusBar = tk.ttk.PanedWindow(panes, orient="horizontal", height=15, style="RRC2.TPanedwindow")
errors = tk.ttk.Label(statusBar, text="errors", style="RRC2.Label")
statusBar.add(errors)
indicators = tk.ttk.Label(statusBar, text="indicators", style="RRC2.Label")
statusBar.add(indicators)
panes.add(statusBar)
def tick():
time_string = time.strftime('%H:%M:%S')
clock.config(text=time_string)
def dataUpdate(i):
if (ser.in_waiting > 0):
#print(ser.readline())
x.append(next(index))
y.append( ser.readline())
#print(y[nextX])
#print(nextX)
if nextX%100 == 0: #Take this out if updates slow down.
pressureFigure.canvas.draw()
pressurePlot.cla()
pressurePlot.plot(x,y)
def testUpdate(i):
data = pd.read_csv('data.csv')
x = data['x_value']
y = data['total_1']
latitude = data['Latitude']
longitude = data['Longitude']
pressurePlot.cla()
pressurePlot.plot(x,y)
#ax.plot(latitude,longitude) #Change so it doesn't stack lines, .cla() clears image as well so it doesn't work unless that is reloaded each time.
ani = FuncAnimation(plt.gcf(), testUpdate, interval=1000)
#while 1: # Replace with while in focus?
#tick()
#window.update()
#dataUpdate(nextX) #Write backup every 5? minuntes
#getSerial()