Files
sunnypilot/common/filter_simple.py
T
github-actions[bot] 94df4d1824 sunnypilot v2025.08.13-2695
version: sunnypilot v0.10.1 release
  date: 2025-08-13T14:04:40
  master commit: c490b3ca12
2025-08-13 14:04:40 +00:00

18 lines
426 B
Python

class FirstOrderFilter:
def __init__(self, x0, rc, dt, initialized=True):
self.x = x0
self.dt = dt
self.update_alpha(rc)
self.initialized = initialized
def update_alpha(self, rc):
self.alpha = self.dt / (rc + self.dt)
def update(self, x):
if self.initialized:
self.x = (1. - self.alpha) * self.x + self.alpha * x
else:
self.initialized = True
self.x = x
return self.x