servoBeginSplineMotion()
描述
允許使用者指定曲線規劃作為伺服機運動軌跡的插補方法,開啟曲線插補功能後,可適度抑制機器人運動過程產生的震動,讓機器人動作更穩定。86Duino IDE 從 Coding 300 開始支援此函式。
語法
servoBeginSplineMotion(mode, frames, frameTime, numFrames)
參數
mode
:有 3 種模式可選擇。
NATURAL_CUBIC
:可適度降低機器人運動中的震動,平滑化機器人動作,需要注意的是,為了符合 NATURAL CUBIC SPLINE 公式定義,機器人的 Frame 編排在某些方式下,插補出來的軌跡可能會超出預期動作,如果不希望此狀況發生,可使用 CONSTRAINED_CUBIC 模式。CONSTRAINED_CUBIC
:依據 CONSTRAINED CUBIC SPLINE 公式定義,可保證不會有上述NATURAL_CUBIC
的缺點,但會降低平滑化的效果。CATMULL_ROM
:依據 CATMULL-ROM SPLINE 公式定義,能有效抑制NATURAL_CUBIC
所產生的 overshooting,且平滑化的效果優於CONSTRAINED_CUBIC
。(從 Coding 315 開始支援此設定)
frames
:要進行曲線規劃的 frame 陣列。
frameTime
:每個 frame 播放的間隔時間陣列(時間單位為 ms)。
numFrames
:要進行曲線規劃的 frames 數量(即 frames 陣列大小)。
回傳
無
範例
#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()
The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.