Skip to content
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

Feature 45 - Depth Widget #47

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
3 changes: 3 additions & 0 deletions frontend/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def __init__(self, comms: Comms):
1020, 68, 1330, 378, fill=accent_color, outline=accent_color
)

depth_widget = DepthWidget((1030, 78), canvas)

thruster_widget = ThrustersWidget((1020, 406), canvas)

self.logo = PhotoImage(file="frontend/resources/logo.gif")
Expand All @@ -92,6 +94,7 @@ def __init__(self, comms: Comms):
"GyroscopeWidget": gyro_widget,
"PiConsoleWidget": console_widget,
"VideoWidget": video_widget,
"DepthWidget": depth_widget
}

def update_widget(self, widget_name: str, data: dict):
Expand Down
Binary file added frontend/resources/DepthGraph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 21 additions & 9 deletions frontend/widget/depth.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
from .widget import Widget
from PIL import Image, ImageTk
from collections import deque


class DepthWidget(Widget):

WIDTH = 250
HEIGHT = 350

# left corner of graph is approximately (left_x + 10, left_y-5)
# width of one block is approximately 58
# height of one meter is approximately 20

def __init__(self, left_corner, canvas):
self.left_x, self.left_y = left_corner
self.canvas = canvas
canvas.create_rectangle(
self.left_x,
self.left_y,
self.left_x + self.WIDTH,
self.left_y + self.HEIGHT,
fill="green",
outline="yellow",
self.graph = myGraph = ImageTk.PhotoImage(Image.open(
"frontend/resources/DepthGraph.png"
))
self.graph_id = canvas.create_image(
self.left_x + 145, self.left_y + 150, image=myGraph
)
self.q = deque(maxlen=5)
self.lines = []
for i in range(5):
self.lines.append(canvas.create_line(self.left_x + 10, self.left_y - 5, self.left_x + 10, self.left_y - 5,
fill="red", width=1.5))

def update(self, data: dict):
raise NotImplementedError
self.q.append(data["depth"])
if len(self.q) > 1:
for k in range(len(self.q) - 1):
self.canvas.coords(self.lines[k], self.left_x + 10 + (58 * k), self.left_y - 5 + (self.q[k] * 20),
self.left_x + 10 + (58 * (k + 1)), self.left_y - 5 + (self.q[k + 1] * 20))
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Pillow
appdirs==1.4.3
attrs==19.3.0
black==19.10b0
Expand Down