@ -205,30 +205,6 @@ void AP_Compass_MAG3110::_update()
Vector3f raw_field = Vector3f ( _mag_x , _mag_y , _mag_z ) * MAG_SCALE ;
Vector3f raw_field = Vector3f ( _mag_x , _mag_y , _mag_z ) * MAG_SCALE ;
bool ret = true ;
# if MAG3110_ENABLE_LEN_FILTER
float len = raw_field . length ( ) ;
if ( is_zero ( compass_len ) ) {
compass_len = len ;
} else {
# define FILTER_KOEF 0.1
float d = abs ( compass_len - len ) / ( compass_len + len ) ;
if ( d * 100 > 25 ) { // difference more than 50% from mean value
printf ( " \n compass len error: mean %f got %f \n " , compass_len , len ) ;
ret = false ;
float k = FILTER_KOEF / ( d * 10 ) ; // 2.5 and more, so one bad sample never change mean more than 4%
compass_len = compass_len * ( 1 - k ) + len * k ; // complimentary filter 1/k on bad samples
} else {
compass_len = compass_len * ( 1 - FILTER_KOEF ) + len * FILTER_KOEF ; // complimentary filter 1/10 on good samples
}
}
# endif
if ( ret ) {
// rotate raw_field from sensor frame to body frame
// rotate raw_field from sensor frame to body frame
rotate_field ( raw_field , _compass_instance ) ;
rotate_field ( raw_field , _compass_instance ) ;
@ -238,6 +214,10 @@ void AP_Compass_MAG3110::_update()
// correct raw_field for known errors
// correct raw_field for known errors
correct_field ( raw_field , _compass_instance ) ;
correct_field ( raw_field , _compass_instance ) ;
if ( ! field_ok ( raw_field ) ) {
return ;
}
if ( _sem - > take ( HAL_SEMAPHORE_BLOCK_FOREVER ) ) {
if ( _sem - > take ( HAL_SEMAPHORE_BLOCK_FOREVER ) ) {
_mag_x_accum + = raw_field . x ;
_mag_x_accum + = raw_field . x ;
_mag_y_accum + = raw_field . y ;
_mag_y_accum + = raw_field . y ;
@ -252,7 +232,6 @@ void AP_Compass_MAG3110::_update()
_sem - > give ( ) ;
_sem - > give ( ) ;
}
}
}
}
}
// Read Sensor data
// Read Sensor data