Developed with the software and tools below.
Well, this repository is the kinda-final form of my hobby project. I first got the idea from a visualization by Matt Henderson a while ago, and recently decided to implement it to expose myself to web development a bit. I also deployed the application to Heroku but don't want to pay for more resources, so I hope no more than a few users try to use it at the same time :D You can use it locally by following the installation steps, though :) I think it might be a good educational resource for some instructors to use in lectures.
This web application aims to visualize inverse kinematics via gradient descent optimization.
Inverse kinematics (IK) deals with finding the joint parameters (angles) that provide a desired position of the robot's end effector. For a robot arm in a 2D plane, this involves calculating the angles of its joints such that the end of the arm reaches a specific point
For a simple 2-joint (2-link) robot arm in a 2D plane, the forward kinematics can be expressed as:
Where:
Gradient descent is an optimization algorithm used to minimize a function by iteratively moving towards the steepest descent, i.e., the negative gradient of the function. In the context of inverse kinematics, the function we want to minimize is the error between the current position of the end effector and the target position.
The error function E can be defined as the squared Euclidean distance between the current end effector position
In the application, you can select various error functions and observe the effect of different error functions on the optimization process
To minimize the error E, we need to compute its gradients with respect to the joint angles
Using the chain rule and the kinematic equations, these gradients can be derived.
We compute the gradients by defining joint angles as parameters and calculating the end effector position as a function of joint angles to leverage automatic differentiation of PyTorch.
With the gradients computed, the joint angles are updated iteratively using the gradient descent rule:
Here,
The iterative process continues until the error E is minimized to an acceptable level, meaning the end effector is sufficiently close to the target position.
Inverse kinematics via gradient descent optimization involves:
Defining the kinematic equations for the robot arm. Setting up an error function representing the distance between the current and target positions. Calculating the gradients of the error function with respect to the joint angles. Iteratively updating the joint angles using gradient descent to minimize the error.
βββ inverse-kinematics-app/
βββ Procfile
βββ README.md
βββ app.py #main logic for optimization
βββ client
β βββ .gitignore
β βββ .vscode
β β βββ extensions.json
β βββ README.md
β βββ __init__.py
β βββ dist
β β βββ assets
β β β βββ index-Bw-pKMAr.js
β β β βββ index-CV_YbN5t.css
β β βββ favicon.ico
β β βββ index.html
β βββ index.html
β βββ jsconfig.json
β βββ package-lock.json
β βββ package.json
β βββ public
β β βββ favicon.ico
β βββ src
β β βββ App.vue
β β βββ assets
β β β βββ base.css
β β β βββ logo.svg
β β β βββ main.css
β β βββ components
β β β βββ Config.vue
β β β βββ Visualizer.vue #main logic for visualization
β β βββ main.js
β β βββ router
β β βββ index.js
β βββ vite.config.js
βββ requirements.txt
βββ runtime.txt
- Clone the inverse-kinematics-app repository:
git clone https://github.com/mrodiduger/inverse-kinematics-app
- Change to the project directory:
cd inverse-kinematics-app
- Create a virtual environment and install dependecies:
python3 -m venv -venv
source .venv/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements.txt
Use the following command to run inverse-kinematics-app:
flask run
This project is protected under the MIT License.