Servo Motor unable to reach specific or precise angle

Discussion in 'The Projects Forum' started by Dale Grana, Feb 19, 2016.

  1. Dale Grana

    Thread Starter New Member

    Feb 3, 2016
    9
    0
    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!
     
  2. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,694
    904
    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
     
  3. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,809
    834
    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
     
  4. Dale Grana

    Thread Starter New Member

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

    Code (C):
    1.  
    2. #include <HBridge.h>
    3. #include <Servo.h>
    4.  
    5. Servo myservo;
    6. int pos;
    7.  
    8.  
    9.     int leftForwardServo();
    10.     int rightForwardServo();
    11.     int leftReverseServo();
    12.     int rightReverseServo();
    13.     int mobotStop();
    14.  
    15. HBridge motors(7,6,5); //wd_pin, pwm_pin, dir_pin
    16.  
    17. void setup()
    18. {
    19.   motors.begin();
    20.   myservo.attach(9);
    21.   Serial.begin(9600);
    22. }
    23.  
    24.  
    25. void loop()
    26. {
    27.   int sensorValue0 = analogRead(A0);
    28.   int sensorValue1 = analogRead(A1);
    29.   int sensorValue2 = analogRead(A2);
    30.  
    31. Serial.print("A0 = ");
    32. Serial.println(sensorValue0
    33. delay(300);
    34. Serial.print("A1 = ");
    35. Serial.println(sensorValue1);
    36. delay(300);
    37. Serial.print("A2 = ");
    38. Serial.println(sensorValue2);
    39. delay(300);
    40.  
    41.  
    42. //Navigation Codes
    43.  
    44.  
    45. //1. Searching for Ultrasonic Signal
    46.  
    47. if((sensorValue0 == 0) && (sensorValue1 == 0) && (sensorValue2 == 0))
    48. {
    49.   leftForwardServo();
    50.   delay(1000);
    51.   rightForwardServo();
    52.   delay(1000);
    53.   if((sensorValue0>0 || sensorValue0<50) && (sensorValue1>0 || sensorValue1<50))
    54.     {
    55.       leftForwardServo();
    56.       if(sensorValue1>200)
    57.       {
    58.         motors.Forward(255);
    59.       }
    60.     }
    61.  
    62.   if((sensorValue1>1 || sensorValue1<50) && (sensorValue2>1 || sensorValue2<50))
    63.     {
    64.      rightForwardServo();
    65.       if(sensorValue1>200)
    66.       {
    67.         motors.Forward(255);
    68.       }
    69.     }
    70.  
    71.  
    72. }
    73.  
    74. if((sensorValue0>500) || sensorValue1>500 || sensorValue2 > 500)
    75. {
    76.   motors.Stop();
    77. }
    78. else
    79. }
    80.  
    81.  
    82.  
    83.  
    84. int leftForwardServo()          
    85. {
    86.   for(pos=0; pos<=45; pos++)
    87.     {
    88.       myservo.write(pos);
    89.       delay(15);
    90.       motors.Forward(255);
    91.     }
    92. }
    93.  
    94. int rightForwardServo()            
    95. {
    96.   for(pos=90; pos>=0; pos-=1)
    97.     {
    98.       myservo.write(pos);
    99.       delay(15);
    100.       motors.Forward(255);
    101.     }
    102.  
    103. }
    104.  
    105. int leftReverseServo()               //reverse going left
    106. {
    107.   for(pos=0; pos<=90; pos+=1)
    108.     {
    109.       myservo.write(pos);
    110.       delay(15);
    111.       motors.Backward(255);
    112.     }
    113. }
    114.    
    115. int rightReverseServo()            //reverse going right
    116. {
    117.   for(pos=90; pos>=0; pos-=1)
    118.   {
    119.     myservo.write(pos);
    120.     delay(15);
    121.     motors.Backward(255);
    122.   }
    123. }
    124.  
    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: Feb 20, 2016
  5. Colin55

    Member

    Aug 27, 2015
    191
    19
    When you swap the servos, does the fault swap too?
     
  6. Dale Grana

    Thread Starter New Member

    Feb 3, 2016
    9
    0
    No it does not

    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: Feb 20, 2016
  7. Sensacell

    Well-Known Member

    Jun 19, 2012
    1,131
    267
    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.
     
Loading...