go away spammer

Author Topic: Servo control?  (Read 3757 times)

0 Members and 1 Guest are viewing this topic.

Offline maverick monkTopic starter

  • Robot Overlord
  • ****
  • Posts: 204
  • Helpful? 0
Servo control?
« 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?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Servo control?
« Reply #1 on: July 01, 2008, 08:38:13 PM »
What do you have coded so far? I mean, I'm sure you attempted to reverse engineer the $50 Robot code, no? :P

Offline maverick monkTopic starter

  • Robot Overlord
  • ****
  • Posts: 204
  • Helpful? 0
Re: Servo control?
« Reply #2 on: September 09, 2008, 03:30:04 PM »
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

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
    • izua electronics
Re: Servo control?
« Reply #3 on: September 10, 2008, 02:35:32 AM »
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 for an animation.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline maverick monkTopic starter

  • Robot Overlord
  • ****
  • Posts: 204
  • Helpful? 0
Re: Servo control?
« Reply #4 on: September 14, 2008, 01:20:25 PM »
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)

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
    • Ro-Bot-X Designs
Re: Servo control?
« Reply #5 on: September 14, 2008, 06:50:22 PM »
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
Check out the uBotino robot controller!

Offline MadMax

  • Full Member
  • ***
  • Posts: 58
  • Helpful? 0
Re: Servo control?
« Reply #6 on: September 15, 2008, 09:44:10 AM »
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)

 


Get Your Ad Here