Inverse Kinematics Basics Tutorial – Oscar Liang
What is Inverse kinematics in robotics? With your robot having legs the position of those legs dictates where its feet are. Where its feet are dictate its point of balance.
As you might know “balance” can be defined as the robot’s centre of mass (affectionately referred to as its centre of gravity) being between its centre of pivots (i.e. the edges of where its feet contact the ground). If the centre of mass is above the centre of pivots and between them the robot will balance (almost an unstable equilibrium, if you’re an applied mathematician. If the centre of mass is above but outside the centre of pivots (i.e. beyond the edges of his feet) the robot will overbalance and fall.
If you feel confident about the Inverse Kinematics basics, you can jump to
Implementation of IK on Hexapod robot:
Kinematics and Robots?
If you’re a little unclear about Robot Kinematics, I recommend to start with something basic, a cube is a good start, and imagine that its centre of mass is right in the middle (which it will be if its density is even throughout). When the cube is just sat there it’s stable. The centre of mass is above the centre of pivot (the edges) but because it’s between them (when viewed from every direction) it will just sit there until you prod it.
Now you prod it and slowly tilt it. As the centre of mass approaches a point directly above one of the edges (our centre of pivot) the cube will feel lighter to your touch and if you can get the centre of mass directly over that centre of pivot it will balance. As soon as you push it past that point, so the centre of mass is the other side of the centre of pivot it will fall.
The robot is exactly the same. This is why the kinematics of the feet are important to you. If you want the robot to balance dynamically you NEED to know where the feet are and where they’re going to need to be. Please understand that I’m not going to do all your work for you, so the code or equations I share are not guaranteed on their accuracy but purely a demonstration of how the method is derived and works.
Forward and Inverse Kinematics – FK & IK
Forward kinematics is the method for determining the orientation and position of the end effector (x,y,z) coordinates relative to the centre of mass , given the joint angles and link lengths of the robot arm (servo positions). This equation is deterministic. You know absolutely from the servo positions exactly where the foot is.
Inverse kinematics is the opposite of forward kinematics. This is when you have a desired end effector position, but need to know the joint angles required to achieve it. This is harder than FK, and there could be more than one solution.
The FK is not very useful here, because if we are given a change of angle of a servo, only one effector moves in the chain. But if we are given a change of coordinate, the whole chain of effectors (servos) might have to move a certain angle for the end point to reach the desired position. And also the movement tend to be more natural as well!
Approaches To Solve IK
There are two approaches to solving inverse kinematics:
- Analytical – requires a lot of trigonometry or matrix algebra
- Iterative – better if there are lots of links and degrees of freedom.
Iterative approach (not important)
Because we will be mainly dealing with 3DOF hexapod or Quadurped robot legs, Analytical, or simple trigonometry would do the trick for now.
Some Real Work
Enough theory, to turn this into progamming language, you’ll have to remember that the angles are unknown, and we need to work it out using equations and trigonometry.
So, first thing is going to be simplify this problem from 3D into two 2D problems, to solve for α (alpha), β (beta) and γ (gamma).
Gamma is easy, from diagram one, we have:
Now that you have gamma, you have two more angles to solve (and they are in the same plane)let’s move on to the second diagram.
Alpha is a bit tricky, so I tend to split it into Alpha1 and Alpha2.
We can get Alpha1 by working out L first.
For Alpha2 and Beta, we need some help from Cosine Rules:
From these formula, if we know 3 sides of a triangle, we can find out any angles inside it. Don’t doubt it, it just works! 🙂
So now we have Alpha2,
And Alpha is
And Finally, Beta
At that point, you have your values for your servos!