Inverse Kinematics - Chapter I

I will like to explain here a bit of Inverse Kinematics (IK). I will use this to get the desired positions for the legs of the tetrapod.

I will split this subject in different chapters so it can be followed easily.

Basically we know where the leg has to go and using IK we will calculate the angles that the servos need to rotate in order to achieve that known position.

In this page I will explain a geometric method and as I will develop this project I may review this and follow other approaches.

So let's start:

I will explain this using 1 leg but the same principles will apply to the other legs. The tetrapod has 3 motors in each leg and for now we are going to see how to use IK to control 2 motors (in the XZ plane), the third one will be discussed later but will allow us to move the leg in the XY plane.

We can represent the leg in a simple manner like:

The two green dots represent the motor and the two black lines are the femur (a) and tibia (b).

We want to know the angles of the black lines to achieve a known X and Z position. I call them X0 and Y0.
We also know the length of the femur and tibia (a and b). So we can find the hypotenuse (h) of the triangle generated by X0 and Y0.

Now, using the law of cosines we can find angle alpha (α):

The first angle we really need is the one that the femur makes with origin axis. This can be different in any case. But let's imagine that the servo is mounted so the angle 0 degrees is vertical (the same way as my tetrapod). So:

Like this:

Then the true angle we need to move our first servo is beta (β).

To find this angle β we need to find first gamma (γ). Like:

But gamma is also located on top of alpha like:

So finally beta (my first servo angle) is:

Let's say that the second servo is mounted of the first one, so the angle I need is epsilon (ε), in red below. 

Like this:

So first we need to find delta (δ). Again using the law of cosines:

Now we can find epsilon like:

In the next chapter I will write these equations in Arduino code.


  1. really use full information!!!! great work buddy

  2. Thanks a lot for your support. Keep looking as I will update the blog soon with more articles.

  3. Marcos. First, neat work man! Your blog has been most helpful. I'm also currently designing and building a 3-dof quadruped walker. I was wondering how you're finding the Cyclic Coordinate Descent method of solving Inverse Kinematics problems - are you managing to get smooth and controlled gaits? As a rule the forward kinematics/Inverse Jacobain/Transposed Jacobain method allows for smoother gait motion...

    1. Hi Martin, thank you for your support. To tell you the truth I haven't attempted yet any gait. I've got all the rotation and translation movements sorted as coordinate descent method but I can see it may be limited. One of the ideas I had in mind was to apply "animation principles" like "easy in" "easy out" but I haven't tried them either. The Jacobi method seems a pretty good alternative and it may help to adapt the movement on the fly rather than waiting to reach to a specific position.

  4. Hi Marcos,
    Great work !!!
    By the way, how do you determine the angles of the servos (coxa, femur and tibia) with the body tilted on one side ???