aiservoBeginSplineMotion()
描述
允許使用者使用曲線規劃作為伺服機運動的插補方法,開啟此功能後,可適度抑制機器人運動過程產生的震動,讓機器人動作更穩定。此功能在 Coding 315 以後開始支援。
語法
aiservoBeginSplineMotion(mode, frames, frameTime, numFrames)
參數
mode
:有 3 種模式可選擇。
NATURAL_CUBIC
:可適度降低機器人運動中的震動,平滑化機器人動作,需要注意的是,為了符合 NATURAL CUBIC SPLINE 公式定義,機器人的 Frame 編排在某些方式下,插補出來的軌跡可能會超出預期動作(overshooting),如果不希望此狀況發生,可使用 CONSTRAINED_CUBIC 模式。CONSTRAINED_CUBIC
:依據 CONSTRAINED CUBIC SPLINE 公式定義,可保證不會有上述NATURAL_CUBIC
的缺點,但會降低平滑化的效果。CATMULL_ROM
:依據 CATMULL-ROM SPLINE 公式定義,能有效抑制NATURAL_CUBIC
所產生的 overshooting,且平滑化的效果優於CONSTRAINED_CUBIC
。
frames
:要進行曲線規劃的 frame 陣列。
frameTime
:每個 frame 播放的間隔時間陣列(時間單位為 ms)。
numFrames
:要進行曲線規劃的 frames 數量(即 frames 陣列大小)。
回傳
無
範例
#include "AIServo86.h" AIServo Servo1; AIServo Servo2; AIServo Servo3; AIServoPort(ROBOTIS, AX12) bus; AIServoFrame Frames[3]; unsigned long playtime[3] = {200, 500, 100}; void setup() { Servo1.attach(bus, 21); Servo2.attach(bus, 22); Servo3.attach(bus, 23); Frames[0].positions[0] = 150; Frames[0].positions[1] = 150; Frames[0].positions[2] = 130; Frames[1].positions[0] = 240; Frames[1].positions[1] = 140; Frames[1].positions[2] = 180; Frames[2].positions[0] = 240; Frames[2].positions[1] = 160; Frames[2].positions[2] = 180; Frames[0].playPositions(playtime[0]); Serial.println("Natural CUBIC"); } void loop() { aiservoBeginSplineMotion(NATURAL_CUBIC, Frames, playtime, 3); for (int i=0; i<3; i++) { Frames[i].playPositions(playtime[i]); while(isAIServoMultiMoving() == true); } aiservoEndSplineMotion(); }
See also
- attach()
- AIServoFrame
- positions[]
- playPositions()
- isAIServoMultiMoving()
- aiservoEndSplineMotion()
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.