Author Topic: Servo centering and LED question $50 robot  (Read 5773 times)

0 Members and 1 Guest are viewing this topic.

Offline boybTopic starter

  • Jr. Member
  • **
  • Posts: 27
  • Helpful? 0
Servo centering and LED question $50 robot
« on: August 07, 2008, 12:33:56 PM »
I am not sure if anyone else ran into this problem but the hex code did not center my servo motors for modification, so I have to edit the code to center them myself.  If anyone else had that trouble please let me know.

I am getting by with this code below, but the thing is when I run this code the LED flashes on for a second and then turns off.  With this code below shouldn't the LED stay on constantly?

------------------------------------------

#include "SoR_Utils.h"


int main(void)
   {

   LED_on();

while(1)
   {
   servo_left(41); //modify number here until it centers
   }

   return 0;
}


-------------------------------------------------

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Servo centering and LED question $50 robot
« Reply #1 on: August 09, 2008, 08:06:59 AM »
Yea, the LED should stay on forever here . . .


try this code with the delay:
Code: [Select]
#include "SoR_Utils.h"


int main(void)
   {
   LED_on();

while(1)
   {
   servo_left(41); //modify number here until it centers
   delay_cycles(5000);
   } 

   return 0;
}

Offline Gertlex

  • Supreme Robot
  • *****
  • Posts: 763
  • Helpful? 24
  • Nuclear Engineer · Roboticist
    • Index of Oddities
Re: Servo centering and LED question $50 robot
« Reply #2 on: August 09, 2008, 12:19:55 PM »
Side question here: isn't 41 a really low value to send?  I think I found 700 to be center value for my servos, and ±400 to be the range from there.

(regardless, I use a separate servo controller now so I simply use 0-254 for my range of positions)
I

Offline boybTopic starter

  • Jr. Member
  • **
  • Posts: 27
  • Helpful? 0
Re: Servo centering and LED question $50 robot
« Reply #3 on: August 09, 2008, 04:32:43 PM »
The "Servo_Left" function though has a 200 delay inside it...

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,431
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
    • Nerdcore - Programming, Electronics, Mechanics
Re: Servo centering and LED question $50 robot
« Reply #4 on: August 09, 2008, 05:43:53 PM »
those are the values for running at 1MHz

Offline boybTopic starter

  • Jr. Member
  • **
  • Posts: 27
  • Helpful? 0
Re: Servo centering and LED question $50 robot
« Reply #5 on: August 12, 2008, 04:43:02 PM »
Quote
#include "SoR_Utils.h"


int main(void)
   {
   LED_on();

while(1)
   {
   servo_left(41); //modify number here until it centers
   delay_cycles(5000);
   } 

   return 0;
}

When I try that the servo gitters a lot and the LED does not turn on.  I don't understand why but when I upload the simple .hex code it turns the LED on but does not center it.  Every time I try different number with this code I cannot seem to get it to center it right, or have the LED turn on.  I just feel really stuck, I don't know why this isn't working.

I have tried number between 20 - 40 and it seems to move it to the same place.  Also, there is a 200 delay cycle inside the "servo_left" function so I don't think you would need to put that after.

Has anyone else ran into this problem and know how to fix it?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Servo centering and LED question $50 robot
« Reply #6 on: August 12, 2008, 05:21:56 PM »
Use a multimeter and check voltages on your battery, and use the Hz function on the signal pin for the servo.

Report back your findings . . .

Also, are you using the ATmega168 or ATmega8? What fuses are you using? Which programmer?

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Servo centering and LED question $50 robot
« Reply #7 on: August 12, 2008, 05:23:40 PM »
Hi boyb
I'm slightly confused by your opening comment:-
Quote
I am not sure if anyone else ran into this problem but the hex code did not center my servo motors for modification, so I have to edit the code to center them myself.  If anyone else had that trouble please let me know.

The hex code does not center your servo for you. You have to upload the code, run it, and then adjust your servo by hand so that it stops rotating (ie it is centered). Is this what you did?

Assuming you center your servo correctly then you shouldn't need to change the 'center' value in your code (although it is possible you may need to change to 100% fwd and 100% reverse values).

Can you confirm your processor and what clock speed you are using.

If your LED isn't working then you may have a soldering issue. Does the following make your LED flash?
Code: [Select]
#include "SoR_Utils.h"


int main(void)
   {

while(1)
   {
   LED_on();
   delay_cycles(5000);
   LED_off();
   delay_cycles(5000);
   } 

   return 0;
}

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: Servo centering and LED question $50 robot
« Reply #8 on: August 12, 2008, 05:37:41 PM »
The LED works when I use the hex code on the website for modifying a servo.  But when I try this code it does not.

The reason I am playing around with the code is that for some reason the hex code provided does not center the servo, it puts it about 60/120degrees for some reason, which is kind of a big deal off.

I am using the cheap programmer, with 10 pin header and an atmega8 chip.

I did check the soldering about a million times and I don't see anything wrong.

The batteries NiMH and are rated at 6V and 2300mAh.  When fully charged the multimeter tells me they're closer to 6.8V instead of 6, but drop slowly as I use it (I was told in an alternative post that this was normal).

Also, could you please let me know the Hz function?

I have got almost everything built but I still don't have the servo's modified, because I can't get to seem to get them to center...

Thanks again for the help.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Servo centering and LED question $50 robot
« Reply #9 on: August 12, 2008, 07:56:02 PM »
It sounds like you didn't physically modify it properly as Webbot said. You need to move the pot around until it centers.

Quote
Also, could you please let me know the Hz function?
There is a spot on the multimeter dial labeled 'Hz' which is useful for measuring a frequency (such as a servo signal).

Offline boybTopic starter

  • Jr. Member
  • **
  • Posts: 27
  • Helpful? 0
Re: Servo centering and LED question $50 robot
« Reply #10 on: August 13, 2008, 04:06:21 PM »
I haven't modified the servo at all actually.

I have not taken the servo apart.  When I upload the hex code to the Atmega8 to modify the servo it does not center the servo, I tested this by marking the two extremes of the servo wheel (by hand) and then marking the location the hex code placed it.  It was much more like 60/120 degrees, which is rather large.

So I had asked in an earlier post and was provided with the code:

Code: [Select]
#include "SoR_Utils.h" //includes all the technical stuff


int main(void)
{
LED_on();

while(1)
{
servo_left(40);//modify number here until it centers
       delay_cycles(xxx);
}

return 0;
}

1. My first question is, why is there a "delay_cycles()" function after the "servo_left()" function, when the servo_left() function has the following code (there is already a "delay_cycle()" command in it):

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

2. Second, when I try to add the "LED_on()" function before the while loop under "main()" the LED does not turn on.  But it does turn on when I simply upload the hex file found in the "modifying the servo" tutorial.

3. I cannot seem to find a value to put in there that will center it, it seems to just put it at one extreme (which makes me think it's either too high or too low, likely too low).  Is there any way to tell what kind of a value to put in there?

4. Does anyone have the c code used exactly in the hex file given to upload?

Thanks again for all the help, I'm just having a really hard time centering these things and furthermore progressing in the robot.
« Last Edit: August 13, 2008, 04:07:01 PM by boyb »

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Servo centering and LED question $50 robot
« Reply #11 on: August 13, 2008, 05:45:51 PM »
Quote
I haven't modified the servo at all actually.

I have not taken the servo apart.  When I upload the hex code to the Atmega8 to modify the servo it does not center the servo,

From these 3 sentences it would appear that you completely fail to understand what is meant by 'centering a servo' - see http://www.societyofrobots.com/actuators_modifyservo.shtml. I would suggest that you re-read these parts of the tutorial. If you 'have not taken the servo apart' then you cannot have even attempted the instructions!

Unless you do this correctly then, I'm afraid, the rest of your questions are somewhat superfluous.
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: Servo centering and LED question $50 robot
« Reply #12 on: August 13, 2008, 06:19:08 PM »
boyb, I strongly suspect you have the timing set up incorrectly. If the pulse is wrong, the servo will likely max out at a particular angle.

You need to tell us how you set the timers up, as well as the fuses, or we can't help you.

I also recommend hooking it up to an oscope to measure the square wave servo signal.

Offline boybTopic starter

  • Jr. Member
  • **
  • Posts: 27
  • Helpful? 0
Re: Servo centering and LED question $50 robot
« Reply #13 on: August 13, 2008, 06:54:52 PM »
I have set everything up as per the tutorial, same value for all components and provided all the code that i used.  How can the timing be different?

Also, I shouldn't have to take it apart yet, if the wheel on the servo motor doesn't spin to the middle of it's full rotation, then it isn't centering, correct?

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Servo centering and LED question $50 robot
« Reply #14 on: August 13, 2008, 07:40:57 PM »
Your components and code may be correct - but you have to tweak the hardware (servos) to fit in with everything else.

Quote
Also, I shouldn't have to take it apart yet, if the wheel on the servo motor doesn't spin to the middle of it's full rotation, then it isn't centering, correct?
In an ideal world - you are right. But.....


I suggest you take the servo apart and check that when you are adjusting the pot that you can make it spin clockwise and counter-clockwise - and finally settle on a position where it no longer moves (ie it is centered as far as your code is concerned and not as far as your eyeballs are concerned).

The question you are asking are logical - but you just need to get that screwdriver out of the toolbox !!

Let me know once you've done that.

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: Servo centering and LED question $50 robot
« Reply #15 on: August 13, 2008, 08:16:22 PM »
I did!

I modified them both.  I guess I've tried enough alternatives, even if it's not quite centered, I can compensate for that with the code.

Thanks again.

Offline Adityav95

  • Full Member
  • ***
  • Posts: 64
  • Helpful? 0
Re: Servo centering and LED question $50 robot
« Reply #16 on: December 26, 2010, 10:27:40 AM »
@webbot: (n00b question) so centering a servo does not mean rotating to extreme left then rotating to extreme right and taking average of the 2? :( I'm plannin to modify my hs-425bb, and that's wat i thought was to be done. Could u pls tell me wat "centering a servo" means then?  ???


Offline VegaObscura

  • Robot Overlord
  • ****
  • Posts: 153
  • Helpful? 6
Re: Servo centering and LED question $50 robot
« Reply #17 on: December 26, 2010, 02:20:08 PM »
Centering a servo means getting the potentiometer into just the right spot so it doesn't move when you send the command for it to stop.  "Centering" is actually a misleading term, because usually the horn will not be perfectly between the two extremes, and sometimes won't even be close.  But once the mechanical stop is removed, it won't matter how far they used to be able to turn, all that matters is when the controller sends the command for 'center', the servo stops.

As for your LED, try changing LED_on() to LED_off().  If that doesn't work, what I did was unsolder the lead of the LED that's going to pin 7, and move it to pin 8.  Also you may or may not need to unsolder it and flip it around.  If you ordered the LEDs that were in the parts list from the $50 tutorial, those particular LEDs have been known to have their anode and cathode backwards for some reason.
« Last Edit: December 26, 2010, 02:25:49 PM by VegaObscura »

 


Get Your Ad Here