Equation for PULSOUT value for Certain Angle
RevC
Posts: 12
I am working with Board of Education and the BS2 Stamp and the standard servo that comes with it. What is the equation for deriving to PULSOUT value with a given angle in degrees?
90 degrees = 1.5ms with 20ms in between pulses.
While reading "What's a Microcontroller" I did not see an equation in the chapter where they covered this. Such equation does exist, right?
90 degrees = 1.5ms with 20ms in between pulses.
While reading "What's a Microcontroller" I did not see an equation in the chapter where they covered this. Such equation does exist, right?
Comments
As the PULSOUT changes up or down from 1.5 mS, the servo will turn clockwise or counterclockwise a certain amount. Try it by varying the PULSOUT from 1 mS to 2 mS.
Don't forget, the BS2 doesn't use mS directly, so you'll have to use the time units ( 2 uS, I think) of the chip.
Once you have control of the servo, you can generate your own formula to know what PULSOUT value corresponds to what angular position. It will be more or less, 0 deg at 1 mS, 90 deg at 1.5 mS and 180 deg at 2 mS.
Cheers,
Equation:
PULSOUT = Minimum PULSOUT Value + ( (Desired Angle x Full Span of PULSOUT)/180)
PULSOUT = MinPV + ( (DA x FSP)/180)
Minimum Pulsout Value: This is the value to get your horn pointing to 0°
Desired Angle: The angle you're looking for in degrees (e.g. 67°, 160°, etc)
Full Span value of PULSOUT from 0° to 180°: count from minimum range (250 for 0°), to maximum range (1250 for 180°) = 1250 - 250 = 1000
180: This is the max angle
First thing! Test your servo and find these values!:
For horn to point to 0° PULSOUT = ?? (I'm using 250 (this is Minimum PULSOUT value))
For horn to point to 180° = ?? (I'm using 1250 for 180° (this is Maximum PULSOUT value)) (your servo may go past 180)
So to find the PULSOUT value for 45°
PULSOUT value = MinPV + ( (DA x FSP)/180)
PULSOUT value = 250 + ( (45° x 1000)/180°)
PULSOUT value = 250 + (45000/180°)
PULSOUT value = 250 + 250
PULSOUT value = 500
PULSOUT 500 = 1000µs: This is because each unit given to PULSOUT is equal to 2µs (500x2µs = 1000µs = 1ms)
I hope this isn't confusing, and most importantly I hope I didn't miss something!
Hope this helps someone!
I did count on this, and I think you can achieve accuracy by adjusting the equation to your own numbers. I used 180° like when a square wave is used to symbolize a digital signal on a textbook, in the real world signals may not look that perfect, but it shows the principle.
In my defense I did "attempt" to put a disclaimer that this number may change, in retrospect I think I could have done better.
my original post:
[QUOTE=RevC;1201787
...
For horn to point to 180° = ?? (I'm using 1250 for 180° (this is Maximum PULSOUT value)) (your servo may go past 180)
...
[/QUOTE]
In my case I will be measuring my servo, I already know mine goes past 180°. So my equation may read something like PULSOUT value = MinPV + ( (DA x FSP)/192)
This value should actually be an other constant that the user has to find for their servo, just like Minimum PULSOUT value, etc..
Thanks, I just finished some code to have the BS2 calculate the angle for me. It was a pain to have the BS2 divide numbers above 65535 but it's doing it just fine. I'm going to test this with a full protractor, if it works well, I may make a video of it.
Could you please elaborate as to how I or anyone would use "third-order polynomial"? I am lacking in math but I'm curious to know more and interested in seeing how others use it.
It doesn't have to be long explanation, unless you wanna :-)! Just wanna know the principals or the concept you meant.
For the knock-off MG996R servos that I have:
0.48 msec ... 0-degrees
2.63 msec ... 180-degrees
Most beginner references like to suggest that servos are high-precision and consistent, with 1msec = 0-degrees; 1.5msec = 90-degrees; and 2msec = 180-degrees. I only found one that was quite frank that there is no standard or consistency. I feel so disillusioned.
Take a number, Pal!
I'm disillusioned, disconnected, disenfranchised, disinfected, and Disney-fied, courtesy of my twin baby girls.
Here I thought you were going to wow me with some genius math
Phatallica, you're right those numbers wont work. Thankfully the equation and method above works. I found it easier to use the mechanical limit on the right as 0°, then go on to measure which PULSOUT value will get the horn to swing to the left the farthest (when you know you're getting close to the mechanical limit of servo increase pulsout by one at a time, so you can find the exact moment your servo reaches the limit).
My 0° number is PULSOUT = 205 not 250 like WAM book says...
Maybe I'll make a video of it to show and tell. So far the tests have been pretty accurate.
duration = (3200-700)/180*angle + 700 =~ 14* angle +700.
Then I used this subroutine;
From anywhere in the main program I can call the subroutine with parameters 'servonr' and 'angle' , like;
and that will rotate the servo to the center 90 deg position.
Then I used a second, same brand same type servo and that turned out to have slightly different extreme and center positions, so the similar code did not position this servo at exactly 90 degrees.
If I want more accuracy, I can determine the min/max durations for each servo, declare them as constants and pass them as parameters to the subroutine, with in the subroutine;
Or, put them in an array; in subroutine;