PX4源碼分析8_PX4的sensor校準(zhǔn)

一.綜述:

sensor的校準(zhǔn)過程分為兩部分,首先需要先通過地面站進(jìn)行校準(zhǔn)設(shè)置,然后通過校準(zhǔn)數(shù)據(jù)的更新來獲取最新的校準(zhǔn)數(shù)據(jù)。

1.校準(zhǔn)數(shù)據(jù)的設(shè)置:

commander(地面站)經(jīng)過計(jì)算之后通過param_set()來設(shè)置校準(zhǔn)數(shù)據(jù),路徑為src/modules/commander下的各個(gè)calibration文件,上電后rcS腳本執(zhí)行sensors start之后會執(zhí)行commder start來啟動commander.cpp,commander.cpp進(jìn)而調(diào)用各個(gè)calibration文件,進(jìn)而進(jìn)行校準(zhǔn)設(shè)置。

2.校準(zhǔn)數(shù)據(jù)的獲?。?/h4>

在sensors.cpp中的task_main()循環(huán)中還有一個(gè)poll函數(shù)是parameter_update_poll(),這個(gè)poll函數(shù)獲取了各個(gè)sensor的offset和scale來供各個(gè)sensor驅(qū)動中measure校準(zhǔn)時(shí)使用,它使用param_get()來獲得。

二.陀螺儀的校準(zhǔn):

1.do_gyro_calibration():

commander.cpp中commander_main()中執(zhí)行do_gyro_calibration()。

2.初始化:

gyro_calibration.cpp中do_gyro_calibration()初始化gyro_scale_zero中各個(gè)offset賦值為0,各個(gè)scale賦值為1,并將gyro_scale_zero各個(gè)值通過param_set()賦值給對應(yīng)參數(shù)值。

3.gyro_calibration_worker():

gyro_calibration.cpp中do_gyro_calibration()執(zhí)行g(shù)yro_calibration_worker()。

4.校準(zhǔn):

gyro_calibration.cpp中g(shù)yro_calibration_worker()中:
(1)循環(huán)執(zhí)行5000次。
(2)每次循環(huán)執(zhí)行px4_poll()進(jìn)行延時(shí)處理。
(3)每次循環(huán)均依次對各個(gè)gyro進(jìn)行如下校準(zhǔn)。
(3)orb_check()檢查更新。
(4)orb_copy()接受數(shù)據(jù)賦值相應(yīng)坐標(biāo)軸offset,將校準(zhǔn)變量gyro_scale[s]加等gyro測量值gyro_report。
(5)相應(yīng)坐標(biāo)軸offset分別除以校準(zhǔn)計(jì)數(shù)值5000。

5.賦值:

gyro_calibration.cpp中執(zhí)行param_set_no_notification()將gyro_scale[s]相應(yīng)坐標(biāo)軸的offset賦值給對應(yīng)參數(shù)值。

三.加速度計(jì)的校準(zhǔn):

1.do_accel_calibration():

commander.cpp中commander_main()中執(zhí)行do_accel_calibration()。

2.初始化:

accelerometer_calibration.cpp中do_accel_calibration()初始化accel_scale中各個(gè)offset賦值為0,各個(gè)scale賦值為1,并將accel_scale各個(gè)值通過param_set()賦值給對應(yīng)參數(shù)值。

3.校準(zhǔn):

accelerometer_calibration.cpp中do_accel_calibration()執(zhí)行do_accel_calibration_measurements。
(1)執(zhí)行calibrate_from_orientation()進(jìn)行六個(gè)方向測量accel的offset值并賦值accel_ref[max_accel_sens][detect_orientation_side_count][3]中:
?[1] 根據(jù)方向的轉(zhuǎn)換,循環(huán)六次。
?[2] 每次循環(huán)執(zhí)行accel_calibration_worker()。
?[3] accel_calibration_worker()執(zhí)行read_accelerometer_avg()。
?[4] read_accelerometer_avg函數(shù)中:
???a:循環(huán)執(zhí)行750次。
???b:每次循環(huán)執(zhí)行px4_poll()進(jìn)行延時(shí)處理。
???c:并對各個(gè)accel進(jìn)行如下校準(zhǔn)。
???d:orb_check()檢查更新。
???e:orb_copy()接受數(shù)據(jù)賦值相應(yīng)坐標(biāo)軸offset,將校準(zhǔn)變量accel_sum[s]加等accel測量值arp。
???f:相應(yīng)坐標(biāo)軸offset分別除以校準(zhǔn)計(jì)數(shù)值750賦值給accel_ref。
(2)執(zhí)行calculate_calibration_values(),根據(jù)accel_ref計(jì)算偏移offsets和轉(zhuǎn)移矩陣transform matrix,分別賦值accel_offs和accel_T。

4.計(jì)算offset:

根據(jù)accel_offs和accel_T值結(jié)合board_rotation_t計(jì)算accel_scale[s]相應(yīng)坐標(biāo)軸的offset。

5.賦值:

accelerometer_calibration.cpp中執(zhí)行param_set_no_notification()將accel_scale[s]相應(yīng)坐標(biāo)軸的offset賦值給對應(yīng)參數(shù)值。

四.地磁的校準(zhǔn):

1.do_mag_calibration():

commander.cpp中commander_main()中執(zhí)行do_mag_calibration()。

2.校準(zhǔn):

mag_calibration.cpp的do_mag_calibration()中
(1)初始化mscale_null中各個(gè)offset賦值為0,各個(gè)scale賦值為1。
(2)執(zhí)行mag_calibrate_all(mavlink_log_pub)同時(shí)對所有mag校準(zhǔn)。
(3)所有測量點(diǎn)x,y,z軸數(shù)據(jù)初始化。
(4)訂閱mag消息。
(5)限制點(diǎn)數(shù)據(jù)測量間隔時(shí)間。
(6)進(jìn)行mag點(diǎn)數(shù)據(jù)進(jìn)行采集,執(zhí)行calibrate_from_orientation,賦值worker_data。
?[1] 對六個(gè)面分別進(jìn)行檢測,檢測過程如下:
?[2] 執(zhí)行calibration_worker指針函數(shù),即mag_calibration_worker函數(shù):
???a:旋轉(zhuǎn)檢測:任意方向旋轉(zhuǎn)即可,僅需要大致相交的兩個(gè)軸,通過對陀螺數(shù)據(jù)積分檢測是否旋轉(zhuǎn)。
???b:對該面進(jìn)行采集calibration_points_perside個(gè)mag數(shù)據(jù)存儲至worker_data.x,worker_data.y,worker_data.z中。
(7)球體擬合最小二乘mag數(shù)據(jù),調(diào)用sphere_fit_least_squares()得到mag偏移sphere_x,sphere_y,sphere_z,sphere_radius。
(8)sphere_x,sphere_y,sphere_z分別賦值mscale.x_offset,mscale.y_offset,mscale.z_offset。
(9)通過mscale.x_offset,mscale.y_offset,mscale.z_offset對偏移參數(shù)賦值。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容