Author Topic: $50 robot servo questions  (Read 6422 times)

0 Members and 1 Guest are viewing this topic.

Offline boybTopic starter

  • Jr. Member
  • **
  • Posts: 27
  • Helpful? 0
$50 robot servo questions
« on: July 19, 2008, 11:16:49 AM »
Hi,

I purchased the Hitec HS-311 as suggested and I had a few questions.

The tutorial says they should rotate 90 degrees, but mine seem to rotate about 180 degrees (forcing them with my hand).

Then when I uploaded the hex code (for modification purposes) and it would spin to a specific position, but that position is not the center of it's rotation.

I tried it on the two different motors and it's the same.

Please let me know if I'm doing something wrong and how to fix it.

Thanks!

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: $50 robot servo questions
« Reply #1 on: July 19, 2008, 12:18:41 PM »
Unmodified, the servos rotate a total of ~180 degrees (90 degrees both ways from center).

Follow the tutorial on how to modify them for continuous rotation.

Quote
Then when I uploaded the hex code (for modification purposes) and it would spin to a specific position, but that position is not the center of it's rotation.
Out of curiousity, how far from the center is it located after programming the microcontroller? Is this using the modify servos hex or the photovore hex?

Offline boybTopic starter

  • Jr. Member
  • **
  • Posts: 27
  • Helpful? 0
Re: $50 robot servo questions
« Reply #2 on: July 19, 2008, 02:01:13 PM »
modify servo code, and it's about 60/120 degree difference from one side to the other.  that seems way too much...

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: $50 robot servo questions
« Reply #3 on: July 19, 2008, 09:40:43 PM »
Yea thats a bit much, but isn't too big of a deal.

If you want to tweak it until it centers, program and run this code:

Code: [Select]
while(1)
{
wheel_left(30);//modify number here until it centers
delay_ms(20);
}

Offline boybTopic starter

  • Jr. Member
  • **
  • Posts: 27
  • Helpful? 0
Re: $50 robot servo questions
« Reply #4 on: July 20, 2008, 11:00:01 AM »
And then when I run the code that controls the robot I can take that same number again and use it as the center position there as well?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: $50 robot servo questions
« Reply #5 on: July 20, 2008, 11:20:51 AM »
Yeap!

Offline boybTopic starter

  • Jr. Member
  • **
  • Posts: 27
  • Helpful? 0
Re: $50 robot servo questions
« Reply #6 on: July 21, 2008, 07:46:11 PM »
Thanks!

Any idea why mine would be different though?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: $50 robot servo questions
« Reply #7 on: July 21, 2008, 07:57:46 PM »
hmmmm I modified my servos many years ago, so I probably just didn't modify them right . . . some of my HS-311 servos have been around for ~7 years now . . . back when I was a noob :P

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
    • Ro-Bot-X Designs
Re: $50 robot servo questions
« Reply #8 on: July 22, 2008, 05:30:29 AM »
It is very important to determine the center of the servo movement BEFORE you glue the pot in place! Otherwise, you may end up with 2 servos with different center points that will yeld different forward and backward max speeds. You want the servos to be as similar as possible in behaviour. Same speed for both when going forward, same speed for both when going backward. This is because actually one of the servos will rotate in the oposite direction of the other, so if they have different end points (different speeds) the robot will veer towards one side.

So, tweak the center value until both servos have the same phisical center point and also check their phisical end points and make the center to be exactly in the middle. THEN modify them for continuous rotation! I was lucky I didn't glue the pot in place but made a slot in the pot axle and drilled a hole in the center of the spline (smaller diameter than the one of the screw) and used a flat clock's man screw driver to adjust the pot anytime it is needed. Better yet, Parallax servos have the pot replaced with an adjustable one and a hole on the side of the servo for adjustment.

Now the purpose of modifying your own servos is to get better speed. Standard servos have about one rotation per second. IF you need more speed, find faster servos and mod them yourself. Otherwise, just buy the readily modified ones (Parallax for example, these servos are Futaba servos, very good ones) and adjust the center.
Check out the uBotino robot controller!

Offline boybTopic starter

  • Jr. Member
  • **
  • Posts: 27
  • Helpful? 0
Re: $50 robot servo questions
« Reply #9 on: July 22, 2008, 09:44:45 AM »
Does it matter what the delay cycle is after the pulse sent to the servo?

This was the code you gave me to edit:

while(1)
   {
   servo_left(40);//modify number here until it centers
   delay_cycles(20);  //I think I can take this out though because it is in the "servo_left" function. Could you confirm this in case I'm overlooking something
   }


And it's used in reference to this in the SoR_Utils.h file:

void servo_left(signed long int speed)
   {
   PORT_ON(PORTD, 0);
   delay_cycles(speed);
   PORT_OFF(PORTD, 0);//keep off
   delay_cycles(200);
   }


Assuming I was right in taking the delay_cycles function out of the first step, does it matter what the delay_cycles value in the servo_left function (200) is set to?  Or is it just the delay_cycles(speed) that matters?

I think I am going to try calculating the center myself, then program it to check, but I don't understand if the delay_cycles between pulses is important or not.

Thanks!

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: $50 robot servo questions
« Reply #10 on: July 22, 2008, 10:04:05 AM »
Quote
Does it matter what the delay cycle is after the pulse sent to the servo?
Yes. You don't want to send a signal to a servo more than once every 10-20ms, or it could vibrate and even heat up. If you send the signal less than ~3 times per second, it won't have as much torque/speed as you want, along with other problems.

Exact timing however depends on the servo you are using.

Offline boybTopic starter

  • Jr. Member
  • **
  • Posts: 27
  • Helpful? 0
Re: $50 robot servo questions
« Reply #11 on: July 29, 2008, 12:38:19 AM »
Is there a way to correlate the delay time cycles to ms?

And why not just use the PWM channel to control the servo instead?
« Last Edit: July 29, 2008, 01:26:19 AM by boyb »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: $50 robot servo questions
« Reply #12 on: July 29, 2008, 04:54:43 AM »
Quote
Is there a way to correlate the delay time cycles to ms?
http://www.societyofrobots.com/microcontroller_time_cycles.shtml

Quote
And why not just use the PWM channel to control the servo instead?
You could. But most people find themselves using more servos than there are PWM channels available.

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: $50 robot servo questions
« Reply #13 on: July 29, 2008, 12:50:01 PM »
Quote
But most people find themselves using more servos than there are PWM channels available.

I believe it would be useful to have a 'center servo' program that uses PWM - just because it is more accurately linked to the processor clock.

Whereas the current program is susceptible to various things: especially code optimization - which is probably why you supply a compiled HEX file rather than source code.

I find that servos which have been exactly centered using the current 'delay' routine and are then connected via PWM do tend to behave differently. So I guess it comes down to which is more accurate: PWM or delay cycles - my bet would be on the first.

Accurate 'centering' is key to then allowing the same servo to be driven via PWM or via delays - and you need to expect that they will behave the same in both scenarios. This hasn't been my experience - which tends to end up with servos tied up to certain boards.

Given the relative cheapness of an ATMega8 then I have a dedicated board which only has the headers for the PWM output pins. I use another board to program it - so I don't even need the AVR/ISP connector pins. I use this board for nothing else other than for centering servos via PWM. It may seem like a luxury but at least I know that all my servos have been set the same way.

Quote
Does it matter what the delay cycle is after the pulse sent to the servo?
I know that most of you guys hate C++ but this is an example of where it really helps. The standard $50 code will just waste time in order to make sure that signals aren't sent to the servo too quickly. In C++, as per my library in the tutorials, I keep track of when the last command was sent and so will ignore any new commands that occur in the rest of the cycle time. So rather than ALWAYS wasting 20ms it can return immediately to allow the rest of your code to work at full speed and will only issue a new command to the servo once the 20ms 'breathing period' has elapsed.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline boybTopic starter

  • Jr. Member
  • **
  • Posts: 27
  • Helpful? 0
Re: $50 robot servo questions
« Reply #14 on: July 30, 2008, 12:48:53 AM »
While I admit some of this is slightly over my head...thanks for the explanation, it does help.

Programming is definitely my Achilles' heel as of now, but if you have a PWM program written I would love to see it.


As for the timing issue.  I found this in the photovore code:

delay_cycles(cycles);
Delays - you can make your robot wait for a certain amount of time with this function.
Put the number of computational cycles to delay in the ().
23 cycles is about .992 milliseconds
to calculate: 23/.992*(time in milliseconds to delay) = cycles
Check servo datasheet where it says: 'Direction: Clockwise/Pulse Traveling 1500 to 1900usec'


and if you do the calculation 23/0.992*1.5 = 34.78.  This is assuming 1.5 centers the servo.  Then in this case using a delay of 35 is the closest to centering that you can achieve without PWM.  Let me know if this sounds right to you.

If you need to reference anything I included the code below this line.


int main(void)
   {

while(1)
   {
   servo_left(40);
   }

   return 0;
}

------

void servo_left(signed long int speed)
   {
   PORT_ON(PORTD, 0);
   delay_cycles(speed);
   PORT_OFF(PORTD, 0);//keep off
   delay_cycles(200);
}

------

void delay_cycles(unsigned long int cycles)
   {
   while(cycles > 0)
      cycles--;
}



Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: $50 robot servo questions
« Reply #15 on: July 30, 2008, 11:04:32 AM »
Quote
This is assuming 1.5 centers the servo.  Then in this case using a delay of 35 is the closest to centering that you can achieve without PWM.
You will find servos are inaccurate by like +/- 2 degrees, and even more when force is applied. This is because of errors in the built in control system, and gearing backlash.

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: $50 robot servo questions
« Reply #16 on: July 30, 2008, 06:45:19 PM »
Quote
Programming is definitely my Achilles' heel as of now, but if you have a PWM program written I would love to see it.

My C++ library in the Members tutorial shows how to do this. You can either use this, or if you prefer C, then you can either C'ify my source code or search the rest of the forum.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: $50 robot servo questions
« Reply #17 on: July 30, 2008, 06:57:29 PM »
AVRlib has PWM code