@@ -33,34 +33,49 @@ const int k_desired_scale_sample_count = 1000;
33
33
// -- definitions -----
34
34
struct GyroscopeNoiseSamples
35
35
{
36
- PSMVector3f omega_samples[k_desired_noise_sample_count];
36
+ PSMVector3i raw_gyro_samples[k_desired_noise_sample_count];
37
+ PSMVector3f calibrated_omega_samples[k_desired_noise_sample_count];
37
38
PSMVector3f drift_rotation;
38
39
std::chrono::time_point<std::chrono::high_resolution_clock> sampleStartTime;
39
40
int sample_count;
40
41
41
- float variance; // Max sensor variance (raw_sensor_units/s/s for DS4, rad/s/s for PSMove)
42
- float drift; // Max drift rate (raw_sensor_units/s for DS4, rad/s for PSMove)
42
+ PSMVector3f raw_bias; // The average bias in the raw gyro measurement per frame
43
+ float angular_drift_variance; // Max sensor variance (raw_sensor_units/s/s for DS4, rad/s/s for PSMove)
44
+ float angular_drift_rate; // Max drift rate (raw_sensor_units/s for DS4, rad/s for PSMove)
43
45
44
46
void clear ()
45
47
{
46
48
drift_rotation= *k_psm_float_vector3_zero;
47
49
sample_count= 0 ;
48
- variance= 0 .f ;
49
- drift= 0 .f ;
50
+ raw_bias= *k_psm_float_vector3_zero;
51
+ angular_drift_variance= 0 .f ;
52
+ angular_drift_rate= 0 .f ;
50
53
}
51
54
52
55
void computeStatistics (std::chrono::duration<float , std::milli> sampleDurationMilli)
53
56
{
54
57
const float sampleDurationSeconds= sampleDurationMilli.count () / 1000 .f ;
55
58
const float N = static_cast <float >(sample_count);
56
59
60
+ // Compute the mean of the raw gyro measurements
61
+ // If this is a non-zero value then the gyro has some per frame
62
+ // bias we need to subtract off.
63
+ raw_bias= *k_psm_float_vector3_zero;
64
+ for (int sample_index = 0 ; sample_index < sample_count; sample_index++)
65
+ {
66
+ PSMVector3f raw_sample= PSM_Vector3iCastToFloat (&raw_gyro_samples[sample_index]);
67
+
68
+ raw_bias= PSM_Vector3fAdd (&raw_bias, &raw_sample);
69
+ }
70
+ raw_bias= PSM_Vector3fUnsafeScalarDivide (&raw_bias, N);
71
+
57
72
// Compute the mean of the error samples, where "error" = abs(omega_sample)
58
- // If we took the mean of the signed omega samples we'd get a value very
59
- // close to zero since the the gyro at rest over a short period has mean-zero noise
73
+ // If the gyro has little to no bias then the mean of the signed omega samples
74
+ // would be very close to zero since the the gyro at rest over a short period has mean-zero noise
60
75
PSMVector3f mean_omega_error= *k_psm_float_vector3_zero;
61
76
for (int sample_index = 0 ; sample_index < sample_count; sample_index++)
62
77
{
63
- PSMVector3f error_sample= PSM_Vector3fAbs (&omega_samples [sample_index]);
78
+ PSMVector3f error_sample= PSM_Vector3fAbs (&calibrated_omega_samples [sample_index]);
64
79
65
80
mean_omega_error= PSM_Vector3fAdd (&mean_omega_error, &error_sample);
66
81
}
@@ -70,7 +85,7 @@ struct GyroscopeNoiseSamples
70
85
PSMVector3f var_omega= *k_psm_float_vector3_zero;
71
86
for (int sample_index = 0 ; sample_index < sample_count; sample_index++)
72
87
{
73
- PSMVector3f error_sample= PSM_Vector3fAbs (&omega_samples [sample_index]);
88
+ PSMVector3f error_sample= PSM_Vector3fAbs (&calibrated_omega_samples [sample_index]);
74
89
PSMVector3f diff_from_mean= PSM_Vector3fSubtract (&error_sample, &mean_omega_error);
75
90
PSMVector3f diff_from_mean_sqrd= PSM_Vector3fSquare (&diff_from_mean);
76
91
@@ -79,12 +94,12 @@ struct GyroscopeNoiseSamples
79
94
var_omega= PSM_Vector3fUnsafeScalarDivide (&var_omega, N - 1 );
80
95
81
96
// Use the max variance of all three axes (should be close)
82
- variance = PSM_Vector3fMaxValue (&var_omega);
97
+ angular_drift_variance = PSM_Vector3fMaxValue (&var_omega);
83
98
84
99
// Compute the max drift rate we got across a three axis
85
100
PSMVector3f drift_rate= PSM_Vector3fUnsafeScalarDivide (&drift_rotation, sampleDurationSeconds);
86
101
PSMVector3f drift_rate_abs= PSM_Vector3fAbs (&drift_rate);
87
- drift = PSM_Vector3fMaxValue (&drift_rate_abs);
102
+ angular_drift_rate = PSM_Vector3fMaxValue (&drift_rate_abs);
88
103
}
89
104
};
90
105
@@ -274,7 +289,8 @@ void AppStage_GyroscopeCalibration::update()
274
289
// Record the next noise sample
275
290
if (m_gyroNoiseSamples->sample_count < k_desired_noise_sample_count)
276
291
{
277
- m_gyroNoiseSamples->omega_samples [m_gyroNoiseSamples->sample_count ]= m_lastCalibratedGyroscope;
292
+ m_gyroNoiseSamples->raw_gyro_samples [m_gyroNoiseSamples->sample_count ]= m_lastRawGyroscope;
293
+ m_gyroNoiseSamples->calibrated_omega_samples [m_gyroNoiseSamples->sample_count ]= m_lastCalibratedGyroscope;
278
294
++m_gyroNoiseSamples->sample_count ;
279
295
}
280
296
@@ -286,8 +302,9 @@ void AppStage_GyroscopeCalibration::update()
286
302
287
303
// Update the gyro config on the service
288
304
request_set_gyroscope_calibration (
289
- m_gyroNoiseSamples->drift ,
290
- m_gyroNoiseSamples->variance );
305
+ m_gyroNoiseSamples->raw_bias ,
306
+ m_gyroNoiseSamples->angular_drift_rate ,
307
+ m_gyroNoiseSamples->angular_drift_variance );
291
308
292
309
setState (eCalibrationMenuState::measureComplete);
293
310
}
@@ -714,6 +731,7 @@ void AppStage_GyroscopeCalibration::handle_tracking_space_settings_response(
714
731
}
715
732
716
733
void AppStage_GyroscopeCalibration::request_set_gyroscope_calibration (
734
+ const PSMVector3f &raw_bias,
717
735
const float drift,
718
736
const float variance)
719
737
{
@@ -725,6 +743,9 @@ void AppStage_GyroscopeCalibration::request_set_gyroscope_calibration(
725
743
726
744
calibration->set_controller_id (m_controllerView->ControllerID );
727
745
746
+ calibration->mutable_raw_bias ()->set_i (raw_bias.x );
747
+ calibration->mutable_raw_bias ()->set_j (raw_bias.y );
748
+ calibration->mutable_raw_bias ()->set_k (raw_bias.z );
728
749
calibration->set_drift (drift);
729
750
calibration->set_variance (variance);
730
751
calibration->set_gyro_gain_setting (" " ); // keep existing gain
0 commit comments