setRealTimeMixing()

描述

將指定值補償至伺服機的當前位置控制週期。

對於一些身上帶有感測器(例如陀螺儀或加速度計)的機器人,此函式可用來將感測器偵測到的物理量反饋到機器人的動作上。

語法


servo.setRealTimeMixing(value)

參數

servoServo 型別的變數。

value:位置補償值,單位:us。當伺服機正在運轉時,此補償值會被即時加到伺服機當前位置控制週期所計算出的目標角度上。

回傳

範例

#include <Servo86.h> 

Servo myservo;

void setup() 
{ 
  myservo.attach(9);
  myservo.setPosition(1500); // 設定目標角度:1500us
  myservo.run(); // 轉動伺服機
  while(myservo.isMoving() == true); // 等待伺服機抵達目標角度

  int i = 0;
  myservo.setPosition(2000, 5000); // 設定目標角度:2000us,花費時間:5 秒
  myservo.run(); // 轉動伺服機
  while(myservo.isMoving() == true)
  {
    i = (i + 10) % 400; // 模擬回饋角度的變化
    myservo.setRealTimeMixing(i);
  }
} 

void loop() {} 

See also

write()
writeMicroseconds()
run()


函式庫參考主頁面

The text of the 86Duino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.