diff --git a/frontend/dashboard.py b/frontend/dashboard.py index 658770e..5114019 100644 --- a/frontend/dashboard.py +++ b/frontend/dashboard.py @@ -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") @@ -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): diff --git a/frontend/resources/DepthGraph.png b/frontend/resources/DepthGraph.png new file mode 100644 index 0000000..3527e4e Binary files /dev/null and b/frontend/resources/DepthGraph.png differ diff --git a/frontend/widget/depth.py b/frontend/widget/depth.py index 7bbf933..6d10c76 100644 --- a/frontend/widget/depth.py +++ b/frontend/widget/depth.py @@ -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)) diff --git a/requirements.txt b/requirements.txt index 55d0672..793aaea 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +Pillow appdirs==1.4.3 attrs==19.3.0 black==19.10b0