go_away

Author Topic: Servo only rotates one direction  (Read 2534 times)

0 Members and 1 Guest are viewing this topic.

Offline NecitralTopic starter

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Servo only rotates one direction
« on: March 18, 2012, 10:01:16 PM »
Hi there

I have an unmodified Hitec HS-311 Servo Connected to an Arduino Uno R3. I have the servo hooked up to a Separate power supply. Here is my code that I have loaded on the Arduino:


#include <Servo.h>
 
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created
 
int pos = 0;    // variable to store the servo position
 
void setup()
{
  myservo.attach(9);  // 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'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
  {                               
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}


However when I turn on the Servo and the Arduino the Servo turns Counter Clockwise until it reaches the point where it stops. It does not do anything else. I know that it is not the servo because I have two other servos that are doing the exact same thing. Any Suggestions?

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Servo only rotates one direction
« Reply #1 on: March 19, 2012, 01:05:09 AM »
Hi,

However when I turn on the Servo and the Arduino the Servo turns Counter Clockwise until it reaches the point where it stops. It does not do anything else. I know that it is not the servo because I have two other servos that are doing the exact same thing. Any Suggestions?
You really ought to post software questions in "Software"!

When your servo stops at one end, does it buzz or anything?
Test with the following changes to the code and tell us what happened

Code: [Select]
void loop()
{
  for(pos = 45; pos < 135; pos += 1)  // goes from 45 degrees to 135 degrees
    {                                  // in steps of 1 degree
     myservo.write(pos);              // tell servo to go to position in variable 'pos'
     delay(15);                       // waits 15ms for the servo to reach the position
    }
  for(pos = 135; pos>=45; pos-=1)     // goes from 135 degrees to 45 degrees
    {                               
      myservo.write(pos);              // tell servo to go to position in variable 'pos'
      delay(15);                       // waits 15ms for the servo to reach the position
    }
  for(pos = 45; pos < 90; pos += 5)  // go to center position (90°)
    {                                  // in steps of 5 degree
     myservo.write(pos);              // tell servo to go to position in variable 'pos'
     delay(15);                       // waits 15ms for the servo to reach the position
    }

}

This will help determine if the issue is caused by the servo hitting the end stop.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline NecitralTopic starter

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Re: Servo only rotates one direction
« Reply #2 on: March 19, 2012, 10:37:56 AM »
Soeren after making the changes that you prescribed the Servo is still doing the same thing.

The Servo is not buzzing or doing anything really but just stopping when it reaches the end of its rotation. I have a modified servo that I have tested with, and it continues to rotate counterclockwise without stopping.

Offline Daanii

  • Robot Overlord
  • ****
  • Posts: 138
  • Helpful? 3
Re: Servo only rotates one direction
« Reply #3 on: March 19, 2012, 03:10:03 PM »
Have you tried debugging your code using the Serial Monitor?

If not, try something like this:

Code: [Select]
#include <Servo.h>
 
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created
 
int pos = 0;    // variable to store the servo position
 
void setup()
{
  Serial.begin(9600);
  myservo.attach(9);  // 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'
    Serial.print("Clockwise position: ");
    Serial.println(pos);
    delay(150);                       // waits 15ms for the servo to reach the position
  }
  delay(5000);
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
  {                               
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    Serial.print("Counterclockwise position: ");
    Serial.println(pos);
    delay(150);                       // waits 15ms for the servo to reach the position
  }
  delay(5000);
}



Then see what is happening on the Serial Monitor at the same time as the servo is turning. At least that will give you some more information.

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Servo only rotates one direction
« Reply #4 on: March 21, 2012, 05:13:25 PM »
Hi

Soeren after making the changes that you prescribed the Servo is still doing the same thing.

Spooky  :o
Did it go the full way (to the end-stop)?
It shouldn't be able to go beyond approximately 45° from the center position either way, so if it does, the timing is wrong somehow...
Did you change the clock frequency relative to what this function is made for?

Maybe the pulse is either too long or too short, but then I'd expect it to be noisy when it reaches the end-stop.

Is the servo continually driven after it reaches the position (test by trying to move the arm a bit).


The Servo is not buzzing or doing anything really but just stopping when it reaches the end of its rotation. I have a modified servo that I have tested with, and it continues to rotate counterclockwise without stopping.

Hmmm, perhaps the program enters an endless loop, after having sent one or a few pulses and then stop delivering pulses at all, like if you cut the signal wire.

Since you don't mention it, I assume you don't have access to an oscilloscope, which really is the best tool for this and give you some alternative yet inferior methods for checking the servo signal wire.
1) A red (or green) LED with a resistor of 150 to 470 Ohm (whatever you may have in that range) connected in series between the servo signal and ground.
This will give off some weak light if it works. Reposition it to between +5V and the servo signal to verify that it was't just stuck on high - it should give off some light here as well.

2) A cheap headphone (usually around 32 Ohm) in series with a resistor in the same range as for the LED could replace a crystal earpiece to listen to the servo signal - this has a very distinct sound with the 50Hz repetition as the main component, bur with a bunch of harmonics, making it more "hard" than a sine wave.

3) The best option is to get a sound card oscilloscope to check the signal, there are several freeware 'scopes and even the simplest suffice for this, but this one has got a bunch of nice features and while a sound card 'scope is very limited, this can still help you in lots of situations beyond this.
Then make this simple interface to couple the servo signal to your microphone input

Don't substitute any of the components without checkin with me first, this is what keeps your sound card alive!

Then you can see the actual servo signal coming from your Arduino and knowing that will be a good aid in trouble shooting.
Post a screen dump from the scope trace around 25ms long (i.e. two pulses plus a little extra at each side) if you need further help.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline ironheartbj18

  • Jr. Member
  • **
  • Posts: 8
  • Helpful? 0
Re: Servo only rotates one direction
« Reply #5 on: August 12, 2012, 09:13:24 PM »
see the servo to choice rotation 90 or one way direction it cost more... http://www.servocity.com/html/hs-311_standard.html

 


Get Your Ad Here