Commit ยท
a90068b
1
Parent(s): e1066b4
updated seo
Browse files- README.md +99 -8
- controls.png +0 -0
README.md
CHANGED
|
@@ -1,10 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--
|
| 2 |
+
SEO: Interactive Arm Simulator, 2-DOF robotic arm, inverse kinematics, python gradio app, robotics education, interactive simulation, arm kinematics visualization, open source robotics tool, robot arm math, educational robotics, engineering demo, real-time robotics, STEM learning
|
| 3 |
+
Description: Interactive Arm Simulator is a Python Gradio app for simulating and visualizing the inverse kinematics of a 2-DOF robotic arm. Adjust controls, see real-time results, and learn the math behind robotic arms. Perfect for education, demos, and open source robotics projects.
|
| 4 |
+
-->
|
| 5 |
+
|
| 6 |
+
# Interactive Arm Simulator
|
| 7 |
+
|
| 8 |
+

|
| 9 |
+
|
| 10 |
+
A modern, interactive Gradio app for simulating the inverse kinematics of a 2-DOF (two-degree-of-freedom) robotic arm. Visualize, experiment, and learn the math behind robotic arm movement in real-time!
|
| 11 |
+
|
| 12 |
---
|
| 13 |
+
|
| 14 |
+
## ๐ Features
|
| 15 |
+
- **Live Simulation:** Adjust target coordinates (X, Y) and arm lengths (L1, L2) with sliders and see the arm move instantly.
|
| 16 |
+
- **Visual Feedback:** Clear visualization of the arm, joints, and unreachable targets.
|
| 17 |
+
- **Angle Display:** See calculated joint angles (shoulder and elbow) in both radians and degrees.
|
| 18 |
+
- **Math Explanation:** Built-in accordion explains the inverse kinematics formulas.
|
| 19 |
+
- **Copyable Python Code:** Easily grab the core function to use in your own projects.
|
| 20 |
+
|
| 21 |
---
|
| 22 |
+
|
| 23 |
+
## ๐น๏ธ Controls Preview
|
| 24 |
+

|
| 25 |
+
*Use the sliders to set the arm lengths and target position. The plot updates in real-time.*
|
| 26 |
+
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
## ๐ฆ Usage
|
| 30 |
+
1. **Install requirements:**
|
| 31 |
+
```bash
|
| 32 |
+
pip install gradio matplotlib numpy
|
| 33 |
+
```
|
| 34 |
+
2. **Run the app:**
|
| 35 |
+
```bash
|
| 36 |
+
python app.py
|
| 37 |
+
```
|
| 38 |
+
3. **Interact:**
|
| 39 |
+
- Move the sliders for X, Y, L1, and L2.
|
| 40 |
+
- Watch the arm and joint angles update.
|
| 41 |
+
- Use the "Copy the Core Python Function" dropdown for your own code.
|
| 42 |
+
|
| 43 |
+
---
|
| 44 |
+
|
| 45 |
+
## ๐งฎ How It Works: Inverse Kinematics
|
| 46 |
+
This app calculates the joint angles needed for a 2-link arm to reach a target point (x, y) using geometry:
|
| 47 |
+
|
| 48 |
+
**1. Elbow Angle ($q_2$):**
|
| 49 |
+
Uses the Law of Cosines:
|
| 50 |
+
|
| 51 |
+
$$ \cos(q_2) = \frac{x^2 + y^2 - L_1^2 - L_2^2}{2L_1L_2} $$
|
| 52 |
+
|
| 53 |
+
**2. Shoulder Angle ($q_1$):**
|
| 54 |
+
Combines the angle to the target and the triangle's internal angle:
|
| 55 |
+
|
| 56 |
+
$$ q_1 = \alpha - \beta $$
|
| 57 |
+
Where:
|
| 58 |
+
- $\alpha = \text{atan2}(y, x)$ (angle to target)
|
| 59 |
+
- $\beta = \text{atan2}(L_2 \sin(q_2), L_1 + L_2 \cos(q_2))$
|
| 60 |
+
|
| 61 |
+
If the target is unreachable, the app shows a warning and marks it in red.
|
| 62 |
+
|
| 63 |
+
---
|
| 64 |
+
|
| 65 |
+
## ๐ Copy the Core Python Function
|
| 66 |
+
The app includes a dropdown with the following code for your use:
|
| 67 |
+
|
| 68 |
+
```python
|
| 69 |
+
def inver_k(l1, l2, x, y):
|
| 70 |
+
"""
|
| 71 |
+
Calculates the joint angles (q1, q2) for a 2-DOF robotic arm.
|
| 72 |
+
Args:
|
| 73 |
+
l1, l2: Lengths of the arm segments
|
| 74 |
+
x, y: Target coordinates
|
| 75 |
+
Returns:
|
| 76 |
+
(success, q1, q2): Whether the point is reachable and the joint angles in radians
|
| 77 |
+
"""
|
| 78 |
+
import math
|
| 79 |
+
import numpy as np
|
| 80 |
+
dist_sq = x**2 + y**2
|
| 81 |
+
if dist_sq > (l1 + l2)**2 or dist_sq < (l1 - l2)**2:
|
| 82 |
+
return (False, 0, 0)
|
| 83 |
+
cos_q2 = (dist_sq - l1**2 - l2**2) / (2 * l1 * l2)
|
| 84 |
+
cos_q2 = np.clip(cos_q2, -1.0, 1.0)
|
| 85 |
+
q2 = math.acos(cos_q2)
|
| 86 |
+
alpha = math.atan2(y, x)
|
| 87 |
+
beta = math.atan2(l2 * math.sin(q2), l1 + l2 * math.cos(q2))
|
| 88 |
+
q1 = alpha - beta
|
| 89 |
+
return (True, q1, q2)
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
---
|
| 93 |
+
|
| 94 |
+
## ๐ Credits
|
| 95 |
+
- Original inverse kinematics logic from [ARMv6 by gokul6350](https://github.com/gokul6350/ARMv6/blob/main/main_src/inverse_k.py)
|
| 96 |
+
- Adapted and extended as an interactive Gradio app for educational purposes.
|
| 97 |
+
|
| 98 |
+
---
|
| 99 |
+
|
| 100 |
+
## License
|
| 101 |
+
MIT
|
controls.png
ADDED
|