From 316c5decd6ad068bb1cf41f464f0d2332fe4af5d Mon Sep 17 00:00:00 2001 From: FrogAi <91348155+FrogAi@users.noreply.github.com> Date: Fri, 7 Jun 2024 06:16:18 -0700 Subject: [PATCH] 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> --- .../controls/lib/frogpilot_functions.py | 19 +++++++++++++++++++ .../controls/lib/frogpilot_variables.py | 1 + 2 files changed, 20 insertions(+) diff --git a/selfdrive/frogpilot/controls/lib/frogpilot_functions.py b/selfdrive/frogpilot/controls/lib/frogpilot_functions.py index ae3f78e24..0c8210161 100644 --- a/selfdrive/frogpilot/controls/lib/frogpilot_functions.py +++ b/selfdrive/frogpilot/controls/lib/frogpilot_functions.py @@ -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 diff --git a/selfdrive/frogpilot/controls/lib/frogpilot_variables.py b/selfdrive/frogpilot/controls/lib/frogpilot_variables.py index f5b097c87..cd23e228c 100644 --- a/selfdrive/frogpilot/controls/lib/frogpilot_variables.py +++ b/selfdrive/frogpilot/controls/lib/frogpilot_variables.py @@ -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):