setRealTimeMixing()

Description

Dynamically sets the servo's offset angle. While the servo is running, the offset value set using this function is immediately added to the servo's target angle, causing positive or negative deviations from the original target angle. This function allows robots with sensors (gyroscopes or accelerometers) to receive feedback from them, allowing the feedback to be reflected in the robot's movements in real time.

Syntax

servo.setRealTimeMixing(value)

Parameters

servo: A variable of type AIServo.

setRealTimeMixing: offset angle, unit: degree.

Postback

None

Example

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

30

31

32

33

#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); //Set target angle: 300 degrees

  myservo.run(); //Start the server

  delay(1500);

  double i = -1;

  _time = millis();

  myservo.setPosition(125, 3000); // Set target angle: 125 degrees, time: 3 seconds

  myservo.run(); // Start the servo

  while(myservo.isMoving() == true)

  {

    if((millis() - _time) < 1000L)

    {

      i = i*2;

      if ( i < -100)

        i = -1;

      myservo.setRealTimeMixing(i);

    }

  }

  while(1);

See also

attach()


Library Reference Home

The text in the 86Duino reference material is modified from the Arduino reference material and is licensed under the Creative Commons Attribution-Share Alike 3.0 License . The code examples in the reference material have been released into the public domain.