setRealTimeMixing()

描述

動態設定伺服機的偏移角度。

當伺服機正在運轉時,用此函式設定的偏移值會即時加入伺服機目標角度的運算,讓原來的目標角度產生正、負偏差。此函式可讓一些身上帶有感測器(陀螺儀或加速度計)的機器人,用來接收其回饋值,使回饋值能即時反應在機器人的動作中。

語法


servo.setRealTimeMixing(value)

參數

servoAIServo 型別的變數。

setRealTimeMixing:偏移角度,單位:度。

回傳

範例

#include <AIServo86.h> 

AIServoPort(ROBOTIS, AX12) bus;
AIServo myservo;
unsigned long _time = 0L;

void setup() 
{ 
  bus.begin(Serial3, 1000000);
  myservo.attach(bus, 3);
} 

void loop()
{
  myservo.setPosition(300); // 設定目標角度:300 度
  myservo.run(); // 啟動伺服機
  delay(1500);
  double i = -1;
  _time = millis();
  myservo.setPosition(125, 3000); // 設定目標角度:125 度,花費時間:3 秒
  myservo.run(); // 啟動伺服機
  while(myservo.isMoving() == true)
  {
    if((millis() - _time) < 1000L)
    {
      i = i*2;
      if ( i < -100)
        i = -1;
      myservo.setRealTimeMixing(i);
    }
  }
  while(1);
} 

See also

attach()


函式庫參考主頁面

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.