Skip to content
Snippets Groups Projects
Commit 0c82e311 authored by holzheim's avatar holzheim
Browse files

Added documentation for tutorial

parent 3762efa0
No related branches found
No related tags found
No related merge requests found
Showing
with 109 additions and 0 deletions
## 01 Tutorial: Introduction to Python
The task for this tutorial can be found in the [01_Tutorial_PythonIntroduction jupyter notebook](01_Tutorial_PythonIntroduction.ipynb). Following, the steps how to import the jupyter notebook to [jupyter hub](https://jupyter.rwth-aachen.de/hub/login).
1. Download the [01_Tutorial_PythonIntroduction jupyter notebook](https://git.rwth-aachen.de/introduction-to-robotics-course/introduction-to-robotics-2023/-/blob/main/01_IntroductionToPython/01_Tutorial_PythonIntroduction.ipynb).
![GIF that shows download of the jupyter notebook](media/download_jupyter_notebook.gif)
2. Open the [RWTH JupyterHub](https://jupyter.rwth-aachen.de/hub/login) website and sign in using RWTH Single Sign-On.
![GIF showing sign in process to RWTH jupyterHub](media/login_jupyterHub.gif)
3. Inside RWTH JupyterHub create a new folder named **i2r**.
![GIF showing process to create new folder](media/creating_folder.gif)
4. Upload the [01_Tutorial_PythonIntroduction jupyter notebook](01_Tutorial_PythonIntroduction.ipynb) and the [forward_kinematics module](forward_kinematics.py) to the **i2r** folder.
![GIF showing process to import files](media/import_files.gif)
5. You can open the file by just double-click the file name in the file browser.
![GIF showing how to open files](media/opening_files.gif)
6. To run/execute the code you implemented in a cell, click into that cell and click the ***Run the selected cells and advance*** button like show below.
![GIF showing how to run a cell](media/run_a_cell.gif)
7. Once you made changes inside the file **forward_kinematics.py** make sure to save the file (Press `Ctrl` + `S` (on a german keyboard `Strg` + `S`)) and click on ***Restart the kernal, then re-run the whole notebook*** inside of the notebook from which you are calling a function of the module.
![GIF showing how to restart the kernal](media/restart_kernal.gif)
# This Python file contains different functions we implemented to perform forward kinematics
#
# First we have to make sure to import the modules with the functions we need for the functions.
# Here we just need the 'math' module which includes among others the following functions:
# - cos(x): returns cosine of x in radians
# - sin(x): returns sine of x in radians
# - radians(x): converts x from degree to radians
import math
# Here we define the function of the name 'forward_kinematics_nLinks_2'.
# For an elbow manipulator in planar space with 2 DoF the function calculates
# the coordinates of the end effector joint.
# The function has to be called with the follwing arguments:
# - a_1: length of link 1
# - a_2: lenght of link 2
# - theta_1: rotation of joint 1
# - theta_2: rotation of joint 2
# The function returns the x and y coordinate of the end effector joint.
def forward_kinematics_nLinks_2(a_1, a_2, theta_1, theta_2):
x = a_1 * math.cos(math.radians(theta_1)) + a_2 * math.cos(math.radians(theta_1 + theta_2))
y = a_1 * math.sin(math.radians(theta_1)) + a_2 * math.sin(math.radians(theta_1 + theta_2))
return x, y
# Here we define the function of the name 'forward_kinematics'.
# For an elbow manipulator in planar space with n DoF the function calculates
# the coordinates of the end effector joint.
# The function has to be called with the follwing arguments:
# - x_0: x coordinate of the refernce coordinate frame
# - y_0: y coordinate of the reference coordinate frame
# - list_a: list with the lenghts [a_1, a_2, ..., a_n] of the links
# - list_theta: list with the rotations [theta_1, theta_2, ..., theta_n] of the joints
# The function returns the x and y coordinate of the end effector joint.
def forward_kinematics(x_0, y_0, list_a, list_theta):
x = x_0
y = y_0
sum_theta = 0
# The zip() function takes iterables (can be zero or more), aggregates them in a tuple, and returns it.
for a, theta in zip(list_a, list_theta):
sum_theta = sum_theta + theta
x = x + a * math.cos(math.radians(sum_theta))
y = y + a * math.sin(math.radians(sum_theta))
return x, y
# Here we define the function of the name 'fk_getJointCoords'.
# For an elbow manipulator in planar space with n DoF the function calculates
# the coordinates of the joints.
# The function has to be called with the follwing arguments:
# - x_0: x coordinate of the refernce coordinate frame
# - y_0: y coordinate of the reference coordinate frame
# - list_a: list with the lenghts [a_1, a_2, ..., a_n] of the links
# - list_theta: list with the rotations [theta_1, theta_2, ..., theta_n] of the joints
# The function returns two lists. 'joint_x_coords' contains the x coordinates of the joints and
# 'joint_y_coords' contains the y coordinates of the joints.
# This function is used to be able to plot the resulting elbow manipulator configuration.
def fk_getJointCoords(x_0, y_0, list_a, list_theta):
x = x_0
y = y_0
sum_theta = 0
joint_x_coords = [x_0]
joint_y_coords = [y_0]
# The zip() function takes iterables (can be zero or more), aggregates them in a tuple, and returns it.
for a, theta in zip(list_a, list_theta):
sum_theta = sum_theta + theta
x = x + a * math.cos(math.radians(sum_theta))
y = y + a * math.sin(math.radians(sum_theta))
joint_x_coords.append(x)
joint_y_coords.append(y)
return joint_x_coords, joint_y_coords
\ No newline at end of file
01_IntroductionToPython/Tutorial/media/creating_folder.gif

900 KiB

File added
01_IntroductionToPython/Tutorial/media/download_jupyter_notebook.gif

5.86 MiB

File added
01_IntroductionToPython/Tutorial/media/import_files.gif

5.07 MiB

File added
01_IntroductionToPython/Tutorial/media/jupyter_hub_rwth_login.png

123 KiB

01_IntroductionToPython/Tutorial/media/login_jupyterHub.gif

1.91 MiB

File added
01_IntroductionToPython/Tutorial/media/opening_files.gif

5.27 MiB

File added
01_IntroductionToPython/Tutorial/media/palette.png

993 B

01_IntroductionToPython/Tutorial/media/restart_kernal.gif

5.62 MiB

File added
01_IntroductionToPython/Tutorial/media/run_a_cell.gif

3.66 MiB

File added
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment