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. 

14 comments:

  1. Hi!

    I found this really helpful. Do you have the mathematics for a 3D space? Thanks!

    ReplyDelete
  2. Hello!
    You have done a great job there. I'm also building a project using the same robotic arm. Do you have knematic equations for 3D space? Thank you!

    ReplyDelete
  3. Hi, unfortunately I haven't write the equations for 3D space. Now that I'm resuming my robotics projects I'm planning to do it. I hope to have them soon.

    ReplyDelete
  4. The answers to your problems are here. These equations are extremely useful. I'm using these calculations for my arm. It's amazing, and simple. (note: it's note my post. credit to maquinapensante1(on youtube))

    http://www.maquinapensante.com/robots/robots/Blog/Entries/2011/2/12_Robot_Arm_with_Inverse_Kinematics_%282011%29.html

    ReplyDelete
  5. Thanks Nebiyou! That link looks great, lots of info.

    ReplyDelete
  6. damm where the example code tho?

    ReplyDelete
    Replies
    1. cuz this did not really explain nothing, just saying

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

      Delete
  7. If anyone looking for packers and movers services in Hyderabad then choose Ashoka Packers and Movers service. They are one of the best shifting service providers.

    Packers And Movers Hakimpet
    Packers And Movers Himayat Nagar
    Packers And Movers Hafeezpet

    ReplyDelete
  8. If you are looking for packers and movers services company in Delhi NCR. click here-
    packers services in noida
    packers services in delhi ncr


    ReplyDelete
  9. We are one of the best packers and movers in Noida which is tend to provide you best packers and movers service so if you want to get best packers and movers services so visit on- Noida Packers and movers

    ReplyDelete
  10. Hi, If you are looking for cheap and moving services provider company in Delhi so visit on Packers Services in Noida and get best moving services.

    ReplyDelete
  11. Excellent Blog, I am surely bookmarking this: also have a look into my sites Best Packers Movers in Kochi City and Packers Movers in Ernakulam District get in touch with us

    ReplyDelete