跳轉到內容

Khepera III 工具箱/工具箱/模組/里程計 goto

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

odometry_goto 模組實現了一個簡單的反饋演算法,使差動驅動車輛移動到給定位置()。它使用 odometry_track 模組來估計機器人的當前位置。

// Instantiate a track and a goto structure
struct sOdometryTrack ot;
struct sOdometryGoto og;

// Initialize the modules
odometry_track_init();
odometry_goto_init();

// Initializes tracking and goto structures
odometry_track_start(&ot);
odometry_goto_start(&og, &ot);

// Set a target position
odometry_goto_set_goal(&og, x, y);

// Move until the robot is close enough to the target position
while (og.result.atgoal == 0) {
	// Update position and calculate new speeds
	odometry_track_step(og.track);
	odometry_goto_step(&og);

	// Set the wheel speed
	khepera3_drive_set_speed(og.result.speed_left, og.result.speed_right);
}

// The final position (which may be slightly different from the target position)
... = og.track->result.x;
... = og.track->result.y;
... = og.track->result.theta;

該模組始終與 odometry_track 模組結合使用。

odometry_goto_start 設定一個 sOdometryGoto 結構併為其分配一個 sOdometryTrack 結構。後者必須事先初始化(但可能已在更早時間初始化並使用過)。

目標位置使用 odometry_goto_set_goal 設定。在主迴圈中,odometry_goto_step(在 odometry_track_step 之後立即呼叫)計算新的輪速並將它們放入 result 結構中。這些速度值應設定為 khepera3_drive_set_speed。請注意,目標位置可以隨時更改。odometry_goto_step 函式將針對當前配置的目標位置計算電機速度。

除了電機速度外,result 結構還提供了兩個更有用的欄位

  • closetogoal:一旦機器人距離目標位置足夠近以開始減速,就會設定該欄位。
  • atgoal:如果機器人已到達目標位置,則設定該欄位。
華夏公益教科書