positions[]

描述

存放機器人動作幀的整數陣列,每個陣列元素的值對應一個機器人伺服機的位置,單位為 us。

ServoFramePololu 在初始化時,沒有指定載入動作幀檔案,則使用者可改由直接設定此陣列的元素值來設定動作幀。

語法


myframe.positions[channel]

參數

myframeServoFramePololu 型別的物件。

channel:指定陣列元素,範圍為 0 ~ 44。第 n 個元素值代表要指定給第 n 個 Servo 的位置,請見下面範例說明。(注意:在 86Duino One 上所有陣列元素都有效;在86Duino EduCake 上只有 0 ~ 25 的範圍有效;在 86Duino Zero 上只有 0 ~ 16 的範圍有效。)

由於 Maestro Control Center 最多支援 24 軸伺服機,當使用 load() 函式由其動作幀檔案載入指定動作幀時,只有 positions[0]、positions[1]、...、positions[23] 會包含有效值,其餘陣列元素皆為 0。

回傳

範例

#include <Servo86.h> 
 
Servo myservo0; 
Servo myservo1; 
Servo myservo2;
ServoFramePololu myframe; // 宣告一個 ServoFramePololu 物件
 
void setup() 
{ 
  myservo0.attach(9); 
  myservo1.attach(11); 
  myservo2.attach(5);

  myframe.positions[0] = 1800; // 設定動作幀內容
  myframe.positions[1] = 1300;
  myframe.positions[2] = 2000;

  // 設定以 500ms 的時間將伺服機由當前位置轉動到 myframe 指定的位置,即令:
  // myservo0 轉動到 position[0],
  // myservo1 轉動到 position[1] 位置,
  // myservo2 轉動到 position[2] 位置。
  myframe.setPositions(500, myservo0 , myservo1, myservo2); 

  servoMultiRun(); // 命令所有伺服機開始轉動
} 
 
void loop() {}

See also

setPostions
playPostions


函式庫參考主頁面

The text of the 86Duino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.