Skip to content
Snippets Groups Projects
Commit 24abdf9e authored by Jan Niklas Holzheim's avatar Jan Niklas Holzheim
Browse files

Upload New File

parent 70c88d7e
Branches develop
No related tags found
No related merge requests found
%% Cell type:markdown id:e4ccc978 tags:
# Forward Kinematics - Denavit-Hartenberg Matrix
%% Cell type:markdown id:79d129c2 tags:
![txt](task1.png)
%% Cell type:markdown id:d138648a tags:
## Exercise 1:
The frame attachment information and the DH table of the Puma 560 robot are given below.
The constant parameters are
- h = 40 cm,
- $a_2$ = 50 cm,
- $a_3$ = 10 cm,
- $d_3$ = 20 cm and
- $d_4$ = 30 cm.
1. Find transformation matrices between every consectuive frame.
**Remember**:
$T_{i-1}^i =
\begin{bmatrix}
c_{\theta} & -s_{\theta}c_{\alpha} & s_{\theta}s_{\alpha} & a_i c_{\theta} \\
s_{\theta} & c_{\theta}c_{\alpha} & -c_{\theta}s_{\alpha} & a_i s_{\theta}\\
0 & s_{\alpha} & c_{\alpha} & d_i\\
0 & 0 & 0 & 1\\
\end{bmatrix}$
2. Find the angular Jacobian matrix ($J_{\omega}$) between the world frame and the end-effector.
**Remember**:
$J_{\omega} = \begin{bmatrix}
R_{0}^1 \begin{bmatrix}0\\0\\1\end{bmatrix} & R_{0}^2 \begin{bmatrix}0\\0\\1\end{bmatrix} & R_{0}^3 \begin{bmatrix}0\\0\\1\end{bmatrix} & R_{0}^4 \begin{bmatrix}0\\0\\1\end{bmatrix} & R_{0}^5 \begin{bmatrix}0\\0\\1\end{bmatrix} & R_{0}^6 \begin{bmatrix}0\\0\\1\end{bmatrix}
\end{bmatrix}$
%% Cell type:code id:856e8c26 tags:
``` python
# importing necessary modules
import numpy as np
import math
!pip install sympy
import sympy as sym
#setting the precision for decimal values.|
%precision 4
```
%% Cell type:markdown id:3e160bf2 tags:
Define your constant parameter **$h$**, **$a_i$** and **$d_i$**. You can define the variable parameters **$\theta_i$** using the [`Symbol`](https://www.tutorialspoint.com/sympy/sympy_symbols.htm) function available in the `sympy` library. A quick start tutorial to the sympy library can be found [here](https://docs.sympy.org/latest/tutorials/intro-tutorial/gotchas.html). We use the library [sympy](https://www.sympy.org/en/index.html) in the context of this task to allow for matrix multiplication with elements of the matrix being symbolic, since the $\theta_i$ values are variable parameters.
%% Cell type:code id:2a7a4011 tags:
``` python
#YOUR CODE HERE
```
%% Cell type:code id:946fe40a tags:
``` python
#SAMPLE SOLUTION
# constant parameters
h = 0.4 # in meter
a_2 = 0.5 # in meter
a_3 = 0.1 # in meter
d_3 = 0.2 # in meter
d_4 = 0.3 # in meter
# variable parameters
#A quick start tutorial to the sympy library - https://docs.sympy.org/latest/tutorials/intro-tutorial/gotchas.html
theta_1 = sym.Symbol('theta_1')
theta_2 = sym.Symbol('theta_2')
theta_3 = sym.Symbol('theta_3')
theta_4 = sym.Symbol('theta_4')
theta_5 = sym.Symbol('theta_5')
theta_6 = sym.Symbol('theta_6')
```
%% Cell type:markdown id:023cc991 tags:
Create a table to store the value of the DH table.
**Hint:** Try using the [`array`](https://numpy.org/doc/stable/reference/generated/numpy.array.html) function from the `numpy` library. Each row of the array will represent row from the DH table.
%% Cell type:code id:6fb13c2f tags:
``` python
#YOUR CODE HERE
```
%% Cell type:code id:1bd37565 tags:
``` python
#SAMPLE SOLUTION
# creating an array for the DH table
#the values are in the order shown in the table
dh_table = np.array([(0,0,h,theta_1),
(-90,0,0,theta_2),
(0,a_2,d_3,theta_3),
(-90,a_3,d_4,theta_4),
(90,0,0,theta_5),
(-90,0,0,theta_6)])
print(dh_table)
```
%% Cell type:markdown id:af6b38c9 tags:
Create a function `calc_T` that takes as input the values from each row of the DH table and then calculates the transformation matrix $T_{i-1}^i$ for each row of the DH Table.
**Hint:** Check the [`Matrix`](https://docs.sympy.org/latest/tutorials/intro-tutorial/matrices.html) function provided in the `sympy` package
**Note:** Once you implement the function remove the `pass` keyword from the function.
%% Cell type:code id:5ae5f46a tags:
``` python
# function to calculate transformation matrix
def calc_T(alpha, a, d, theta):
#YOUR CODE HERE
pass
```
%% Cell type:code id:0ee7c6bd tags:
``` python
#SAMPLE SOLUTION
# function to calculate transformation matrix
def calc_T(alpha, a, d, theta):
s_theta = sym.sin(theta)
c_theta = sym.cos(theta)
s_alpha = math.sin(math.radians(alpha))
c_alpha = math.cos(math.radians(alpha))
# Sympy Matrix Documentation - https://docs.sympy.org/latest/tutorials/intro-tutorial/matrices.html
T = sympy.Matrix([[c_theta, -s_theta*s_alpha, s_theta*s_alpha,a*c_theta],
[s_theta, c_theta*c_alpha, -c_theta*s_alpha, a*s_theta],
[0, s_alpha, c_alpha, d],
[0,0,0,1]])
return T
```
%% Cell type:markdown id:9d36c06b tags:
## To Kemal and Jan
I think we can leave the below cell as such so that they will understand how the data is being input to the function. We can leave out this section for Task 2.
%% Cell type:code id:fd3975c1 tags:
``` python
n_frame = dh_table.shape[0]
T_list = []
for i in range(0,n_frame):
T = calc_T(alpha=dh_table[i,0], a=dh_table[i,1], d=dh_table[i,2], theta=dh_table[i,3])
T_list.append(T)
```
%% Cell type:markdown id:56230bbd tags:
Print the transformation matrix $T_{0}^1$:
%% Cell type:code id:fb9fff68 tags:
``` python
#Print statement here
```
%% Cell type:code id:5a2f93fc tags:
``` python
#SAMPLE SOLUTION
T_list[0]
```
%% Cell type:markdown id:2fbdb3d4 tags:
Print the transformation matrix $T_{1}^2$:
%% Cell type:code id:aee3978b tags:
``` python
#Print statement here
```
%% Cell type:code id:92c4262b tags:
``` python
#SAMPLE SOLUTION
T_list[1]
```
%% Cell type:markdown id:08d7ff99 tags:
Print the transformation matrix $T_{2}^3$:
%% Cell type:code id:4e2ceb82 tags:
``` python
#Print statement here
```
%% Cell type:code id:3013564b tags:
``` python
#SAMPLE SOLUTION
T_list[2]
```
%% Cell type:markdown id:66b1f49b tags:
Print the transformation matrix $T_{3}^4$:
%% Cell type:code id:15a390dc tags:
``` python
#Print statement here
```
%% Cell type:code id:27ad3be0 tags:
``` python
#SAMPLE SOLUTION
T_list[3]
```
%% Cell type:markdown id:5f1a09eb tags:
Print the transformation matrix $T_{4}^5$:
%% Cell type:code id:a2bda339 tags:
``` python
#Print statement here
```
%% Cell type:code id:e7272bd3 tags:
``` python
#SAMPLE SOLUTION
T_list[4]
```
%% Cell type:markdown id:139344a9 tags:
Print the transformation matrix $T_{5}^6$:
%% Cell type:code id:71646159 tags:
``` python
#Print statement here
```
%% Cell type:code id:80000505 tags:
``` python
#SAMPLE SOLUTION
T_list[5]
```
%% Cell type:markdown id:95844079 tags:
## Note To kemal
I don't understand how you want the rotational jacobian to be formed. The lecture say that the jacobian is made of derivatives. But the task mentions to use the rotation matrix. So, I am not sure how to set up this task
%% Cell type:markdown id:86f1dd3f tags:
## Exercise 2
![Task2](taks2.png)
%% Cell type:markdown id:b0494415 tags:
For this exercise we will use the same steps as before with the **only** difference being the values of $a_{i-1}$ is also a variable.
We will follow the steps below to complete this task
1. Define the variables as symbols using the `Symbol` function from the `sympy` library.
2. Create a DH table using the `array` function from the `numpy` library.
3. Define a function `calc_T` which takes as input the variable required to calculate the transformation matrix $T_{i-1}^i$ .
4. Create a `for` loop that will call the `calc_T` repeatedly to calculate the tranformation matrix one by one.
%% Cell type:code id:33a02c35 tags:
``` python
# 1. Define the variables as symbols using the `Symbol` function from the `sympy` library.
```
%% Cell type:code id:ced0882f tags:
``` python
# 2. Create a DH table using the `array` function from the `numpy` library.
```
%% Cell type:code id:7ad86c87 tags:
``` python
#3. Define a function `calc_T` which takes as input the variable required to calculate the transformation matrix T_{i-1}^i.
```
%% Cell type:code id:d735ae4e tags:
``` python
#4. Create a `for` loop that will call the `calc_T` repeatedly to calculate the tranformation matrix one by one.
```
%% Cell type:markdown id:0409b179 tags:
Finally calculate the transformation matrix $T_{0}^3$ from the base frame `0` to the end effector frame `3`.
%% Cell type:code id:fcb08280 tags:
``` python
#calculate the transformation between the base and end-effector frame.
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment