Society of Robots - Robot Forum
Software => Software => Topic started by: maverick monk on June 26, 2008, 03:47:43 PM
-
Hey guys, im back, and more confused than before. I still dont understand how to do servo control, Ive read the tutorials, and looked at the source code, but Im not good enough with c to be able to understand what does what. Can anyone help me?
-
What do you have coded so far? I mean, I'm sure you attempted to reverse engineer the $50 Robot code, no? :P
-
Sorry for the late reply, my computer went on the frits and ive just recentlystarted taking a look at this stuff again, yes i have tried, and failed, I just dont understand how it works
-
You have a pulse. This pulse is repetead 50 times per second. The width of the pulse determines the servo's horn angle.
Check this (http://www.izua.ro/tools/servo_calculator) for an animation.
-
so in code it would be like this for forward?
bring pin high
wait(250)
bring pin low
wait(1)
bring pin high
wait(250)
bring pin low
wait (1)
-
Ok, a servo pulse has a high time and a low time, totalling 20 miliseconds. The high time duration controlls the servo horn position. A 1 ms high time will make the horn go to 0 degrees (left), a 1.5 ms high time will make it go to 90 degrees (middle) and a 2 ms high time will make it go to 180 degrees (right). The low time will make the difference to the 20 ms period. In practice, we just set the high time for all servos and wait for about 15-20 ms at the end of the main loop. A servo modified for continuous rotation will rotate one way for a 1 ms pulse and the other way for a 2 ms pulse. A 1.5 ms pulse should make it stop.
So, your code will look like this:
do
bring servo1_pin high
delay_us(1000)
bring servo1_pin low
bring servo2_pin high
delay_us(2000)
bring servo2_pin low
delay_ms(20)
loop
However, Admin uses cycles to specify the high time, and that is different for each microcontroller clock (1MHz to 16 or more MHz). Read this thread to see how are the cycle numbers determined for your setup:
http://www.societyofrobots.com/robotforum/index.php?topic=2724.0 (http://www.societyofrobots.com/robotforum/index.php?topic=2724.0)
-
If you want to this perfectly:
A servo checks the signal after 20ms, it checks the signal at 50Hz.
Lets say you want to create a squarewave with a pulsewidth of 1ms (center servo).
Your actual code should look like this:
Bring servo pin high
Wait (pulsewidth)
Bring servo pin low
Wait (20ms - pulsewidth)