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. 


Monday, July 22, 2013

Back on writing soon

I haven't write anything new for some months, the reason for that is that I got married and I have been busy setting up our new home; but anxious the get my hands on the robot again, so new posts are coming soon!

Tuesday, November 13, 2012

A little pause: Class recommendation

Due to my work I had to move from Costa Rica into Houston, US; and with this I couldn't take my robot with me. I'll be in this new location until March 2013, so in the meantime I've been taking an online class of Machine Learning at Coursera (www.coursera.org). .

The class has been truly amazing, the teacher (Andrew Ng) has a great way to explain things without losing focus on the big picture, so you always understand why they are useful for. He also explains everything without assuming you know things, so you don't get lost in the subject. It's been a great experience and I strongly recommend you to take this class; it's like learning Kung-Fu for robots, I have a lot of ideas about how to apply it into my robot.

Also in the meantime, I'm trying to run a half-marathon...  


Monday, September 3, 2012

Inverse Kinematics video

I did a video about the Inverse Kinematics equations for the Arm. I also show there some of the errors I described in my previous post. And all of this is shown with some great dubstep beats... :) 
I'm quite an amateur on video editing, but I hope you like it.




Saturday, July 28, 2012

Correcting displacement errors

Ok here's the deal: after putting the kinematics equations into the robot, theoretically everything was fine, but the robot was smashing into the table, it was having some deep dives heading for destruction. Why the heck was that happening?

My first thought was that maybe the controller was not calculating the right angle values, but after a quick check with a serial monitor, those values were fine. Then I thought that maybe the equations were wrong, so I simulate the different arm positions (below picture) but they were ok.


Yep, I drew the trajectories using a Logo simulator... it was fast and convenient at the time ;) 


With all the directions from controller performing as desired, I realized that some of the servos just weren't capable to go into some positions.

My theory was that it was due to the arm weight and that with larger extensions of the arm, this effect will be greater. To demonstrate that I measured the angles of the joints with several arm extensions. The shoulder servo showed a notorious error increase with larger extensions, elbow showed a relative stable error with a constant value (possible due to some assembly issue). Wrist servo had almost no error.



In summary: I had a shoulder servo that couldn't hold all the arm weight when extended and a elbow with a constant error value.


How to fix this?

On first impression the solution would be to buy a more powerful servo motor for the shoulder, but since I'm saving to buy an apartment, I don't have so much money to throw away things so easily; and the idea is not just to give muscles to the robot, but to make it more efficient.

So, I tried to help the servomotor with some elastic force. First I used the spring that Lynxmotion suggests on their page (and comes with the arm assembly parts), It helped somehow, especially for short and medium extensions, but for large extensions it was not effective. Then I added also a rubber band but the assembly behaved just the same as with only the spring.

Then I thought that if the error in the joint angle behaved always similarly, I could find an equation to describe it, therefore having an error correction equation. I made an X-Y graph with the theoretical values vs the obtained angles, added a trend line and found the equation for it; so next time I would order the servo to go to angle A in order to really go to angle B. I applied this software correction procedure to shoulder and elbow joints.



Shoulder and elbow angle functions



Ultimately, I figured out that reducing the mass of the arm, servos would perform better. So I amputated the arm and removed the wrist rotate upgrade to save some weight  (I prefer more accurate results even by eliminating 1 DOF). This last fixture gave me the best combination of low error values on shoulder and elbow joints.  



Another effect I had was that servos moved so fast that they had a large underdamped movement (that decreasing oscillation when it stops moving), hitting things due to this inaccuracy. 

When you have a motor with this issue, usually you apply a PID control to its movements and tuned it up, but since in a servo motor you do not apply a control signal directly (you just specify the desired position) this option was not feasible.

The technique used in several Arduino forums was to reduce the speed of servo, this is achieved by gradually increasing the desired position sent to the servo.

By using the error correction techniques described above and decreasing the speed of the servos, I was able to obtain smoother and more accurate results, however the best way to achieve more precise and accurate results would be to have some feedback of the joint position going to the controller, having this way a closed loop control for the position. 

In conclusion: I need to get better servos (like the Dynamixel servos) or hack the ones I have to have that position feedback in real time. 


Friday, May 11, 2012

Applying inverse kinematics to the robot


When it comes to programing the logic for your robot to move there are several paths you can take. Usually you start by specifying the position of each servo on every movement of the robot, thus giving the angles of the joints to make the arm gripper go to a certain position. This is called Forward Kinematics.

The disadvantage with Forward Kinematics is that you need to know the angle of every joint on every instant of a movement, therefore as the complexity of the movement increases it also increases the amount of angles you need to know. This characteristic makes long and tedious the duty to program your robot with the intention to go to variable positions. I started programming some moves to the robot in this way, but I quickly realized about how impractical this technique was.

If your intention is to go into more complex projects, you really don't want to program every position of every joint; you just want to tell your robotic arm (or any robotic chain) "go to X,Y,Z position". Well, that technique is called Inverse Kinematics, were you just specify the desired position of the arm gripper and the robot logic calculates the angle of every joint in order to accomplish that gripper position.

Using this technique allows you to escalate your code for higher levels of complexity, but you need to obtain the inverse kinematics equations for your robot; those are the equations that will give the joint angles (and thus servo positions) when you just input the final gripper position.
To obtain those Inverse Kinematics equations you need to image your robot arm as a series of geometric figures and use geometry principles to obtain the desired angles. I will explain how I did it for my robotic arm, but it varies according to the type of robot and the number of Degrees Of Freedom (DOF) it has.

First I started by dividing the arm assembly into the below figures, then I specified which values will be constants (in this case the lengths from joint to joint and the desired final position) and which angles will be my desired output (in this case the shoulder, elbow and wrist angles).

Geometric figures on my robotic arm


Now it comes the math-fun part: you can use the Law of Cosines to obtain the angles of a triangle by knowing the length of its sides. So we can obtain the elbow angle with the following formula:

Where c is obtained using the known sides of the triangles and Pythagoras' theorem:

Also by Law of Sines we can obtain angles A and B:

With A and B we can get the angles of the wrist (m) and shoulder (h):

Finally, I substitute the sides of the arms and the desired extension (E) on those formulas and I used them on some routines on the Arduino controller that specifies where to extend the arm. Also I created other routines for raising the arm, rotating the base, opening/closing the wrist and rotating the gripper.

By using these routines, I was able to scale my code into simpler instructions, something like: raise, rotate A degrees, go to B extension, raise, rotate C degrees, go to D extension and so on.

Note that these formulas use always the gripper perpendicular to the ground and on a 2-Dimensional space, places around the ground. Next steps will be to create these inverse kinematics equations for a 3-D space. 

Wednesday, March 14, 2012

Building the Robotic Arm


Building the mechanical part of the robot is one of the funniest part of projects, it’s just like building LEGOs when you were younger, but with tougher parts and tools.

Since I bought a robotic arm kit from Lynxmotion, there are detailed instructions on their webpage. You just need to follow the instructions, but pay extra attention to the pictures because not all the details are covered on the text; I had to disassemble parts several times to fix things I found they need to be in other way. Also you need to have some basic tools like screwdrivers, clippers, wrenches and allen keys. With all this, it’s just a matter of expending time on the building process and you will have a nice piece of hardware for further developments.


One interesting feature during that process is that you start to realize what are going to be some of the limitations your hardware will have and some of the challenges you will face. For example, I soon appreciated how rigid servomotors are, I mean the word actuator is literal, they just act on the way you order them to act; there's no sense of intelligence at all compared to when a animal moves a limb. Also I realized how much weight each articulation have to handle and how easy is for some servos to get stressed if too much weight is carried during many time.

One important outcome was that I discovered I want to explore more about proprioception, which is the perception of your body parts, its weight, force, position. I think that increasing this type of intelligence on robots would result into projects that could be applied to a wider range of situations.