描述
检查伺服机是否正在转动。
语法
servo.isMoving()
参数
servo
:AIServo
型别的变数。
回传
若伺服机正在转动,回传 true,其他状况下(如:伺服机暂停、停止、释放或到达目标位置)则回传 false。
范例
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
26
27
28
29
|
#include <AIServo86.h>
AIServoPort(ROBOTIS, AX12) bus;
AIServo myservo;
void setup()
{
bus.begin(Serial1, 1000000);
myservo.attach(bus, 9);
myservo.write(150); // 将伺服机转到 150 度
delay(1000);
myservo.setPosition(180, 3000); // 设定伺服机的目标角度:180 度,时间:3 秒
myservo.run();
delay(1000); // 伺服机转动 1 秒
if (myservo.isMoving() == true ) // 检查伺服机是否转到目标角度
Serial.println( "The servo is moving..." );
else
Serial.println( "The servo stops at target position" );
delay(3000); // 让伺服机转动至目标角度
if (myservo.isMoving() == true ) // 检查伺服机是否转到目标角度
Serial.println( "The servo is moving..." );
else
Serial.println( "The servo stops at target position" );
}
void loop() {}
|
See also
- attach()
- setPosition()
- isAIServoMultiMoving()
86Duino 参考资料中的文字修改自 Arduino 参考资料,并根据 知识共享署名-许可证方式共享 3.0 授权相同。参考资料中的程式码范例已发布到公共领域。