Society of Robots - Robot Forum
Software => Software => Topic started by: offy on February 23, 2009, 02:30:15 PM
-
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.
#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);
}
}
-
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.
-
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.
-
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.
-
Got it almost working right. Now the servos go forwards, and backwards, when I only want them to go forward.
#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);
}
}
-
Change to
left.write(pos);
For both servos to spin the same direction.
-
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.
-
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:
void loop()
{
right.write(180);
left.write(0);
delay(11);
}
-
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.
-
Please specify what happens when "it didnt work". What happened?
Did you modify your servos for continuous rotation?
-
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...
-
Can you measure the output signal using a multimeter or an oscilloscope?
-
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.
-
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
-
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.