Skip to content

Commit 2e35a94

Browse files
test cov smoothing
1 parent c56aef1 commit 2e35a94

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

tests/test_smoothing.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,61 @@ def test_benchmark_vru(self):
262262

263263
smoother.P.shape == (len(acc_imu), 12, 12)
264264
np.testing.assert_array_less(err_smth[warmup:], err_ains[warmup:] + 1e-12)
265+
266+
def test_cov_smoothing(self):
267+
# Reference signal
268+
fs = 10.24 # sampling rate in Hz
269+
_, pos, vel, euler, acc, gyro = benchmark_full_pva_beat_202311A(fs)
270+
euler = np.degrees(euler)
271+
gyro = np.degrees(gyro)
272+
273+
# IMU measurements
274+
err_acc = sf.constants.ERR_ACC_MOTION2 # m/s^2
275+
err_gyro = sf.constants.ERR_GYRO_MOTION2 # rad/s
276+
imu_noise = sf.noise.IMUNoise(err_acc, err_gyro)(fs, len(acc))
277+
acc_imu = acc + imu_noise[:, :3]
278+
gyro_imu = gyro + np.degrees(imu_noise[:, 3:])
279+
280+
# AINS
281+
p0 = pos[0] # position [m]
282+
v0 = vel[0] # velocity [m/s]
283+
q0 = sf.quaternion_from_euler(euler[0], degrees=True) # unit quaternion
284+
ba0 = np.zeros(3) # accelerometer bias [m/s^2]
285+
bg0 = np.zeros(3) # gyroscope bias [rad/s]
286+
x0 = np.concatenate((p0, v0, q0, ba0, bg0))
287+
P0 = np.eye(12) * 1e-3
288+
err_acc = sf.constants.ERR_ACC_MOTION2 # m/s^2
289+
err_gyro = sf.constants.ERR_GYRO_MOTION2 # rad/s
290+
291+
ains_a = sf.VRU(fs, x0, P0, err_acc, err_gyro)
292+
smoother_a = sf.FixedIntervalSmoother(ains_a, cov_smoothing=True)
293+
ains_b = sf.VRU(fs, x0, P0, err_acc, err_gyro)
294+
smoother_b = sf.FixedIntervalSmoother(ains_b, cov_smoothing=False)
295+
296+
err_ains = []
297+
for f_i, w_i in zip(acc_imu, gyro_imu):
298+
smoother_a.update(
299+
f_i,
300+
w_i,
301+
degrees=True,
302+
)
303+
smoother_b.update(
304+
f_i,
305+
w_i,
306+
degrees=True,
307+
)
308+
309+
err_ains.append(smoother_a.ains.P.diagonal())
310+
311+
# Forward filter state estimates
312+
err_ains = np.array(err_ains)
313+
314+
# Smoothed state estimates
315+
err_smth_a = np.array([P_i.diagonal() for P_i in smoother_a.P])
316+
err_smth_b = np.array([P_i.diagonal() for P_i in smoother_b.P])
317+
318+
smoother_a.P.shape == (len(acc_imu), 12, 12)
319+
smoother_b.P.shape == (len(acc_imu), 12, 12)
320+
np.testing.assert_array_less(err_smth_a, err_ains + 1e-12)
321+
np.testing.assert_array_less(err_smth_a, err_smth_b + 1e-12)
322+
np.testing.assert_allclose(err_smth_b, err_ains)

0 commit comments

Comments
 (0)