The forward position kinematics problem can be stated as follows: given the different joint angles, what is the position of the end-effector?
With the previous sections in mind, the answer is rather simple: construct the different transformation matrices and combine them in the right way, the result being
b
s
e
e
T
{\displaystyle _{bs}^{ee}T\,}
, where
{
b
s
}
{\displaystyle \{bs\}}
is the base frame of the robot manipulator.
Suppose the mutual orientation matrices between adjacent links are known. (As the fixed parameters of each link are known, and the joint angles are a given to the problem, these can be calculated. One possible way to do this would be to make use of the Denavit-Hartenberg convention.) The transformation that relates the last and first frames in a serial manipulator arm, and thus, the solution to the forward kinematics problem, is then represented by the compound homogeneous transformation matrix. The axes are moving, thus, the compound homogeneous transformation matrix is found by premultiplying the individual transformation matrices:
b
s
e
e
T
=
0
N
T
=
0
1
T
1
2
T
…
N
−
2
N
−
1
T
N
−
1
N
T
{\displaystyle _{bs}^{ee}T=\,_{0}^{N}T=\,_{0}^{1}T\,_{1}^{2}T\ldots \,_{N-2}^{N-1}T\,_{N-1}^{N}T}
A planar three link manipulator. Each
X
i
{\displaystyle X_{i}}
-axis lies along the
i
{\displaystyle i}
th link. Each
Y
i
{\displaystyle Y_{i}}
-axis lies perpendicular to the corresponding
X
i
{\displaystyle X_{i}}
-axis in such a way that a positive
θ
i
{\displaystyle \theta _{i}}
corresponds with a rotation from
X
i
{\displaystyle X_{i}}
to
Y
i
{\displaystyle Y_{i}}
.
The equations below use 3 × 3 pose matrices, as this is just a 2-dimensional case (cf. the figure on the right).
The pose of the first link, relative to the reference frame, is given by (recall the elementary rotation about the z-axis from the previous section):
T
1
(
θ
1
)
=
(
cos
(
θ
1
)
−
sin
(
θ
1
)
0
sin
(
θ
1
)
cos
(
θ
1
)
0
0
0
1
)
{\displaystyle T_{1}(\theta _{1})={\begin{pmatrix}\cos(\theta _{1})&-\sin(\theta _{1})&0\\\sin(\theta _{1})&\cos(\theta _{1})&0\\0&0&1\end{pmatrix}}}
The pose of the second link, relative to the first link, is given by:
T
2
(
θ
2
)
=
(
cos
(
θ
2
)
−
sin
(
θ
2
)
l
1
sin
(
θ
2
)
cos
(
θ
2
)
0
0
0
1
)
{\displaystyle T_{2}(\theta _{2})={\begin{pmatrix}\cos(\theta _{2})&-\sin(\theta _{2})&l_{1}\\\sin(\theta _{2})&\cos(\theta _{2})&0\\0&0&1\end{pmatrix}}}
This corresponds to a rotation by an angle
θ
2
{\displaystyle \theta _{2}}
and a translation by a distance
l
1
{\displaystyle l_{1}}
, where
l
1
{\displaystyle l_{1}}
is the length of the first link.
The pose of the third link, relative to the second link, is given by:
T
3
(
θ
3
)
=
(
cos
(
θ
3
)
−
sin
(
θ
3
)
l
2
sin
(
θ
3
)
cos
(
θ
3
)
0
0
0
1
)
{\displaystyle T_{3}(\theta _{3})={\begin{pmatrix}\cos(\theta _{3})&-\sin(\theta _{3})&l_{2}\\\sin(\theta _{3})&\cos(\theta _{3})&0\\0&0&1\end{pmatrix}}}
The pose of the end effector, relative to the third link, is given by:
T
4
=
(
1
0
l
3
0
1
0
0
0
1
)
{\displaystyle T_{4}={\begin{pmatrix}1&0&l_{3}\\0&1&0\\0&0&1\end{pmatrix}}}
The solution to the forward kinematics problem is then:
b
s
e
e
T
=
0
4
T
(
θ
1
,
θ
2
,
θ
3
)
=
(
c
123
−
s
123
l
1
c
1
+
l
2
c
12
+
l
3
c
123
s
123
c
123
l
1
s
1
+
l
2
s
12
+
l
3
s
123
0
0
1
)
{\displaystyle _{bs}^{ee}T=\,_{0}^{4}T(\theta _{1},\theta _{2},\theta _{3})={\begin{pmatrix}c_{123}&-s_{123}&l_{1}c_{1}+l_{2}c_{12}+l_{3}c_{123}\\s_{123}&c_{123}&l_{1}s_{1}+l_{2}s_{12}+l_{3}s_{123}\\0&0&1\end{pmatrix}}}
Hence:
(
x
y
1
)
=
T
(
0
0
1
)
{\displaystyle {\begin{pmatrix}x\\y\\1\end{pmatrix}}=T{\begin{pmatrix}0\\0\\1\end{pmatrix}}}
The resulting kinematic equations are:
x
=
l
1
cos
θ
1
+
l
2
cos
(
θ
1
+
θ
2
)
+
l
3
cos
(
θ
1
+
θ
2
+
θ
3
)
y
=
l
1
sin
θ
1
+
l
2
sin
(
θ
1
+
θ
2
)
+
l
3
sin
(
θ
1
+
θ
2
+
θ
3
)
{\displaystyle {\begin{array}{l}x=l_{1}\cos \theta _{1}+l_{2}\cos(\theta _{1}+\theta _{2})+l_{3}\cos(\theta _{1}+\theta _{2}+\theta _{3})\\y=l_{1}\sin \theta _{1}+l_{2}\sin(\theta _{1}+\theta _{2})+l_{3}\sin(\theta _{1}+\theta _{2}+\theta _{3})\end{array}}}
The inverse kinematics problem is the opposite of the forward kinematics problem and can be summarized as follows: given the desired position of the end effector, what combinations of the joint angles can be used to achieve this position?
An example of two different solutions for the inverse kinematics problem leading to the same end-effector position and orientation.
Two types of solutions can be considered: a closed-form solution and a numerical solution. Closed-form or analytical solutions are sets of equations that fully describe the connection between the end-effector position and the joint angles. Numerical solutions are found through the use of numerical algorithms, and can exist even when no closed-form solution is available. There may also be multiple solutions, or no solution at all.
The inverse kinematics problem for this 2D manipulator can quite easily be solved algebraically.
From the earlier results (for simplicity, the displacement over the distance
l
3
{\displaystyle l_{3}}
shall be omitted here):
0
3
T
=
(
c
123
−
s
123
0
l
1
c
1
+
l
2
c
12
s
123
c
123
0
l
1
s
1
+
l
2
s
12
0
0
1
0
0
0
0
1
)
{\displaystyle _{0}^{3}T={\begin{pmatrix}c_{123}&-s_{123}&0&l_{1}c_{1}+l_{2}c_{12}\\s_{123}&c_{123}&0&l_{1}s_{1}+l_{2}s_{12}\\0&0&1&0\\0&0&0&1\\\end{pmatrix}}}
Now assume a given end-effector orientation in the following form:
b
s
e
e
T
=
(
c
ϕ
−
s
ϕ
0
x
s
ϕ
c
ϕ
0
y
0
0
1
0
0
0
0
1
)
{\displaystyle _{bs}^{ee}T={\begin{pmatrix}c_{\phi }&-s_{\phi }&0&x\\s_{\phi }&c_{\phi }&0&y\\0&0&1&0\\0&0&0&1\\\end{pmatrix}}}
Equating the two previous expressions results in:
c
ϕ
=
c
123
s
ϕ
=
s
123
x
=
l
1
c
1
+
l
2
c
12
y
=
l
1
s
1
+
l
2
s
12
{\displaystyle {\begin{array}{lll}c_{\phi }&=&c_{123}\\s_{\phi }&=&s_{123}\\x&=&l_{1}c_{1}+l_{2}c_{12}\\y&=&l_{1}s_{1}+l_{2}s_{12}\\\end{array}}}
As:
c
12
=
c
1
c
2
−
s
1
s
2
s
12
=
c
1
s
2
+
s
1
c
2
{\displaystyle {\begin{array}{lll}c_{12}&=&c_{1}c_{2}-s_{1}s_{2}\\s_{12}&=&c_{1}s_{2}+s_{1}c_{2}\\\end{array}}}
,
squaring both the expressions for
x
{\displaystyle x}
and
y
{\displaystyle y}
and adding them, leads to:
x
2
+
y
2
=
l
1
2
+
l
2
2
+
2
l
1
l
2
c
2
{\displaystyle x^{2}+y^{2}=l_{1}^{2}+l_{2}^{2}+2l_{1}l_{2}c_{2}}
Solving for
c
2
{\displaystyle c_{2}}
leads to:
c
2
=
x
2
+
y
2
−
l
1
2
−
l
2
2
2
l
1
l
2
{\displaystyle c_{2}={\frac {x^{2}+y^{2}-l_{1}^{2}-l_{2}^{2}}{2l_{1}l_{2}}}}
,
while
s
2
{\displaystyle s_{2}}
equals:
s
2
=
±
1
−
c
2
2
{\displaystyle s_{2}=\pm {\sqrt {1-c_{2}^{2}}}}
,
and, finally,
θ
2
{\displaystyle \theta _{2}}
:
θ
2
=
Atan2
(
s
2
,
c
2
)
{\displaystyle \theta _{2}={\mbox{Atan2}}(s_{2},c_{2})}
Note : The choice of the sign for
s
2
{\displaystyle s_{2}}
corresponds with one of the two solutions in the figure above.
The expressions for
x
{\displaystyle x}
and
y
{\displaystyle y}
may now be solved for
θ
1
{\displaystyle \theta _{1}}
. In order to do so, write them like this:
x
=
k
1
c
1
−
k
2
s
1
y
=
k
1
s
1
+
k
2
c
1
{\displaystyle {\begin{array}{lll}x&=&k_{1}c_{1}-k_{2}s_{1}\\y&=&k_{1}s_{1}+k_{2}c_{1}\\\end{array}}}
where
k
1
=
l
1
+
l
2
c
2
{\displaystyle k_{1}=l_{1}+l_{2}c_{2}}
, and
k
2
=
l
2
s
2
{\displaystyle k_{2}=l_{2}s_{2}}
.
Let:
r
=
k
1
2
+
k
2
2
γ
=
Atan2
(
k
2
,
k
1
)
{\displaystyle {\begin{array}{lll}r&=&{\sqrt {k_{1}^{2}+k_{2}^{2}}}\\\gamma &=&{\mbox{Atan2}}(k2,k1)\\\end{array}}}
Then:
k
1
=
r
cos
γ
k
2
=
r
sin
γ
{\displaystyle {\begin{array}{lll}k_{1}&=&r\cos \gamma \\k_{2}&=&r\sin \gamma \\\end{array}}}
Applying these to the above equations for
x
{\displaystyle x}
and
y
{\displaystyle y}
:
x
/
r
=
cos
γ
c
1
+
sin
γ
s
1
y
/
r
=
cos
γ
s
1
+
sin
γ
c
1
{\displaystyle {\begin{array}{lll}x/r&=&\cos \gamma \,c_{1}+\sin \gamma \,s_{1}\\y/r&=&\cos \gamma \,s_{1}+\sin \gamma \,c_{1}\\\end{array}}}
,
or:
cos
(
γ
+
θ
1
)
=
x
r
sin
(
γ
+
θ
1
)
=
y
r
{\displaystyle {\begin{array}{lll}\cos(\gamma +\theta _{1})&=&{\frac {x}{r}}\\\sin(\gamma +\theta _{1})&=&{\frac {y}{r}}\\\end{array}}}
Thus:
γ
+
θ
1
=
Atan2
(
y
,
x
)
{\displaystyle \gamma +\theta _{1}={\mbox{Atan2}}(y,x)}
Hence:
θ
1
=
Atan2
(
y
,
x
)
−
Atan2
(
k
2
,
k
1
)
{\displaystyle \theta _{1}={\mbox{Atan2}}(y,x)-{\mbox{Atan2}}(k_{2},k_{1})}
Note : If
x
=
y
=
0
{\displaystyle x=y=0}
,
θ
1
{\displaystyle \theta _{1}}
actually becomes arbitrary.
θ
3
{\displaystyle \theta _{3}}
may now be solved from the first two equations for
s
ϕ
{\displaystyle s_{\phi }}
and
c
ϕ
{\displaystyle c_{\phi }}
:
θ
3
=
ϕ
−
θ
1
−
θ
2
=
Atan2
(
s
ϕ
,
c
ϕ
)
−
θ
1
−
θ
2
{\displaystyle \theta _{3}=\phi -\theta _{1}-\theta _{2}={\mbox{Atan2}}(s_{\phi },c_{\phi })-\theta _{1}-\theta _{2}}