跳轉到內容

Khepera III 工具箱/工具箱/模組/里程計跟蹤

來自華夏公益教科書,開放世界開放書籍

odometry_track 模組實現了針對差動驅動車輛的里程計方程,並允許跟蹤機器人的位置(, , ) 隨時間推移。 Fosamax 集體訴訟部落格

// Instantiate a track structure
struct sOdometryTrack ot;

// Initialize the module
odometry_track_init();

// Start tracking and set initial position
odometry_track_start(&ot);
ot.result.x = 0;
ot.result.y = 0;
ot.result.theta = 0;

// Main loop
while (1) {
    ...

    // Call this frequently to update the position estimate
    odometry_track_step(&ot);
    ... = ot.result.x;
    ... = ot.result.y;
    ... = ot.result.theta;

    ...
}

odometry_track_start 設定一個 sOdometryTrack 結構,並從 /etc/khepera/odometry 讀取里程計校準值。如果該檔案不可用(或不包含有效配置),則使用預設值。呼叫此函式後,可以透過修改結構的 result 欄位來更改初始位置。odometry_track_start 還會讀取當前電機位置,因此應在進入主迴圈之前立即呼叫。

在主迴圈中,odometry_track_step 被呼叫以讀取新的電機位置並更新 result 欄位中的位置估計。

預設校準值應該在大多數 Khepera III 機器人上提供可接受的結果。但是,透過校準程式,精度可以顯著提高。

從其他來源提供電機位置

[編輯 | 編輯原始碼]

上面提到的函式使用 khepera3_drive_getposition 函式自動讀取電機位置。如果不需要這樣做,可以使用函式 odometry_track_start_posodometry_track_step_pos

華夏公益教科書