I have discovered that this code works:
LeftFoot.attach(9); // attaches the servo on pin 9 to the servo object
RightFoot.attach(8); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
Serial.println("Begin Movement");
Serial.println("F");
Forward(5000);
Serial.println("B");
Backward(1000);
Stop(); // Writes both Servos to 90 (Stop)
LeftFoot.detach();
RightFoot.detach();
The effect is both servos forward for 5 seconds, both Servos back for one second, and then both servos stop.
However, when you remove the last two lines (Servo.detach) both servos continue spinning forward in some kind of pattern, on their own! There is nothing after this code snippet except an empty loop. Nothing is telling these servos to continue forward! So it's like "Stop()" does not stop the servos. Only when you detach them!
You need to calibrate them first!!
See the tutorial I linked earlier.
Power_Broker:
You need to calibrate them first!!
See the tutorial I linked earlier.
Oh right!
I suppose that with the other posts it slipped my mind. Do you really think it's a calibration issue?
I'm going to take a look at your tutorial now
stupid-questions:
Oh right!
I suppose that with the other posts it slipped my mind. Do you really think it's a calibration issue?
I'm going to take a look at your tutorial now
Yup, if you're sending a cont. rot. servo 90 and they still rotate, it's a calibration issue. I've experience using them for a model RC tank controlled by an Arduino.
Power_Broker:
Yup, if you're sending a cont. rot. servo 90 and they still rotate, it's a calibration issue. I've experience using them for a model RC tank controlled by an Arduino.
I have re-calibrated the Servos so that they both stop when sent "90"
However, I am still having an issue:
/* Sweep
by BARRAGAN <http://barraganstudio.com>
This example code is in the public domain.
modified 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Sweep
*/
#include <Servo.h>
Servo LeftFoot; // create servo object to control a servo
Servo RightFoot;
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void Stop() {
LeftFoot.write(90);
RightFoot.write(90);
}
//------------------------------------------------------
void WalkForward() {
LeftFoot.write(180);
RightFoot.write(0);
}
void WalkBackward() {
LeftFoot.write(0);
RightFoot.write(180);
}
void WalkLeft() {
LeftFoot.write(130);
RightFoot.write(130);
}
void WalkRight() {
LeftFoot.write(30);
RightFoot.write(30);
}
//------------------------------------------------------
void AttachFeet() {
LeftFoot.attach(8);
RightFoot.attach(9);
}
void DetachFeet() {
LeftFoot.detach();
RightFoot.detach();
}
void setup() {
Serial.begin(9600);
Serial.println("Attaching");
AttachFeet();
Serial.println("Attached");
}
void loop() {
WalkForward();
//WalkBackward();
//WalkLeft();
//WalkRight();
}
When I run each "Walk" function individually (in the loop by itsself, with the others commented out) it works fine. WalkForward() makes the bot go forward WalkBackward() makes the robot reverse, etc.
However, when I put two functions in the loop together, with a delay between them - the servos seem to get stuck doing one of the included functions.
The servos have been re-calibrated and are no longer spinning out of control (Thanks @Power_Broker!!!
) but they certainly do not behave normally! :o
(BY THE WAY: I have removed the Servos from the testing Arduino and put them into the actual Robot with an external battery pack. Should I put them back into the testing environment for now?)
Let's see the code for the behavior you just described.
If you have something like this:
void loop() {
WalkForward();
delay(3000);
WalkBackward();
//WalkLeft();
//WalkRight();
}
then you will not get what you likely expect.
You will get start walking forward.
Keep doing that for 3 seconds.
Start walking backwards but before the servos even get a chance to change, start walking forward.
Keep doing that for 3 seconds.
Start walking backwards but before the servos even get a chance to change, start walking forward.
and so on. It will look like you are only walking forward. The command is given to walk backward, but without a similar delay after the walk backward, you instantly start walking forward again.
vinceherman:
and so on. It will look like you are only walking forward. The command is given to walk backward, but without a similar delay after the walk backward, you instantly start walking forward again.
I understand what you're saying, but I was already putting a delay after "WalkBackwards()"
How do the servos react to this code? Be very specific.
#include <Servo.h>
Servo LeftFoot; // create servo object to control a servo
Servo RightFoot;
void AttachFeet()
{
LeftFoot.attach(8);
RightFoot.attach(9);
}
void setup()
{
Serial.begin(9600);
Serial.println("Attaching");
AttachFeet();
Serial.println("Attached");
}
void loop()
{
LeftFoot.write(90);
RightFoot.write(90);
delay(2000);
LeftFoot.write(50);
RightFoot.write(130);
delay(2000);
LeftFoot.write(130);
RightFoot.write(50);
delay(2000);
LeftFoot.write(130);
RightFoot.write(130);
delay(2000);
LeftFoot.write(50);
RightFoot.write(50);
delay(2000);
}
Do what Power_Broker said.
But I am curious what your loop looked like when you said it would get stuck in one mode.
Power_Broker:
How do the servos react to this code? Be very specific.
#include <Servo.h>
Servo LeftFoot; // create servo object to control a servo
Servo RightFoot;
void AttachFeet()
{
LeftFoot.attach(8);
RightFoot.attach(9);
}
void setup()
{
Serial.begin(9600);
Serial.println("Attaching");
AttachFeet();
Serial.println("Attached");
}
void loop()
{
LeftFoot.write(90);
RightFoot.write(90);
delay(2000);
LeftFoot.write(50);
RightFoot.write(130);
delay(2000);
LeftFoot.write(130);
RightFoot.write(50);
delay(2000);
LeftFoot.write(130);
RightFoot.write(130);
delay(2000);
LeftFoot.write(50);
RightFoot.write(50);
delay(2000);
}
I mean, I really can't be that specific.
The robot spins one direction for a while, and then goes straight, backward. Then it goes back to spinning in the same direction.
ROBOT MOVEMENT:
Program Starts
Robot Moves Backwards
Robot Spins Direction A For a While
Robot Moves Backwards Again
stupid-questions:
ROBOT MOVEMENT:
Program Starts
Robot Moves Backwards
Robot Spins Direction A For a While
Robot Moves Backwards Again
A link to a youtube vid would be nice if you don't mind.
Power_Broker:
A link to a youtube vid would be nice if you don't mind.
Well first here is a better description of what the SERVOS Are doing. I took a look at the code.
First they are in a STOP position. This is successful.
Next they are in a SPIN position. (Travelling opposite directions) This is successful
Next, they continue the same SPIN position. The sound coming from the servos change, but they do NOT change directions.
Next, they continue the same SPIN position. The sound coming from the servos change, but they do NOT change directions.
Next, the program hits the end of the loop and goes back to the initial STOP position. However, the Servos continue in the same SPIN position and don't stop. The program continues this way.
EDIT: See? It's like they're stuck in the same SPIN position, even though the program changes and the sound coming from the servos change.
Gosh, I don't know. Bad servos maybe?
Power_Broker:
Gosh, I don't know. Bad servos maybe?
It's just weird!
They were working great, and then all the sudden BOTH of them broke at the EXACT SAME TIME???
If you can't find anything wrong any further, then I guess I must've done something maybe???
Huh.
Well, since you seem to have experience with Servos, what do you recommend? I need Servos that are long-lasting and work reliably for years...
EDIT: I have a friend coming over tomorrow and I want to show him my robot. Luckily I found a pair of spare servos to replace these with. But that's only a temporary solution. I obviously need to look into higher quality, longer lasting servos
Do the spares work as intended?
I've only used the ones from sparkfun here.
Power_Broker:
Do the spares work as intended?
I just did a very basic test: one servo at a time plugged into the previously mentioned Testing Arduino. They both spun perfectly in both directions, and were able to change directions.
However, 90 degrees is not their resting position. When you set them to 90, they seem to "drift" a little bit, but they probably just need to be calibrated!
I will calibrate and test them on the robot tomorrow morning and give you an update.
Delta_G:
You mean 5V pins on the Arduino? They're not independent. They're hooked together. And the Arduino shouldn't be powering either of them off a 5V pin. It might work OK while they're free and not loaded, but as soon as you put them on the bot I would expect problems.
In the testing environment, I powered them with the 5V pin. In this scenario, they had no weight. (Because the Testing Arduino was not used on the robot)
When I connected the Servos to the robot, they were powered with external batteries (and a different Arduino - the one used in the robot) In the case of the robot, they did carry the weight of the robot. However, I was powering them with external batteries in that case.
Whenever they were powered by 5V they were being used on the Testing Arduino, solely for testing. Whenever they were supporting the robot, they were powered by an external power supply.
I assume that's all fine and dandy. Right?
Power_Broker:
Do the spares work as intended?
Yes! I just checked them with my robot. They work perfectly. Those other servos must've "went bad."
Does anyone know why those Servos could've just bit the dust? What can I do to maintain good Servos? For an Arduino component, they're not cheap!
stupid-questions:
Yes! I just checked them with my robot. They work perfectly. Those other servos must've "went bad."
Does anyone know why those Servos could've just bit the dust? What can I do to maintain good Servos? For an Arduino component, they're not cheap!
Time to do an autopsy!
I once bought a brand new RC bull dozer for my grand sons, at at a garage sale. Lady said it never worked. I figured I could fix it. It had several identical motors, all made in China. Every motor was FULL of dust! Cleaned and lubed, the tractor ran for years.
Paul