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 授权授权。参考资料中的程式码范例已发布到公共领域。