-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtip_constantposition.py
More file actions
28 lines (21 loc) · 910 Bytes
/
tip_constantposition.py
File metadata and controls
28 lines (21 loc) · 910 Bytes
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
import numpy as np
class Minimal_Variance_Fusion:
def __init__(self, shape):
self.shape = shape
self.measurements = []
self.cov_matrix = np.eye(shape) * 0.04 # Initial cov-matrix as identity matrix
self.measurement_noise_matrix = (
np.eye(shape) * 0.04
) # Doesn't change (for updating cov-matrix later)
def reset(self, measurement):
self.measurements = [np.array(measurement)]
self.cov_matrix = np.eye(self.shape) * 0.04
return self.measurements[0]
def update(self, dt, measurement):
z = np.array(measurement)
self.measurements.append(z)
# New estimate x as the arithmetic mean of all measurements
self.x = np.mean(self.measurements, axis=0)
# Update covariance matrix
self.cov_matrix = self.measurement_noise_matrix / len(self.measurements)
return self.x