-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiltering.py
28 lines (22 loc) · 869 Bytes
/
filtering.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
# Low pass filter to filter the joystick inputs - avoid the noisy inputs due to small scale fluctuations
import numpy as np
class LowPassFilter:
def __init__(self, alpha):
self.alpha = alpha # Smoothing factor, 0 < alpha < 1
self.state = None
def update(self, input_value):
if self.state is None:
self.state = input_value
else:
self.state = self.alpha * input_value + (1 - self.alpha) * self.state
return self.state
def input_filtering(U):
# Define filters for each joystick axis
phi_filter = LowPassFilter(alpha=0.1)
theta_filter = LowPassFilter(alpha=0.1)
psi_filter = LowPassFilter(alpha=0.1)
phi = phi_filter.update(U[0])
theta = theta_filter.update(U[1])
psi = psi_filter.update(U[2])
U_filtered = np.array([phi, theta, psi, U[3]])
return U_filtered