11import pytest
22
33import numpy as np
4+ from scipy .signal import resample_poly
45import smsfusion as sf
56from smsfusion import FixedIntervalSmoother
67from smsfusion .benchmark import (
@@ -29,11 +30,7 @@ def test__init__(self, ains):
2930 assert smoother .bias_acc ().size == 0
3031 assert smoother .bias_gyro ().size == 0
3132
32- @pytest .mark .parametrize (
33- "benchmark_gen" ,
34- [benchmark_full_pva_beat_202311A , benchmark_full_pva_chirp_202311A ],
35- )
36- def test_benchmark (self , benchmark_gen ):
33+ def test_benchmark (self ):
3734 fs_imu = 10.0
3835 fs_aiding = 1.0
3936 fs_ratio = np .ceil (fs_imu / fs_aiding )
@@ -43,7 +40,7 @@ def test_benchmark(self, benchmark_gen):
4340 vel_noise_std = 0.1
4441
4542 # Reference signals (without noise)
46- t , pos_ref , vel_ref , euler_ref , acc_ref , gyro_ref = benchmark_gen (fs_imu )
43+ t , pos_ref , vel_ref , euler_ref , acc_ref , gyro_ref = benchmark_full_pva_beat_202311A (fs_imu )
4744 euler_ref = np .degrees (euler_ref )
4845 gyro_ref = np .degrees (gyro_ref )
4946
@@ -55,7 +52,7 @@ def test_benchmark(self, benchmark_gen):
5552 noise_model = sf .noise .IMUNoise (err_acc , err_gyro , seed = 0 )
5653 imu_noise = noise_model (fs_imu , len (t ))
5754 acc_meas = acc_ref + imu_noise [:, :3 ]
58- gyro_meas = gyro_ref + imu_noise [:, 3 :]
55+ gyro_meas = gyro_ref + np . degrees ( imu_noise [:, 3 :])
5956
6057 # Compass / heading (aiding) measurements
6158 head_noise = compass_noise_std * rng .standard_normal (len (t ))
@@ -81,6 +78,7 @@ def test_benchmark(self, benchmark_gen):
8178
8279 smoother = FixedIntervalSmoother (ains , cov_smoothing = True )
8380
81+ pos_ains , vel_ains , euler_ains , bias_acc_ains , bias_gyro_ains = [], [], [], [], []
8482 for i , (acc_i , gyro_i , pos_i , vel_i , head_i ) in enumerate (
8583 zip (acc_meas , gyro_meas , pos_meas , vel_meas , head_meas )
8684 ):
@@ -101,3 +99,42 @@ def test_benchmark(self, benchmark_gen):
10199 )
102100 else : # without aiding
103101 smoother .update (acc_i , gyro_i , degrees = True )
102+
103+ pos_ains .append (smoother .ains .position ())
104+ vel_ains .append (smoother .ains .velocity ())
105+ euler_ains .append (smoother .ains .euler (degrees = True ))
106+ bias_acc_ains .append (smoother .ains .bias_acc ())
107+ bias_gyro_ains .append (smoother .ains .bias_gyro (degrees = True ))
108+
109+ pos_ains = np .array (pos_ains )
110+ vel_ains = np .array (vel_ains )
111+ euler_ains = np .array (euler_ains )
112+ bias_acc_ains = np .array (bias_acc_ains )
113+ bias_gyro_ains = np .array (bias_gyro_ains )
114+
115+ pos_smth = smoother .position ()
116+ vel_smth = smoother .velocity ()
117+ euler_smth = smoother .euler (degrees = True )
118+ bias_acc_smth = smoother .bias_acc ()
119+ bias_gyro_smth = smoother .bias_gyro (degrees = True )
120+
121+ pos_smth = np .array (pos_smth )
122+ vel_smth = np .array (vel_smth )
123+ euler_smth = np .array (euler_smth )
124+ bias_acc_smth = np .array (bias_acc_smth )
125+ bias_gyro_smth = np .array (bias_gyro_smth )
126+
127+ # Half-sample shift (compensates for the delay introduced by Euler integration)
128+ pos_ains = resample_poly (pos_ains , 2 , 1 )[1 :- 1 :2 ]
129+ pos_smth = resample_poly (pos_smth , 2 , 1 )[1 :- 1 :2 ]
130+ pos_ref = pos_ref [:- 1 , :]
131+ vel_ains = resample_poly (vel_ains , 2 , 1 )[1 :- 1 :2 ]
132+ vel_smth = resample_poly (vel_smth , 2 , 1 )[1 :- 1 :2 ]
133+ vel_ref = vel_ref [:- 1 , :]
134+ euler_ains = resample_poly (euler_ains , 2 , 1 )[1 :- 1 :2 ]
135+ euler_smth = resample_poly (euler_smth , 2 , 1 )[1 :- 1 :2 ]
136+ euler_ref = euler_ref [:- 1 , :]
137+
138+ pos_err_smth = np .std ((pos_smth - pos_ref )[warmup :], axis = 0 )
139+ pos_err_ains = np .std ((pos_ains - pos_ref )[warmup :], axis = 0 )
140+ assert pos_err_smth [0 ] < pos_err_ains [0 ]
0 commit comments