2

Author Topic: Servo right; wont move, servo left; will! C programming roboduino  (Read 3294 times)

0 Members and 1 Guest are viewing this topic.

Offline offyTopic starter

  • Supreme Robot
  • *****
  • Posts: 340
  • Helpful? 1
I have the following code. It compiles fine and everything. Until I run it. The left servo starts moving. The right servo stands still. The right servo works.

Code: [Select]
#include <Servo.h>
 
Servo right;
Servo left;
 
int pos = 0;
int posl = 0;
 
void setup()
{
  right.attach(9);
  left.attach(10);
}
 
 
void loop()
{
  for(pos = 0; pos < 180; pos += 1)
  for(posl = 180; posl >= 1; posl -= 1)
  {
    right.write(pos);
    delay(15);
    left.write(posl);
    delay(15);
  }
  for(posl = 0; posl < 180; posl += 1)
  for(pos = 180; pos>=1; pos-=1)
  {   
    right.write(pos);
    delay(15);
    left.write(posl);   
    delay(15);
  }
}

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: Servo right; wont move, servo left; will! C programming roboduino
« Reply #1 on: February 23, 2009, 02:38:49 PM »
Have you tried swapping the servos ie unplug the right servo and plug it into the left port and vice versa.

If the problem moves with the servo (ie the left servo now doesn't work) - then the servo is at fault.

If the problem stays with the port(ie its still the right servo giving problems) - then the circuit is at fault.
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 offyTopic starter

  • Supreme Robot
  • *****
  • Posts: 340
  • Helpful? 1
Re: Servo right; wont move, servo left; will! C programming roboduino
« Reply #2 on: February 23, 2009, 02:47:42 PM »
I changed ports in the servo. And now right is working.

So I think my servo is messed up... Crap and I just bought it too.

The servo works fine for the first set, but after that nope. It moves, but really slow, while the other one goes normals.
« Last Edit: February 23, 2009, 02:52:19 PM by offy »

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: Servo right; wont move, servo left; will! C programming roboduino
« Reply #3 on: February 23, 2009, 05:49:32 PM »
OK - so from what you are saying - when you swapped the servos it was the same physical servo that was playing up.

So next tests with the offending servo:
1 - If you use the center-a-servo.hex file from Admin then does the servo spin at all. It shouldn't. If it does then its not properly centered.
2 - Try changing the length of pulse you send to the servo. It could be that this one requires a different pulse length compared to the other in order to get the sameresult. So fiddle to see if you can make it spin faster.

Unfortunately it is a kind of fact of life IMHO that servos aren't comparable. In their unmodified form then they probably all move to the 'correct' angle (due to the feedback pot/PID) but of course they may do this at slightly different speeds. With a modified servo then it is this 'speed' that you are relying on for the wheel speed.

DC motors are as bad - but at least the 'centering' is consistent - ie 0V.

Trying to get a robot to go in a straight line is actually bl**dy difficult!!

I try to put sticky labels onto my servos to write down what pulse was required for centering and for full speed reverse and forward. I use a crude encoder to judge when a motor is 'full' reverse/forward. That way I know its characteristics when I re-use it.
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 offyTopic starter

  • Supreme Robot
  • *****
  • Posts: 340
  • Helpful? 1
Re: Servo right; wont move, servo left; will! C programming roboduino
« Reply #4 on: February 23, 2009, 07:33:44 PM »
Got it almost working right. Now the servos go forwards, and backwards, when I only want them to go forward.

Code: [Select]
#include <Servo.h>
 
Servo right;
Servo left;
 
int pos = 0;
int posl = 0;
 
void setup()
{
  right.attach(9);
  left.attach(10);
}
 
void loop()
{
for(pos = 0; pos <= 180; pos++)
  {
    right.write(pos);
    left.write(180 - pos);
    delay(11);

  }
}

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
Re: Servo right; wont move, servo left; will! C programming roboduino
« Reply #5 on: February 23, 2009, 07:38:22 PM »
Change to
Code: [Select]
left.write(pos);
For both servos to spin the same direction.

Offline offyTopic starter

  • Supreme Robot
  • *****
  • Posts: 340
  • Helpful? 1
Re: Servo right; wont move, servo left; will! C programming roboduino
« Reply #6 on: February 23, 2009, 07:47:22 PM »
The servos are turned around for each site, so they need to go different directions. So right now they go straight, but than they go back again, and repeats. Look at the new code I posted.

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
Re: Servo right; wont move, servo left; will! C programming roboduino
« Reply #7 on: February 23, 2009, 07:51:31 PM »
I'm not sure about what values Arduino uses to drive servos, but the reason it goes back is because your for loop is restarting. I reccomend you read a basic C tutorial, it should help a lot.

To answer your question:
Code: [Select]
void loop()
{
right.write(180);
left.write(0);
delay(11);
}

Offline offyTopic starter

  • Supreme Robot
  • *****
  • Posts: 340
  • Helpful? 1
Re: Servo right; wont move, servo left; will! C programming roboduino
« Reply #8 on: February 23, 2009, 07:58:42 PM »
it didn't work. I just want my servos to go straight none stop. Once I know that I can code the rest, well besides the IR but I will figure that out.

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
Re: Servo right; wont move, servo left; will! C programming roboduino
« Reply #9 on: February 23, 2009, 08:09:15 PM »
Please specify what happens when "it didnt work". What happened?

Did you modify your servos for continuous rotation?

Offline offyTopic starter

  • Supreme Robot
  • *****
  • Posts: 340
  • Helpful? 1
Re: Servo right; wont move, servo left; will! C programming roboduino
« Reply #10 on: February 23, 2009, 08:15:53 PM »
I have modified my servos already.

The "not working" was they roated.. like 1 degrees and stopped.

Also I hooked up code for 180 degrees and it only goes about... 140 degrees or so...
« Last Edit: February 23, 2009, 09:07:27 PM by offy »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,658
  • Helpful? 169
    • Society of Robots
Re: Servo right; wont move, servo left; will! C programming roboduino
« Reply #11 on: February 26, 2009, 09:40:40 PM »
Can you measure the output signal using a multimeter or an oscilloscope?

Offline offyTopic starter

  • Supreme Robot
  • *****
  • Posts: 340
  • Helpful? 1
Re: Servo right; wont move, servo left; will! C programming roboduino
« Reply #12 on: February 26, 2009, 10:09:24 PM »
I don't have a multimeter or an oscilloscope.

Can someone just give me some code to make servo left go forward, and servo right go backwards, or the other way around. I have been on google, forums, and asking around and no help so far.
« Last Edit: February 26, 2009, 10:10:45 PM by offy »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,658
  • Helpful? 169
    • Society of Robots
Re: Servo right; wont move, servo left; will! C programming roboduino
« Reply #13 on: February 28, 2009, 09:26:28 PM »
I don't have a multimeter or an oscilloscope.

Can someone just give me some code to make servo left go forward, and servo right go backwards, or the other way around. I have been on google, forums, and asking around and no help so far.
Ummm the $50 Robot code and the Arduino servo code are 100% compatible (they use the same exact microcontroller).

Also, you *really* should buy a multimeter if you are serious about robotics. Its a tool you'll find yourself using daily, and will save tons of hair pulling! :P

Offline offyTopic starter

  • Supreme Robot
  • *****
  • Posts: 340
  • Helpful? 1
Re: Servo right; wont move, servo left; will! C programming roboduino
« Reply #14 on: March 02, 2009, 04:40:42 PM »
Ok, in a matter of fact I do have a multimeter, well my dad does but, close enough. I found out I forgot to modify something in the servo. So I am working on that right now. The glue is drying. I will first try my code, if it doesn't work I will go ahead and use the $50 robot code.
« Last Edit: April 08, 2009, 05:16:12 PM by offy »

 


Get Your Ad Here