@ -85,7 +85,7 @@ static calibrate_return gyro_calibration_worker(detect_orientation_return orient
struct gyro_report gyro_report ;
struct gyro_report gyro_report ;
unsigned poll_errcount = 0 ;
unsigned poll_errcount = 0 ;
struct pollfd fds [ max_gyros ] ;
px4_p ollfd_struct_t fds [ max_gyros ] ;
for ( unsigned s = 0 ; s < max_gyros ; s + + ) {
for ( unsigned s = 0 ; s < max_gyros ; s + + ) {
fds [ s ] . fd = worker_data - > gyro_sensor_sub [ s ] ;
fds [ s ] . fd = worker_data - > gyro_sensor_sub [ s ] ;
fds [ s ] . events = POLLIN ;
fds [ s ] . events = POLLIN ;
@ -182,25 +182,16 @@ int do_gyro_calibration(int mavlink_fd)
// Reset all offsets to 0 and scales to 1
// Reset all offsets to 0 and scales to 1
( void ) memcpy ( & worker_data . gyro_scale [ s ] , & gyro_scale_zero , sizeof ( gyro_scale ) ) ;
( void ) memcpy ( & worker_data . gyro_scale [ s ] , & gyro_scale_zero , sizeof ( gyro_scale ) ) ;
sprintf ( str , " %s%u " , GYRO_BASE_DEVICE_PATH , s ) ;
sprintf ( str , " %s%u " , GYRO_BASE_DEVICE_PATH , s ) ;
int fd = open ( str , 0 ) ;
int fd = px4_ open( str , 0 ) ;
if ( fd > = 0 ) {
if ( fd > = 0 ) {
worker_data . device_id [ s ] = ioctl ( fd , DEVIOCGDEVICEID , 0 ) ;
worker_data . device_id [ s ] = ioctl ( fd , DEVIOCGDEVICEID , 0 ) ;
res = ioctl ( fd , GYROIOCSSCALE , ( long unsigned int ) & gyro_scale_zero ) ;
res = ioctl ( fd , GYROIOCSSCALE , ( long unsigned int ) & gyro_scale_zero ) ;
close ( fd ) ;
px4_close ( fd ) ;
< < < < < < < HEAD
for ( unsigned s = 0 ; s < max_gyros ; s + + ) {
px4_close ( sub_sensor_gyro [ s ] ) ;
gyro_scale [ s ] . x_offset / = calibration_counter [ s ] ;
gyro_scale [ s ] . y_offset / = calibration_counter [ s ] ;
gyro_scale [ s ] . z_offset / = calibration_counter [ s ] ;
= = = = = = =
if ( res ! = OK ) {
if ( res ! = OK ) {
mavlink_log_critical ( mavlink_fd , CAL_ERROR_RESET_CAL_MSG , s ) ;
mavlink_log_critical ( mavlink_fd , CAL_ERROR_RESET_CAL_MSG , s ) ;
return ERROR ;
return ERROR ;
}
}
> > > > > > > upstream / master
}
}
}
}
@ -223,7 +214,7 @@ int do_gyro_calibration(int mavlink_fd)
calibrate_cancel_unsubscribe ( cancel_sub ) ;
calibrate_cancel_unsubscribe ( cancel_sub ) ;
for ( unsigned s = 0 ; s < max_gyros ; s + + ) {
for ( unsigned s = 0 ; s < max_gyros ; s + + ) {
close ( worker_data . gyro_sensor_sub [ s ] ) ;
px4_ close( worker_data . gyro_sensor_sub [ s ] ) ;
}
}
if ( cal_return = = calibrate_return_cancelled ) {
if ( cal_return = = calibrate_return_cancelled ) {
@ -242,15 +233,9 @@ int do_gyro_calibration(int mavlink_fd)
/* maximum allowable calibration error in radians */
/* maximum allowable calibration error in radians */
const float maxoff = 0.0055f ;
const float maxoff = 0.0055f ;
< < < < < < < HEAD
if ( ! PX4_ISFINITE ( worker_data . gyro_scale [ 0 ] . x_offset ) | |
if ( ! PX4_ISFINITE ( gyro_scale [ 0 ] . x_offset ) | |
! PX4_ISFINITE ( worker_data . gyro_scale [ 0 ] . y_offset ) | |
! PX4_ISFINITE ( gyro_scale [ 0 ] . y_offset ) | |
! PX4_ISFINITE ( worker_data . gyro_scale [ 0 ] . z_offset ) | |
! PX4_ISFINITE ( gyro_scale [ 0 ] . z_offset ) | |
= = = = = = =
if ( ! isfinite ( worker_data . gyro_scale [ 0 ] . x_offset ) | |
! isfinite ( worker_data . gyro_scale [ 0 ] . y_offset ) | |
! isfinite ( worker_data . gyro_scale [ 0 ] . z_offset ) | |
> > > > > > > upstream / master
fabsf ( xdiff ) > maxoff | |
fabsf ( xdiff ) > maxoff | |
fabsf ( ydiff ) > maxoff | |
fabsf ( ydiff ) > maxoff | |
fabsf ( zdiff ) > maxoff ) {
fabsf ( zdiff ) > maxoff ) {
@ -276,30 +261,6 @@ int do_gyro_calibration(int mavlink_fd)
( void ) sprintf ( str , " CAL_GYRO%u_ID " , s ) ;
( void ) sprintf ( str , " CAL_GYRO%u_ID " , s ) ;
failed | = ( OK ! = param_set_no_notification ( param_find ( str ) , & ( worker_data . device_id [ s ] ) ) ) ;
failed | = ( OK ! = param_set_no_notification ( param_find ( str ) , & ( worker_data . device_id [ s ] ) ) ) ;
/* apply new scaling and offsets */
( void ) sprintf ( str , " %s%u " , GYRO_BASE_DEVICE_PATH , s ) ;
int fd = open ( str , 0 ) ;
if ( fd < 0 ) {
failed = true ;
continue ;
}
< < < < < < < HEAD
/* if any reasonable amount of data is missing, skip */
if ( calibration_counter [ s ] < calibration_count / 2 ) {
continue ;
}
( void ) sprintf ( str , " CAL_GYRO%u_XOFF " , s ) ;
failed | = ( OK ! = param_set_no_notification ( param_find ( str ) , & ( gyro_scale [ s ] . x_offset ) ) ) ;
( void ) sprintf ( str , " CAL_GYRO%u_YOFF " , s ) ;
failed | = ( OK ! = param_set_no_notification ( param_find ( str ) , & ( gyro_scale [ s ] . y_offset ) ) ) ;
( void ) sprintf ( str , " CAL_GYRO%u_ZOFF " , s ) ;
failed | = ( OK ! = param_set_no_notification ( param_find ( str ) , & ( gyro_scale [ s ] . z_offset ) ) ) ;
( void ) sprintf ( str , " CAL_GYRO%u_ID " , s ) ;
failed | = ( OK ! = param_set_no_notification ( param_find ( str ) , & ( device_id [ s ] ) ) ) ;
/* apply new scaling and offsets */
/* apply new scaling and offsets */
( void ) sprintf ( str , " %s%u " , GYRO_BASE_DEVICE_PATH , s ) ;
( void ) sprintf ( str , " %s%u " , GYRO_BASE_DEVICE_PATH , s ) ;
int fd = px4_open ( str , 0 ) ;
int fd = px4_open ( str , 0 ) ;
@ -309,12 +270,8 @@ int do_gyro_calibration(int mavlink_fd)
continue ;
continue ;
}
}
res = px4_ioctl ( fd , GYROIOCSSCALE , ( long unsigned int ) & gyro_scale [ s ] ) ;
res = px4_ioctl ( fd , GYROIOCSSCALE , ( long unsigned int ) & worker_data . gyro_scale [ s ] ) ;
px4_close ( fd ) ;
px4_close ( fd ) ;
= = = = = = =
res = ioctl ( fd , GYROIOCSSCALE , ( long unsigned int ) & worker_data . gyro_scale [ s ] ) ;
close ( fd ) ;
> > > > > > > upstream / master
if ( res ! = OK ) {
if ( res ! = OK ) {
mavlink_log_critical ( mavlink_fd , CAL_ERROR_APPLY_CAL_MSG ) ;
mavlink_log_critical ( mavlink_fd , CAL_ERROR_APPLY_CAL_MSG ) ;