In order to move a multiped(is that a word?) robot properly, you must be able to place each foot at specific coordinates. But how can you find the values of each joint to the to the desired target?

Forward kinematics is "refers to the use of the kinematic equations of a robot to compute the position of the end-effector from specified values for the joint parameters.". Inverse Kinematics refers to the oposite task, the joints' values are calculated from the end-effector(in our case the feet) position. This allows us to controle each foot by using cartersian coordinates, which simplifies things a lot.

### IK Calculation

The formulas are not really hard to derivate, It's basic geometry, and you don't have to consider all the axis at the same time, first you can do the tibia-femur plane, then the ground plane.

This guy did a really good job at documenting these things: Inverse Kinematics IK Implementation for 3DOF Hexapod Robot

### Alternative: Iterative Optimization

During the research on methods for calculating the inverse kinematics, I stumbled with an alternative way, this method actually works by variating the joint's angles values on the forward kinematics, and tries to find the lowest error.

It's an interesting idea:

```
import scipy.optimize as opt
def error(args):
x2,y2,z2 = forward_ik(args)
return sqrt((x2-x)**2 +(y2-y)**2 +(z2-z)**2)
def ik_to3(self, x, y, z):
result opt.fmin_slsqp(func=error,
x0=[0,0,pi/2],
bounds=[(-pi/2,pi/2),(-pi/2,pi/2),(0,pi)],
iprint=0, #this gives verbose output, with number of iterations, etc..
acc=0.01)
return result
```

What happens here is that Scipy inputs the values of "x0" into "error()", calculates the error, then varies each of the parameters until the error is smaller than "acc". It then returns the calculated values. The process took around 7 iterations with these settings on my setup.

This is a quite interesting idea, since you can just plug the forward kinematics for different bodys and get results quick, however I am unsure about wheter it can get stuck on local minimums or not.

Here is a video of the IK at work on my robot: