servo.read() starts at negative value, no matter where servo actually is I don't like how my servo quickly jumps to the default middle position, so I commented out the line where DEFAULT_PULSE_WIDTH is set in Servo.cpp:

//servos[this-&gt;servoIndex].ticks = usToTicks(DEFAULT_PULSE_WIDTH);


Unfortunately while this stopped the servo from moving on execution of attach, the position of the servo is now showing up as -52!

Just running the following in setup() is enough to generate the bug:

int servo_pin = 53;
servo.attach(servo_pin);
Serial.print("Initial position: ");
Serial.println(servo.read());  //returns -52


This last line returns -52 no matter what position the servo is actually in, which has bad consequences (its initial movement is way off).

Note I get the same behavior when I set the DEFAULT_PULSE_WIDTH to 0 in Servo.h.

I am using a Mega -- an Elegoo clone -- on Windows 10.

Note I got the ideas for stopping the servo from moving on initialization from these threads:        


https://stackoverflow.com/questions/40892922/how-to-stop-an-arduino-servo-from-moving-during-the-myservo-attach-command?noredirect=1&amp;lq=1
https://stackoverflow.com/questions/26695670/attach-arduino-servo-without-moving
You seem to be starting from a fundamental misunderstanding of RC hobby type PWM servos.  To put it simply, they do not electronically output any position information.

Until you have commanded a position and the servo loop has had a fair chance to seek to that, the position of the servo is utterly and entirely unknowable.

This is stated in the documentation of the Arduino servo system:

read()

Description

Read the current angle of the servo (the value passed to the last call to write()).


As this explains, the returned value is not the physical position, but rather the last commanded position.

Until you have commanded a position (something your code does not do) the return value of this call is physically meaningless.