servoBeginSplineMotion()

描述

允許使用者指定曲線規劃作為伺服機運動軌跡的插補方法,開啟曲線插補功能後,可適度抑制機器人運動過程產生的震動,讓機器人動作更穩定。86Duino IDE 從 Coding 300 開始支援此函式。

語法

servoBeginSplineMotion(mode, frames, frameTime, numFrames)

參數

mode:有 3 種模式可選擇。

  1. NATURAL_CUBIC:可適度降低機器人運動中的震動,平滑化機器人動作,需要注意的是,為了符合 NATURAL CUBIC SPLINE 公式定義,機器人的 Frame 編排在某些方式下,插補出來的軌跡可能會超出預期動作,如果不希望此狀況發生,可使用 CONSTRAINED_CUBIC 模式。
  2. CONSTRAINED_CUBIC:依據 CONSTRAINED CUBIC SPLINE 公式定義,可保證不會有上述 NATURAL_CUBIC 的缺點,但會降低平滑化的效果。
  3. CATMULL_ROM:依據 CATMULL-ROM SPLINE 公式定義,能有效抑制 NATURAL_CUBIC 所產生的 overshooting,且平滑化的效果優於 CONSTRAINED_CUBIC。(從 Coding 315 開始支援此設定)

frames:要進行曲線規劃的 frame 陣列。

frameTime:每個 frame 播放的間隔時間陣列(時間單位為 ms)。

numFrames:要進行曲線規劃的 frames 數量(即 frames 陣列大小)。

回傳

範例

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

#include "Servo86.h"

Servo Servo1;

Servo Servo2;

Servo Servo3;

 

ServoFrame Frames[3];

unsigned long playtime[3] = {200, 500, 100};

void setup() {

  Servo1.attach(21); Servo2.attach(22); Servo3.attach(23);

  Frames[0].positions[0] = 1500; Frames[0].positions[1] = 1500; Frames[0].positions[2] = 1310;

  Frames[1].positions[0] = 2040; Frames[1].positions[1] = 1450; Frames[1].positions[2] = 1840;

  Frames[2].positions[0] = 2040; Frames[2].positions[1] = 1060; Frames[2].positions[2] = 1840;

  Frames[0].playPositions(playtime[0]);

  Serial.println("Natural CUBIC");

}

 

void loop() {

  servoBeginSplineMotion(NATURAL_CUBIC, Frames, playtime, 3);

  // 以下播放的動作將有曲線插補的平滑化效果

  for (int i=0; i<3; i++) {

    Frames[i].playPositions(playtime[i]);

    while(isServoMultiMoving() == true);

  }

  servoEndSplineMotion();  // 關閉曲線插補功能

}

See also

- attach()
- ServoFrame
- positions[]
- playPositions()
- isServoMultiMoving()
- servoEndSplineMotion()


 

函式庫參考主頁面

86Duino 參考資料中的文字採用 知識共享署名-相同方式共享 3.0 授權授權。參考資料中的程式碼範例已發佈到公共領域。