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 ( .

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.

Wednesday, February 8, 2012

Playing with Arduino

Learning how to use an Arduino board is a straight forward process if you follow the tutorials on Arduino page ( You just need some basic programming skills and some basic electronic knowledge; the tutorials put everything on a very simple way.

The Arduino Environment is a higher level code based on C++ for microcontrollers; there are many libraries that cover the low level setup. For example if you use the PWM (Pulse With Modulation) library, you just have to specify the duty cycle of it; frequency of the signal is a fixed value, you can't change it easily unless you go the C++ code. This implies that Arduino code is less flexible but it also makes it a lot (really a lot!) easier to use.

After doing a lot of the examples on the tutorials, my objective was to control the servo motors to be used on my robot. So I used the servo library from Arduino to control the position of 1 servo by manipulating a potentiometer, then the same for 2 servos and then for all the 5 servos.

As I mentioned on the previous post, the Arduino Uno board can source up to 2 servos; so for sourcing all the 5 servos I used an external 5V power supply. Be careful that if you use a wall adapter power supply, not to buy any cheap one because it can be very inaccurate on the voltage it says to provide.

Then I created a costume sequence with the servos, that's a bit trickier since you have to code each servo position separately, thus you have to know where every servo should be at every moment of the sequence. This exercise is very useful since it's something pretty similar than controlling the robotic arm in an open loop project.

You can take a look at how the servos worked on the following video:

Next step will be to build the mechanical part of the robot and create some sequence for it, so that the arm can show off.