FrogPilot community - Moving Average Calculator

Co-Authored-By: Efini <19368997+efini@users.noreply.github.com>
Co-Authored-By: Kumar <36933347+rav4kumar@users.noreply.github.com>
This commit is contained in:
FrogAi
2024-06-07 06:16:18 -07:00
parent 7e9af01657
commit 316c5decd6
2 changed files with 20 additions and 0 deletions
@@ -182,3 +182,22 @@ def uninstall_frogpilot():
run_cmd(copy_cmd, "Successfully restored the original boot logo.", "Failed to restore the original boot logo.")
HARDWARE.uninstall()
class MovingAverageCalculator:
def __init__(self):
self.reset_data()
def add_data(self, value):
if len(self.data) == 5:
self.total -= self.data.pop(0)
self.data.append(value)
self.total += value
def get_moving_average(self):
if len(self.data) == 0:
return None
return self.total / len(self.data)
def reset_data(self):
self.data = []
self.total = 0
@@ -8,6 +8,7 @@ from openpilot.system.version import get_build_metadata
CITY_SPEED_LIMIT = 25 # 55mph is typically the minimum speed for highways
CRUISING_SPEED = 5 # Roughly the speed cars go when not touching the gas while in drive
PROBABILITY = 0.6 # 60% chance of condition being true
class FrogPilotVariables:
def __init__(self):