[SOLVED] Servomotor jerks

Hello everyone! I’m testing with servomotors (mg996r).
I used this code but when I run it the servomotor jumps for a minute (see the this video: https://drive.google.com/open?id=1y83XvZb10X7m79iMCFHbqaGK0Rr9gdnH) and then starts working correctly, how do I solve it?

#include <Servo.h>
 
Servo myservo;

int servo_speed = 15;
int moveTO(Servo servo, int degree){
  int pos = servo.read();
  if(pos == degree){
    return pos;
  }
  if(pos < degree){
    for(; pos < degree; pos += 1)
    {
      servo.write(pos);
      delay(servo_speed);
    }
  } else {
    for(; pos >= degree; pos -= 1)
    {
      myservo.write(pos);
      delay(servo_speed);
    }
  }
  return pos;
}
 
void setup()
{
  myservo.attach(9);
  Serial.begin(9600);
}
 
void loop()
{
  moveTO(myservo, 76);
  delay(1000);
  moveTO(myservo, 152);
  delay(1000);
  moveTO(myservo, 0);
  delay(1000);
}

When you attach a servo it goes to 90 degrees by default, if you want a different start position, say 15, you can specify it before attaching, do this in setup():

servo.write(15);
servo.attach(9);
 int pos = servo.read();

Do you know that the servo.read() function does not return the actual position of the servo, but the last position that was sent to the servo with servo.write()?

Perfect! thanks, works with 93!