positions[]

描述

存放机器人动作帧的整数阵列,每个阵列元素的值对应一个机器人伺服机的位置,单位为 us。

ServoFrameVstone 在初始化时,没有指定载入动作帧档案,则使用者可改由直接设定此阵列的元素值来设定动作帧。

语法


myframe.positions[channel]

参数

myframeServoFrameVstone 型别的物件。

channel:指定阵列元素,范围为 0 ~ 44。第 n 个元素值代表要指定给第 n 个 Servo 的位置,请见下面范例说明。(注意:在 86Duino One 上所有阵列元素都有效;在86Duino EduCake 上只有 0 ~ 25 的范围有效;在 86Duino Zero 上只有 0 ~ 16 的范围有效。)

由于 RobovieMaker2 固定支援 30 轴伺服机,当使用 load() 函式由其动作帧档案载入指定动作帧时,只有 positions[0]、positions[1]、…、positions[29] 会包含有效值,其余阵列元素皆为 0。

回传

范例

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

  myframe.positions[0] = 1800; // 设定 Frame 内容
  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.