Friday, October 10, 2014

Coming from a halt... Servo calibration


Coming back from a halt… lots of things happened last year that consumed my time, but I’m back.


During the last weeks I've resuming the work I've done before. Although I have new ideas for the arm, the issue with the servos showing position errors kept bothering me; so I decided to give it a last try and solve it for good.


Background:  the issue was that the arm shows an error on the position, which increases as the arm increases its extend.  The larger error was seen on the shoulder servo. Hypothesis was error was caused by arm weight.


Debug process: First I calculated the sum of torques that will be applied to the shoulder servo (based on arm weight and extension) and compared with the spec data. Even on full extension the sum of torques won’t be larger than 4 Kg.cm (this type of units is used on hobby servos torques) and the shoulder servo (HS-755HB) is capable of holding 11kg.cm. Now, the hypothesis of weight seems not so good…


Due to Lynxmotion staff suggestion I also checked that power supply was capable to provide enough power to the arm (servos and control). My wall power adapter was sufficient and I also tried with a DC power supply (5V 2A).  Measured current consumption was around 350mA. Also with both power supplies the servos behaved similarly.


Then also due to Lynxmotion suggestion I took apart the arm and test the servo without any load… surprise! The servo kept showing errors without any load. Now, the error statement changed into: shoulder servo shows an error in position as it approaches 0 degrees.


I did some research and found some important fact about hobby servos. Their origin is very influential since they came from the RC world, where you need some precision for the center position (90 degrees) and then you just need it to go right or left but with no precise amount.


What I found on the literature is that there's an agreement about having center position with a signal of 1500us, but there's no consensus on what is signal length for 0 degrees and 180 degrees on hobby servos. 


Lynxmotion mentioned that "500 is 0 degrees, and 2500 is 180 degrees". Arduino Servo Library has "0-degree angle on the servo defaults to 544... 180-degree angle on the servo defaults to 2400. Other Arduino reference even says: "1000 is fully counter-clockwise, 2000 is fully clockwise". 


But the most important statement that I found was: "Note that some manufactures do not follow this standard very closely so that servos often respond to values between 700 and 2300".


Since I was using Arduino Servo library, it uses its default values and my experimental data was consistent with them: 547us for 0 degrees and 2392 for 180 degrees (It was slightly different from theoretic values, probably since I didn't have a scope so I used a DVM and measured Mean Voltage and then calculated time).


This article provided me some insights about how to modify time values for 0 and 180 degrees on the Arduino Servo function when declaring Servo Attach statement.  I found that my HS-755 servo has 670us for 0 degrees and 2300us for 180 degrees. I tried also with HS-422 servo and found a different set of values.


Technical conclusion: each servo might have difference time values for 0 and 180 degrees. For future settings, if I need some precision on angle settings, I need to manually measure those time values first and adjust Arduino Servo function accordingly.


Time for some reflection: the main difference this time is that I asked for help early in the debugging process. I consulted on a help forum from Lynxmotion and during the discussion process I got new ideas and found new answers. I could came to this point many time ago if I have just asked for help earlier.


Philosophical conclusion: While debugging an issue, try for a while alone but if it is taking you too much, ask for help. 


8 comments:

  1. Thank you for this helpful article but i have two questions for you:
    1)How did you measure those frequency values for the servos(670us and 2300us)?(or did you find them from a catalogue?)
    2)How did you modify original servo library?
    Thank you in advance for your answers and have a good day!

    ReplyDelete
  2. Hi Alí, I'm glad you liked the article. For your questions:
    1) I found those values through experimentation, that is I used a protractor, and start playing with time values until I see a match for 0 degrees and 180 degrees.
    2) It wasn't necessary to modify the Arduino library. When you do the servo attach declaration, you put your minimum (time for 0 degrees) and maximum (time for 180 degree) values for your servo.
    Format is as follows: servo.attach(pin, min, max)
    In my case it was: myservo.attach(6, 670, 2300)

    I hope this would help you!

    ReplyDelete
  3. Hi JC and thank you for your fast reply!
    I forgot to ask in my previous message so i have to ask it now, did changing the max and min frequencies help to solve the problem?
    I'm asking this because i'm also doing a project using the same robotic arm that you use and i also faced with the same problem.So it would be great if you could share those frequency values!
    See you later!

    ReplyDelete
  4. Well, I solved the problem in great percentage but not totally. Let me explain myself, the robot arm is more accurate now, it doesn't smash itself against the table by having wrong position value. However there's still a minor position error, which is by the servo motor itself; when the arm is fully extended the load on the shoulder servo is greater and it start to show some bias on the position.
    I'll post in some hours the time values for min and max position on my servos. I hope this will help you!
    JC

    ReplyDelete
  5. Hey Alí, at this moment I have only done the servo calibration for the shoulder, elbow and wrist servos. Here are the values:
    shoulder.attach(6, 670, 2310);
    elbow.attach(7, 610, 2430);
    wrist.attach(8, 540, 2360);

    ReplyDelete
  6. Hello JC,
    I haven't tried your freq. values yet. But i'll let you know when i do. And i'm hoping to learn more from your experiences about the robotic arm.(if you don't mind of course :D) Thank you for your help!

    ReplyDelete
  7. Hello again JC,
    I got a question for you after a long break. Have you calculated the 0-180 degree values for HS-422? If so can you post them?
    Thanks!

    ReplyDelete