Servo motor control

Can someone advise me the formula to convert microseconds to degrees of rotation.

I am using an SG90 and know the range of microseconds required but my code (micropython_pca9685 Servo) uses servo.angle to drive the servo.

Thanks
Toni

1 Like

Are you talking about the pulse width times here ?

i.e. a pulse width of X uS = Y degrees of movement

If so, the actual number would depend on the servo specs.

Can you supply the part no (or a link to the datasheet) for your survo. from there we should be able to work out the math.

I dont think there will be a golden rule/mapping.

To add some math. example only.
Lets say you have a servo
The specs of the servo are from 0 - 360 Deg are 700uS - 2300 uS
Assuming movement is linear. then my math would be

2300 - 700 = 1600 uS from 0 to 360 Deg
1600 uS/360 = 4.4444 (rounded) uS per Deg
so to move 180 Deg.
700uS + (180 * 4.4444)
=> 700 + 799.992
= 1499.992 uS (approx due to rounding errors)

Note: made up numbers in the example and some movement assumptions.

1 Like

Hi Toni
360 will not divide evenly into 1000000 so you will only get an approximation.
I am still trying to figure out how you get a claimed “precision” servo under these circumstances. Of course if your pulse width can be adjusted in fractions of 1 microsecond you can get closer to “precision” but in most of the text I have seen on the devices used for the hobby market I think the term is used a bit loosely.
Cheers Bob

Edit add on
I have not had great experience with servos but most I have seen are between 1mSec and 2mSec (1000µSec) for 180º and at 90 requires a pulse of 1.5mSec or 1500µSec.

That is 5.55555(repeat) µSec per degree I think applies for most common hobby servos. I daresay that more sophisticated applications will have available much better and more accurate servos and the ability to drive them. They probably come with an appropriate price tag also. A bit out of reach for us mere mortals.

1 Like

Thanks to both of you.
I think I was complicating the issue, I didn’t need to do the conversion, just stick to angles throughout the code.
Its now all working perfectly with the PCA9685/Pico combination driving two SG90 servos via Mosquitto MQTT from the JMRI model rail package on the RPi.
Cheers
Toni

1 Like