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 (this type of units is used on hobby servos torques) and the shoulder servo (HS-755HB) is capable of holding 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.