-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathguisuspension.py
98 lines (77 loc) · 3.41 KB
/
guisuspension.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
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 13 15:16:10 2022
@author: RTB
"""
import tkinter
import tkinter.ttk
from collections import deque
import statistics
import constants
import math
TIRES = ['FL', 'FR', 'RL', 'RR']
class Suspension ():
def __init__ (self, maxlen=60):
self.maxlen=maxlen
self.min = 999
self.max = 0
self.avg = deque(maxlen=self.maxlen)
self.cur = 0
self.min_var = tkinter.StringVar()
self.max_var = tkinter.StringVar()
self.cur_var = tkinter.StringVar()
self.avg_var = tkinter.StringVar()
self.reset()
def reset(self):
self.min = 999
self.max = 0
self.avg.extend([0]*self.maxlen)
self.cur = 0
self.min_var.set(" 0.00")
self.max_var.set(" 0.00")
self.cur_var.set(" 0.00")
self.avg_var.set(" 0.00")
class GUISuspension:
def __init__(self, logger, *args, **kwargs):
self.logger = logger
self.suspension = {x:Suspension() for x in TIRES}
def display(self):
for x in TIRES:
tire = self.suspension[x]
tire.min_var.set(f"{tire.min*100: >2.2f}")
tire.max_var.set(f"{tire.max*100: >2.2f}")
tire.avg_var.set(f"{statistics.mean(tire.avg)*100: >2.2f}")
tire.cur_var.set(f"{tire.cur*100: >2.2f}")
def update(self, fdp):
if fdp.is_race_on == 0:
return
for x in TIRES:
tire = self.suspension[x]
val = getattr(fdp, f"suspension_travel_meters_{x}")
tire.min = min(tire.min, val)
tire.max = max(tire.max, val)
tire.cur = val
tire.avg.append(val)
def set_canvas(self, frame):
self.frame = tkinter.Frame(frame, border=0, bg=constants.background_color, relief="groove",
highlightthickness=True, highlightcolor=constants.text_color)
opts = {'bg':constants.background_color, 'fg':constants.text_color, 'font':('Helvetica 12 bold')}
tkinter.Label(self.frame, text="Suspension (cm)", **opts).grid(row=1, columnspan=6)
tkinter.Label(self.frame, text="extend", **opts).grid(row=2, column=1, columnspan=2)
tkinter.Label(self.frame, text="avg (1s)", **opts).grid(row=2, column=4, columnspan=2)
tkinter.Label(self.frame, text="compression", **opts).grid(row=5, column=1, columnspan=2)
tkinter.Label(self.frame, text="current", **opts).grid(row=5, column=4, columnspan=2)
opts.update({'justify':tkinter.RIGHT, 'anchor': tkinter.E,
'font':('Helvetica 14 bold italic'), 'width': 6})
# min avg
# max cur
for i, x in enumerate(TIRES):
row = int(i/2)+3
column = i%2 + 1
tkinter.Label(self.frame, textvariable=self.suspension[x].min_var, **opts).grid(row=row, column=column)
tkinter.Label(self.frame, textvariable=self.suspension[x].max_var, **opts).grid(row=row+3, column=column)
tkinter.Label(self.frame, textvariable=self.suspension[x].avg_var, **opts).grid(row=row, column=column+3)
tkinter.Label(self.frame, textvariable=self.suspension[x].cur_var, **opts).grid(row=row+3, column=column+3)
def reset(self):
for x in TIRES:
self.suspension[x].reset()