# Robotics Kinematics and Dynamics/Serial Manipulator Position Kinematics
## Forward Position Kinematics

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 $_{bs}^{ee}T\,$, where $\{bs\}$ is the base frame of the robot manipulator.

### Solution

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:
    $_{bs}^{ee}T=\,_{0}^{N}T=\,_{0}^{1}T\,_{1}^{2}T\ldots \,_{N-2}^{N-1}T\,_{N-1}^{N}T$

### Examples
#### The Planar Three-Link Manipulator

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}(\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}(\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 $\theta _{2}$ and a translation by a distance $l_{1}$, where $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}(\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}={\begin{pmatrix}1&0&l_{3}\\0&1&0\\0&0&1\end{pmatrix}}$
The solution to the forward kinematics problem is then:
    $_{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:
    ${\begin{pmatrix}x\\y\\1\end{pmatrix}}=T{\begin{pmatrix}0\\0\\1\end{pmatrix}}$
The resulting kinematic equations are:
    ${\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}}$

## Inverse Position Kinematics

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

### Example: Planar Three-Link Manipulator

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}$ shall be omitted here):
    $_{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:
    $_{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:
    ${\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:
    ${\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$ and $y$ and adding them, leads to:
    $x^{2}+y^{2}=l_{1}^{2}+l_{2}^{2}+2l_{1}l_{2}c_{2}$
Solving for $c_{2}$ leads to:
    $c_{2}={\frac {x^{2}+y^{2}-l_{1}^{2}-l_{2}^{2}}{2l_{1}l_{2}}}$,
while $s_{2}$ equals:
    $s_{2}=\pm {\sqrt {1-c_{2}^{2}}}$,
and, finally, $\theta _{2}$:
    $\theta _{2}={\mbox{Atan2}}(s_{2},c_{2})$
Note: The choice of the sign for $s_{2}$ corresponds with one of the two solutions in the figure above.
The expressions for $x$ and $y$ may now be solved for $\theta _{1}$. In order to do so, write them like this:
    ${\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}$, and $k_{2}=l_{2}s_{2}$.
Let:
    ${\begin{array}{lll}r&=&{\sqrt {k_{1}^{2}+k_{2}^{2}}}\\\gamma &=&{\mbox{Atan2}}(k2,k1)\\\end{array}}$
Then:
    ${\begin{array}{lll}k_{1}&=&r\cos \gamma \\k_{2}&=&r\sin \gamma \\\end{array}}$
Applying these to the above equations for $x$ and $y$:
    ${\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:
    ${\begin{array}{lll}\cos(\gamma +\theta _{1})&=&{\frac {x}{r}}\\\sin(\gamma +\theta _{1})&=&{\frac {y}{r}}\\\end{array}}$
Thus:
    $\gamma +\theta _{1}={\mbox{Atan2}}(y,x)$
Hence:
    $\theta _{1}={\mbox{Atan2}}(y,x)-{\mbox{Atan2}}(k_{2},k_{1})$
Note: If $x=y=0$, $\theta _{1}$ actually becomes arbitrary.
$\theta _{3}$ may now be solved from the first two equations for $s_{\phi }$ and $c_{\phi }$:
    $\theta _{3}=\phi -\theta _{1}-\theta _{2}={\mbox{Atan2}}(s_{\phi },c_{\phi })-\theta _{1}-\theta _{2}$