@@ -465,7 +465,17 @@ bool pbio_imu_is_stationary(void) {
465465static bool pbio_imu_stationary_acceleration_out_of_range (float value , bool expect_positive ) {
466466 const float expected_value = expect_positive ? standard_gravity : - standard_gravity ;
467467 const float absolute_error = value > expected_value ? value - expected_value : expected_value - value ;
468- return absolute_error > standard_gravity / 15 ;
468+ return absolute_error > standard_gravity / 10 ;
469+ }
470+
471+ /**
472+ * Tests if a value is close to 360 degrees.
473+ *
474+ * @param [in] value The value to test.
475+ * @return True if the value is within +/-15 degrees of 360, false otherwise.
476+ */
477+ static bool pbio_imu_setting_close_to_360 (float value ) {
478+ return pbio_geometry_absf (value - 360.0f ) < 15.0f ;
469479}
470480
471481/**
@@ -501,7 +511,7 @@ pbio_error_t pbio_imu_set_settings(pbio_imu_persistent_settings_t *new_settings)
501511 }
502512
503513 if (new_settings -> flags & PBIO_IMU_SETTINGS_FLAGS_GYRO_SCALE_SET ) {
504- if (new_settings -> angular_velocity_scale .values [i ] < 350 || new_settings -> angular_velocity_scale . values [ i ] > 370 ) {
514+ if (! pbio_imu_setting_close_to_360 ( new_settings -> angular_velocity_scale .values [i ]) ) {
505515 return PBIO_ERROR_INVALID_ARG ;
506516 }
507517 persistent_settings -> angular_velocity_scale .values [i ] = new_settings -> angular_velocity_scale .values [i ];
@@ -522,7 +532,7 @@ pbio_error_t pbio_imu_set_settings(pbio_imu_persistent_settings_t *new_settings)
522532 }
523533
524534 if (new_settings -> flags & PBIO_IMU_SETTINGS_FLAGS_HEADING_CORRECTION_1D_SET ) {
525- if (new_settings -> heading_correction_1d < 350 || new_settings -> heading_correction_1d > 370 ) {
535+ if (! pbio_imu_setting_close_to_360 ( new_settings -> heading_correction_1d ) ) {
526536 return PBIO_ERROR_INVALID_ARG ;
527537 }
528538 persistent_settings -> heading_correction_1d = new_settings -> heading_correction_1d ;
0 commit comments