Two Servos Not Changine Direction

I have two continuous rotation servos as wheels for my robot. For some reason, they do not change direction when I run this code. (Which should make them change direction)

/* 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;
Servo RightFoot;


void RunForward() {
  LeftFoot.write(150);
  RightFoot.write(10);
}
void RunBackward() {
  LeftFoot.write(10);
  RightFoot.write(150);
}

void RunLeft() {
  LeftFoot.write(150);
  RightFoot.write(150);
}

void RunRight() {
  LeftFoot.write(30);
  RightFoot.write(30);
}

void Stop() {
  LeftFoot.write(90);
  RightFoot.write(90);
}

//------------------------------------------------------

void WalkForward() {
  LeftFoot.write(130);
  RightFoot.write(30);
}
void WalkBackward() {
  LeftFoot.write(30);
  RightFoot.write(130);
}

void WalkLeft() {
  LeftFoot.write(130);
  RightFoot.write(130);
}

void WalkRight() {
  LeftFoot.write(30);
  RightFoot.write(30);
}

void AttachFeet() {
  LeftFoot.attach(7);
  RightFoot.attach(6);
}

void DetachFeet() {
  LeftFoot.detach();
  RightFoot.detach();
}

void setup() {
  AttachFeet();
}

void loop() {
  WalkForward();
    delay(1000);
  WalkBackward();
  delay(1000);
}

Have you written a test program to prove they can turn both directions?

Paul

Paul_KD7HB:
Have you written a test program to prove they can turn both directions?

Paul

I have used them before in both directions.
Truthfully, my robot was working fine. It could go backword (spin both servos backward) forward (spin both servos forward) left (spin servos in oppisite directions) and right (spin both servos in the opposite directions of left)

Just recently, I noticed this problem and I don't know what I changed to cause it!

Here is a better description of the Servo behavior.
They will go one direction, they will switch direction, but they won't switch directions again! (loop)

stupid-questions:
Here is a better description of the Servo behavior.
They will go one direction, they will switch direction, but they won't switch directions again! (loop)

IS all the above true each time you boot the Arduino?

Paul

Paul_KD7HB:
IS all the above true each time you boot the Arduino?

Paul

I'm sorry, I'm not explaining this well. After closer observation I think I better understand the symptoms of the problem, so hopefully I can explain them better.

Take a look at this code:

  RightFoot.write(30); //First Position
  LeftFoot.write(130);
  delay(5000);
  RightFoot.write(130); //Second Position
  LeftFoot.write(30);
delay(5000);

When this bit of code is run (in the loop() function) First Position will get executed. What I'd expect this code to do is put both Servos into first position for 5 seconds, and then set both Servos into second position for 5 seconds. After the five second the function would loop and go back to first position. But this is not the case. Instead, the motors go to first position for five seconds, and then stay stuck in second position, and never go back to first!

I'd just fiddle around more. Write more lines, change 5000 to 10000, switch the order of first and second position, whatever. Just to see what happens each time. Could it be that voltage drops after 4-5 seconds and nothing happens after that? Due to bad batteries?

How are the servos wired and powered?

Delta_G:
How are the servos wired and powered?

The control pins are wired to pins 7 and 6. The power and grounds are connected to breadboard ground and power rails. The ground and power rails are connected to a 4xAA battery pack wired through a switch. Breadboard ground rail is wired to Arduino Ground as well.

I have played around a little more and have noticed something. One servo is working fine. It goes forward and back. The other servo is the one that can't switch directions. So while one servo works properly, the other one is not. Is the servo shot? Do I need a new one?

stupid-questions:
I have played around a little more and have noticed something. One servo is working fine. It goes forward and back. The other servo is the one that can't switch directions. So while one servo works properly, the other one is not. Is the servo shot? Do I need a new one?

Did you calibrate the servos? I bet it's a calibration issue.

Power_Broker:
Did you calibrate the servos? I bet it's a calibration issue.

Um....

Yeah, man! Of course I did... totally.. hehe... definatly... yup... :confused:

Just kidding. I have no idea how to "calibrate the servos" :o

How do I do that?

When I run the one funky servo on a separate Arduino board, it works fine with the "Sweep" example program, implying that the Servo doesn't need to be replaced.

Can you write a sweep for both servos and put it on your card in the robot?

vinceherman:
your card in the robot

What?

vinceherman:
Can you write a sweep for both servos and put it on your card in the robot?

Do you mean a "double-sweep" like this? (With both servos

/* 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 myservo;  // create servo object to control a servo
Servo myservo2;
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo2.attach(8);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    myservo2.write(pos);
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos); 
    myservo2.write(pos);// tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

Plugged both servos into the seperate Arduino and they both worked perfectly!

stupid-questions:
Um....

Yeah, man! Of course I did... totally.. hehe... definatly... yup... :confused:

Just kidding. I have no idea how to "calibrate the servos" :o

How do I do that?

Tutorial.

oops, meant to say board, not card.

It sounds like you have 2 arduinos? One in your robot and another one.
You got the sweep sketch to run on your other board.

Can you get the servo sweep to talk to 2 servos?

vinceherman:
oops, meant to say board, not card.

It sounds like you have 2 arduinos? One in your robot and another one.
You got the sweep sketch to run on your other board.

Yes I have 2 Arduinos. One for my robot and the other for testing the servos and working out any bugs. Once I get this issue resolved and all the servo-related-bugs fixed, I will remove the second Arduino and just use the first one in the robot.

By the way, with the "Testing Arduino" i am simply powering each servo from a separate 5V pin on the "Testing Arduino. In the actual robot, I will use an external power supply as I mentioned before, in an earlier post.

vinceherman:
Can you get the servo sweep to talk to 2 servos?

I got THIS SKETCH running on the Testing Arduino. It is the same principle as the normal Sweep Sketch, just with 2 servos. Is that what you mean?

/* 
Double Sweep Example
*(Sweep with 2 servos)
*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
Servo myservo2;
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo2.attach(8);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    myservo2.write(pos);
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos); 
    myservo2.write(pos);// tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

I also got the normal Sweep sketch working for each individual Servo, obviously. I just don't know what you mean by the sketch "talking to 2 servos"

Good that you have a test environment set up.
Yes, writing to both servos is what I meant by 'talking to both servos'
What were the results of the 2 servo test?

Best not to power the servos, especially more than one, from the 5v arduino pin. We won't know if bad servo behavior is from under powered servos, thermal shutdown, or other problems.