Insert a print as shown to monitor the value of duration_us. Servos usually only go to 180°. Trying to run it beyond 180° can cause damage.
What is connected to A0? That is the only reading that you use, the rangefinder output is ignored.
You print the rangefinder output, but use A0.