mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-15 14:22:11 +08:00
4012d181e1
date: 2024-03-17T10:14:38 master commit: 7e9a909e0e57ecb31df4c87c5b9a06b1204fd034
19 lines
449 B
Python
19 lines
449 B
Python
class FirstOrderFilter:
|
|
# first order filter
|
|
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
|