Servo Motor unable to reach specific or precise angle

Thread Starter

Dale Grana

Joined Feb 3, 2016
9
i've purchased two TowerPro MG995 servos and testing them was a bit confusing (I'm a bit new to servos). They do not have the same output angles coming from the same program uploaded into the microcontroller. Now, I want the servo to rotate to a specific angle then stays constant and retracts until specified in the program.

Now upon testing i'm confused that the servo does not achieve the precise angle and also rotates back to its original position after achieving its maximum angle from the program.

Can anyone enlighten mo on this?

Thanks a lot!
 

jpanhalt

Joined Jan 18, 2008
10,082
There are several possibilities. But to really help you, you will need to post your code.
1) Are the servos connected absolutely identically? For example, were the servos powered with the same signal when you attached the servo arms in the same position?
2) When you say they don't turn the same, how far off are they from each other?

John
 

djsfantasi

Joined Apr 11, 2010
6,712
When you say that it does not achieve the precise angle, I assume that you are referring to the angle of the servo horn?

To align the servo horns, one wants to connect the servo to a signal source set for the middle position (pulse width of 1.5ms). Then attach the horn in the desired "middle" position. There are circuits for digital servo testers, that can be found online. You can also do this with the extreme positions, but note that the signal varies by manufacturer and even between servos and your code will have to take this into account.

This particular servo has a particularly bad rating on the RC boards, particularly with regard to centering. Take a look at some of these reviews here:
http://www.servodatabase.com/servo/towerpro/mg995
 

Thread Starter

Dale Grana

Joined Feb 3, 2016
9
Well this is my code..

C:
#include <HBridge.h>
#include <Servo.h>

Servo myservo;
int pos;


    int leftForwardServo();
    int rightForwardServo();
    int leftReverseServo();
    int rightReverseServo();
    int mobotStop();

HBridge motors(7,6,5); //wd_pin, pwm_pin, dir_pin

void setup()
{
  motors.begin();
  myservo.attach(9);
  Serial.begin(9600);
}


void loop()
{
  int sensorValue0 = analogRead(A0);
  int sensorValue1 = analogRead(A1);
  int sensorValue2 = analogRead(A2);

Serial.print("A0 = ");
Serial.println(sensorValue0
delay(300);
Serial.print("A1 = ");
Serial.println(sensorValue1);
delay(300);
Serial.print("A2 = ");
Serial.println(sensorValue2);
delay(300);


//Navigation Codes


//1. Searching for Ultrasonic Signal

if((sensorValue0 == 0) && (sensorValue1 == 0) && (sensorValue2 == 0))
{
  leftForwardServo();
  delay(1000);
  rightForwardServo();
  delay(1000);
  if((sensorValue0>0 || sensorValue0<50) && (sensorValue1>0 || sensorValue1<50))
    {
      leftForwardServo();
      if(sensorValue1>200)
      {
        motors.Forward(255);
      }
    }

  if((sensorValue1>1 || sensorValue1<50) && (sensorValue2>1 || sensorValue2<50))
    {
     rightForwardServo();
      if(sensorValue1>200)
      {
        motors.Forward(255);
      }
    }
 

}

if((sensorValue0>500) || sensorValue1>500 || sensorValue2 > 500)
{
  motors.Stop();
}
else
}




int leftForwardServo()          
{
  for(pos=0; pos<=45; pos++)
    {
      myservo.write(pos);
      delay(15);
      motors.Forward(255);
    }
}

int rightForwardServo()            
{
  for(pos=90; pos>=0; pos-=1)
    {
      myservo.write(pos);
      delay(15);
      motors.Forward(255);
    }
 
}

int leftReverseServo()               //reverse going left
{
  for(pos=0; pos<=90; pos+=1)
    {
      myservo.write(pos);
      delay(15);
      motors.Backward(255);
    }
}
   
int rightReverseServo()            //reverse going right
{
  for(pos=90; pos>=0; pos-=1)
  {
    myservo.write(pos);
    delay(15);
    motors.Backward(255);
  }
}
i'm not yet finished by this program for the ultrasonic mobile robot that i'm working on.
Or maybe you can add suggestions. HUEHUEHUE

Moderators note: used code tags for C

So how can I set my servo to have a constant turn for a short amount of time? Because i'm using the servo motor as a steering mechanism
 
Last edited by a moderator:

Thread Starter

Dale Grana

Joined Feb 3, 2016
9
No it does not

When you swap the servos, does the fault swapNo too?
No it does not, I mean, I want it to stay at 45 degrees if the ultrasonic sensor senses a signal from the transitter if the user is 45 degrees from the sensor. :)
 
Last edited by a moderator:

Sensacell

Joined Jun 19, 2012
2,587
RC Servo motors use analog feedback internally to determine the position, therefore you will need to individually calibrate the positions if you want them to make an exact movement.

Translation: they are not terribly accurate, unit to unit, each one will behave slightly differently.
 
Top