The implementation of the servo easer cumulates little timing mistakes. As a result it is difficult to implement multiple servos, and they need to be synchronised.
A new timing mechanism has been implemented, in which timing errors are not cumulated: the library always tries to return to the planned timing based on the starting time.
An example has been added to control 2 servos without the need to sync them in between, they simply remain synchronised.
Testing code
To see the difference between the 2 implementations, you can check the code below. In the original code, the behaviour is changed a lot because of the random delay. The proposed changes make the execution independent of the random delays.
You can make use of my fork of the library https://github.com/FedericoBusero/ServoEaser if you want to test this fix together with my 2 other proposed changes (call by reference & ESP32).
#include <Servo.h>
#include "ServoEaser.h"
const int servo1Pin = 7;
const int servo2Pin = 6;
int servoFrameMillis = 10; // time between servo updates
Servo servo1;
Servo servo2;
ServoEaser servo1Easer;
ServoEaser servo2Easer;
int myServoMovesCount = 8;
// configurable list of servo moves
ServoMove myServoMoves[] = {
// angle, duration
{0, 3000},
{45, 1000},
{20, 500},
{90, 1000},
{45, 2000},
{135, 2000},
{75, 1000},
{165, 1000},
};
//
void setup()
{
Serial.begin(19200);
Serial.println("ServoEaser test with random delays");
servo1.attach( servo1Pin );
servo2.attach( servo2Pin );
servo1Easer.begin( servo1, servoFrameMillis );
servo2Easer.begin( servo2, servoFrameMillis );
servo2Easer.setFlipped( true );
servo1Easer.play( myServoMoves, myServoMovesCount );
servo2Easer.play( myServoMoves, myServoMovesCount );
}
//
void loop()
{
servo1Easer.update();
servo2Easer.update();
delay(random(20));
}
Problem
The implementation of the servo easer cumulates little timing mistakes. As a result it is difficult to implement multiple servos, and they need to be synchronised.
Issues
This pull request relates to following issues:
Solution
Testing code
To see the difference between the 2 implementations, you can check the code below. In the original code, the behaviour is changed a lot because of the random delay. The proposed changes make the execution independent of the random delays.
You can make use of my fork of the library https://github.com/FedericoBusero/ServoEaser if you want to test this fix together with my 2 other proposed changes (call by reference & ESP32).