deltakin 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- deltakin/__init__.py +14 -0
- deltakin/errors.py +13 -0
- deltakin/robot.py +232 -0
- deltakin-0.1.0.dist-info/METADATA +74 -0
- deltakin-0.1.0.dist-info/RECORD +8 -0
- deltakin-0.1.0.dist-info/WHEEL +5 -0
- deltakin-0.1.0.dist-info/licenses/LICENSE +21 -0
- deltakin-0.1.0.dist-info/top_level.txt +1 -0
deltakin/__init__.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""deltakin: forward and inverse kinematics for 3-DOF Delta parallel robots."""
|
|
2
|
+
from .errors import DeltaKinematicsError, SingularityError, UnreachableError
|
|
3
|
+
from .robot import DeltaGeometry, DeltaRobot
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"DeltaRobot",
|
|
7
|
+
"DeltaGeometry",
|
|
8
|
+
"DeltaKinematicsError",
|
|
9
|
+
"UnreachableError",
|
|
10
|
+
"SingularityError",
|
|
11
|
+
]
|
|
12
|
+
__version__ = "0.1.0"
|
|
13
|
+
__author__ = "Salim Toumache"
|
|
14
|
+
__email__ = "salimtoumache@gmail.com"
|
deltakin/errors.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Exceptions raised by deltakin."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class DeltaKinematicsError(Exception):
|
|
5
|
+
"""Base class for all deltakin errors."""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class UnreachableError(DeltaKinematicsError, ValueError):
|
|
9
|
+
"""The requested position (or joint configuration) has no valid solution."""
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SingularityError(DeltaKinematicsError, ArithmeticError):
|
|
13
|
+
"""The configuration is singular and the solution is undefined."""
|
deltakin/robot.py
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"""Kinematics of a 3-DOF Delta parallel robot.
|
|
2
|
+
|
|
3
|
+
Notation and equations follow:
|
|
4
|
+
R. L. Williams II, "The Delta Parallel Robot: Kinematics Solutions",
|
|
5
|
+
Ohio University.
|
|
6
|
+
|
|
7
|
+
Frame: origin at the centre of the base, z axis pointing up, so a platform
|
|
8
|
+
hanging below the base has a negative z. Leg 1 sits on the -y side, legs 2
|
|
9
|
+
and 3 on the +x / -x sides.
|
|
10
|
+
|
|
11
|
+
All lengths share one (arbitrary) unit; the equations are scale free.
|
|
12
|
+
"""
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import math
|
|
16
|
+
from dataclasses import dataclass
|
|
17
|
+
from typing import Iterable, List, Sequence, Tuple
|
|
18
|
+
|
|
19
|
+
from .errors import SingularityError, UnreachableError
|
|
20
|
+
|
|
21
|
+
Vec3 = Tuple[float, float, float]
|
|
22
|
+
|
|
23
|
+
_SQRT3 = math.sqrt(3.0)
|
|
24
|
+
_UNITS = ("deg", "rad")
|
|
25
|
+
_BRANCHES = ("primary", "alternate")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass(frozen=True)
|
|
29
|
+
class DeltaGeometry:
|
|
30
|
+
"""Physical dimensions of the robot.
|
|
31
|
+
|
|
32
|
+
Sb: base equilateral triangle side
|
|
33
|
+
Sp: platform equilateral triangle side
|
|
34
|
+
L: upper arm length
|
|
35
|
+
l: lower arm (parallelogram) length
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
Sb: float
|
|
39
|
+
Sp: float
|
|
40
|
+
L: float
|
|
41
|
+
l: float
|
|
42
|
+
|
|
43
|
+
def __post_init__(self) -> None:
|
|
44
|
+
for name in ("Sb", "Sp", "L", "l"):
|
|
45
|
+
value = getattr(self, name)
|
|
46
|
+
if not math.isfinite(value) or value <= 0:
|
|
47
|
+
raise ValueError(f"{name} must be a positive finite number, got {value!r}")
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def Wb(self) -> float:
|
|
51
|
+
"""Planar distance from the base centre to the nearest base side."""
|
|
52
|
+
return _SQRT3 / 6.0 * self.Sb
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def Ub(self) -> float:
|
|
56
|
+
"""Planar distance from the base centre to a base vertex."""
|
|
57
|
+
return _SQRT3 / 3.0 * self.Sb
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def Wp(self) -> float:
|
|
61
|
+
"""Planar distance from the platform centre to the nearest platform side."""
|
|
62
|
+
return _SQRT3 / 6.0 * self.Sp
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def Up(self) -> float:
|
|
66
|
+
"""Planar distance from the platform centre to a platform vertex."""
|
|
67
|
+
return _SQRT3 / 3.0 * self.Sp
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _wrap(angle: float) -> float:
|
|
71
|
+
"""Wrap an angle in radians to [-pi, pi)."""
|
|
72
|
+
return (angle + math.pi) % (2.0 * math.pi) - math.pi
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class DeltaRobot:
|
|
76
|
+
"""Forward and inverse kinematics of a Delta robot.
|
|
77
|
+
|
|
78
|
+
>>> robot = DeltaRobot(Sb=567, Sp=76, L=524, l=1244)
|
|
79
|
+
>>> angles = robot.inverse(0, 0, -900) # degrees
|
|
80
|
+
>>> x, y, z = robot.forward(*angles) # back to (0, 0, -900)
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
def __init__(self, Sb: float, Sp: float, L: float, l: float, *, angle_unit: str = "deg") -> None:
|
|
84
|
+
if angle_unit not in _UNITS:
|
|
85
|
+
raise ValueError(f"angle_unit must be one of {_UNITS}, got {angle_unit!r}")
|
|
86
|
+
self.geometry = DeltaGeometry(float(Sb), float(Sp), float(L), float(l))
|
|
87
|
+
self.angle_unit = angle_unit
|
|
88
|
+
|
|
89
|
+
def __repr__(self) -> str:
|
|
90
|
+
g = self.geometry
|
|
91
|
+
return f"DeltaRobot(Sb={g.Sb:g}, Sp={g.Sp:g}, L={g.L:g}, l={g.l:g}, angle_unit={self.angle_unit!r})"
|
|
92
|
+
|
|
93
|
+
# ------------------------------------------------------------------ units
|
|
94
|
+
def _to_rad(self, angle: float) -> float:
|
|
95
|
+
return math.radians(angle) if self.angle_unit == "deg" else float(angle)
|
|
96
|
+
|
|
97
|
+
def _from_rad(self, angle: float) -> float:
|
|
98
|
+
return math.degrees(angle) if self.angle_unit == "deg" else angle
|
|
99
|
+
|
|
100
|
+
# ---------------------------------------------------------------- forward
|
|
101
|
+
def forward(self, theta1: float, theta2: float, theta3: float) -> Vec3:
|
|
102
|
+
"""Platform centre (x, y, z) for the three actuated joint angles.
|
|
103
|
+
|
|
104
|
+
Raises UnreachableError if the three legs cannot be assembled, and
|
|
105
|
+
SingularityError at a singular configuration.
|
|
106
|
+
"""
|
|
107
|
+
g = self.geometry
|
|
108
|
+
t1, t2, t3 = self._to_rad(theta1), self._to_rad(theta2), self._to_rad(theta3)
|
|
109
|
+
Wb, Wp, Up, Sp, L, l = g.Wb, g.Wp, g.Up, g.Sp, g.L, g.l
|
|
110
|
+
|
|
111
|
+
# Centres of the three spheres (elbows shifted by the platform joint offsets).
|
|
112
|
+
y1 = -Wb - L * math.cos(t1) + Up
|
|
113
|
+
z1 = -L * math.sin(t1)
|
|
114
|
+
|
|
115
|
+
x2 = (_SQRT3 / 2.0) * (Wb + L * math.cos(t2)) - Sp / 2.0
|
|
116
|
+
y2 = 0.5 * (Wb + L * math.cos(t2)) - Wp
|
|
117
|
+
z2 = -L * math.sin(t2)
|
|
118
|
+
|
|
119
|
+
x3 = -(_SQRT3 / 2.0) * (Wb + L * math.cos(t3)) + Sp / 2.0
|
|
120
|
+
y3 = 0.5 * (Wb + L * math.cos(t3)) - Wp
|
|
121
|
+
z3 = -L * math.sin(t3)
|
|
122
|
+
|
|
123
|
+
dnm = (y2 - y1) * x3 - (y3 - y1) * x2
|
|
124
|
+
if abs(dnm) < 1e-12 * L * L:
|
|
125
|
+
raise SingularityError("Singular configuration (the three sphere centres are aligned).")
|
|
126
|
+
|
|
127
|
+
w1 = y1 * y1 + z1 * z1
|
|
128
|
+
w2 = x2 * x2 + y2 * y2 + z2 * z2
|
|
129
|
+
w3 = x3 * x3 + y3 * y3 + z3 * z3
|
|
130
|
+
|
|
131
|
+
# x = (a1 z + b1) / dnm
|
|
132
|
+
a1 = (z2 - z1) * (y3 - y1) - (z3 - z1) * (y2 - y1)
|
|
133
|
+
b1 = -((w2 - w1) * (y3 - y1) - (w3 - w1) * (y2 - y1)) / 2.0
|
|
134
|
+
# y = (a2 z + b2) / dnm
|
|
135
|
+
a2 = -(z2 - z1) * x3 + (z3 - z1) * x2
|
|
136
|
+
b2 = ((w2 - w1) * x3 - (w3 - w1) * x2) / 2.0
|
|
137
|
+
|
|
138
|
+
# a z^2 + b z + c = 0 (sphere of radius l around the first centre)
|
|
139
|
+
a = a1 * a1 + a2 * a2 + dnm * dnm
|
|
140
|
+
b = 2.0 * (a1 * b1 + a2 * (b2 - y1 * dnm) - z1 * dnm * dnm)
|
|
141
|
+
c = (b2 - y1 * dnm) ** 2 + b1 * b1 + dnm * dnm * (z1 * z1 - l * l)
|
|
142
|
+
|
|
143
|
+
disc = b * b - 4.0 * a * c
|
|
144
|
+
if disc < 0:
|
|
145
|
+
if disc > -1e-9 * b * b:
|
|
146
|
+
disc = 0.0
|
|
147
|
+
else:
|
|
148
|
+
raise UnreachableError("These joint angles do not give a valid platform position.")
|
|
149
|
+
|
|
150
|
+
z0 = -0.5 * (b + math.sqrt(disc)) / a
|
|
151
|
+
x0 = (a1 * z0 + b1) / dnm
|
|
152
|
+
y0 = (a2 * z0 + b2) / dnm
|
|
153
|
+
return (x0, y0, z0)
|
|
154
|
+
|
|
155
|
+
# ---------------------------------------------------------------- inverse
|
|
156
|
+
def _inverse_rad(self, x: float, y: float, z: float) -> Tuple[List[float], List[float]]:
|
|
157
|
+
g = self.geometry
|
|
158
|
+
L, l = g.L, g.l
|
|
159
|
+
a = g.Wb - g.Up
|
|
160
|
+
b = g.Sp / 2.0 - (_SQRT3 / 2.0) * g.Wb
|
|
161
|
+
c = g.Wp - g.Wb / 2.0
|
|
162
|
+
|
|
163
|
+
r2 = x * x + y * y + z * z
|
|
164
|
+
E = (
|
|
165
|
+
2.0 * L * (y + a),
|
|
166
|
+
-L * (_SQRT3 * (x + b) + y + c),
|
|
167
|
+
L * (_SQRT3 * (x - b) - y - c),
|
|
168
|
+
)
|
|
169
|
+
F = (2.0 * z * L,) * 3
|
|
170
|
+
G = (
|
|
171
|
+
r2 + a * a + L * L + 2.0 * y * a - l * l,
|
|
172
|
+
r2 + b * b + c * c + L * L + 2.0 * (x * b + y * c) - l * l,
|
|
173
|
+
r2 + b * b + c * c + L * L - 2.0 * (x * b - y * c) - l * l,
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
primary: List[float] = []
|
|
177
|
+
alternate: List[float] = []
|
|
178
|
+
for i in range(3):
|
|
179
|
+
disc = E[i] ** 2 + F[i] ** 2 - G[i] ** 2
|
|
180
|
+
if disc < 0:
|
|
181
|
+
if disc > -1e-9 * (E[i] ** 2 + F[i] ** 2 + G[i] ** 2 + 1.0):
|
|
182
|
+
disc = 0.0
|
|
183
|
+
else:
|
|
184
|
+
raise UnreachableError(
|
|
185
|
+
f"Position ({x:g}, {y:g}, {z:g}) is outside the workspace "
|
|
186
|
+
f"(leg {i + 1} cannot reach it)."
|
|
187
|
+
)
|
|
188
|
+
root = math.sqrt(disc)
|
|
189
|
+
den = G[i] - E[i]
|
|
190
|
+
# atan2 keeps this well defined even when den == 0.
|
|
191
|
+
primary.append(_wrap(2.0 * math.atan2(-F[i] - root, den)))
|
|
192
|
+
alternate.append(_wrap(2.0 * math.atan2(-F[i] + root, den)))
|
|
193
|
+
return primary, alternate
|
|
194
|
+
|
|
195
|
+
def inverse_all(self, x: float, y: float, z: float) -> Tuple[Vec3, Vec3]:
|
|
196
|
+
"""Both joint-angle solutions: (primary, alternate)."""
|
|
197
|
+
p, a = self._inverse_rad(x, y, z)
|
|
198
|
+
return (
|
|
199
|
+
tuple(self._from_rad(t) for t in p), # type: ignore[return-value]
|
|
200
|
+
tuple(self._from_rad(t) for t in a), # type: ignore[return-value]
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
def inverse(self, x: float, y: float, z: float, branch: str = "primary") -> Vec3:
|
|
204
|
+
"""Joint angles (theta1, theta2, theta3) for a platform position.
|
|
205
|
+
|
|
206
|
+
branch="primary" is the usual elbow-out configuration (about -20.5
|
|
207
|
+
degrees at (0, 0, -900) for the example geometry); "alternate" is the
|
|
208
|
+
other mathematical solution.
|
|
209
|
+
|
|
210
|
+
Raises UnreachableError if the position is outside the workspace.
|
|
211
|
+
"""
|
|
212
|
+
if branch not in _BRANCHES:
|
|
213
|
+
raise ValueError(f"branch must be one of {_BRANCHES}, got {branch!r}")
|
|
214
|
+
primary, alternate = self.inverse_all(x, y, z)
|
|
215
|
+
return primary if branch == "primary" else alternate
|
|
216
|
+
|
|
217
|
+
# ------------------------------------------------------------------ extras
|
|
218
|
+
def is_reachable(self, x: float, y: float, z: float) -> bool:
|
|
219
|
+
"""True if the platform centre can be placed at (x, y, z)."""
|
|
220
|
+
try:
|
|
221
|
+
self._inverse_rad(x, y, z)
|
|
222
|
+
except UnreachableError:
|
|
223
|
+
return False
|
|
224
|
+
return True
|
|
225
|
+
|
|
226
|
+
def forward_many(self, angles: Iterable[Sequence[float]]) -> List[Vec3]:
|
|
227
|
+
"""forward() for many (theta1, theta2, theta3) triples."""
|
|
228
|
+
return [self.forward(*t) for t in angles]
|
|
229
|
+
|
|
230
|
+
def inverse_many(self, points: Iterable[Sequence[float]], branch: str = "primary") -> List[Vec3]:
|
|
231
|
+
"""inverse() for many (x, y, z) points."""
|
|
232
|
+
return [self.inverse(*p, branch=branch) for p in points]
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: deltakin
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Forward and inverse kinematics for 3-DOF Delta parallel robots.
|
|
5
|
+
Author-email: Salim Toumache <salimtoumache@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: delta robot,parallel robot,kinematics,robotics,mechatronics
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Science/Research
|
|
10
|
+
Classifier: Intended Audience :: Education
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering
|
|
14
|
+
Requires-Python: >=3.8
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# deltakin
|
|
20
|
+
|
|
21
|
+
Forward and inverse kinematics for 3-DOF Delta parallel robots, in pure Python (no dependencies).
|
|
22
|
+
|
|
23
|
+
Equations follow R. L. Williams II, *The Delta Parallel Robot: Kinematics Solutions* (Ohio University).
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install . # from this folder
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from deltakin import DeltaRobot, UnreachableError
|
|
35
|
+
|
|
36
|
+
robot = DeltaRobot(Sb=567, Sp=76, L=524, l=1244) # lengths in mm
|
|
37
|
+
|
|
38
|
+
angles = robot.inverse(0, 0, -900) # degrees -> about (-20.55, -20.55, -20.55)
|
|
39
|
+
x, y, z = robot.forward(*angles) # -> (0, 0, -900)
|
|
40
|
+
|
|
41
|
+
robot.is_reachable(0, 0, 0) # False
|
|
42
|
+
|
|
43
|
+
try:
|
|
44
|
+
robot.inverse(0, 0, 0)
|
|
45
|
+
except UnreachableError as err:
|
|
46
|
+
print(err) # clear error, no fake angles
|
|
47
|
+
|
|
48
|
+
primary, alternate = robot.inverse_all(100, -50, -1000) # both solutions
|
|
49
|
+
robot.inverse_many([(0, 0, -900), (50, 20, -1000)]) # batches
|
|
50
|
+
DeltaRobot(567, 76, 524, 1244, angle_unit="rad") # radians instead of degrees
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Conventions
|
|
54
|
+
|
|
55
|
+
- Origin at the centre of the base, z up (a hanging platform has negative z).
|
|
56
|
+
- Leg 1 on the -y side; legs 2 and 3 on the +x and -x sides.
|
|
57
|
+
- Lengths use any single unit; angles default to degrees.
|
|
58
|
+
- `inverse(..., branch="primary")` returns the usual elbow-out solution; `"alternate"` returns the other one.
|
|
59
|
+
|
|
60
|
+
## Tests
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
PYTHONPATH=src python -m unittest discover -s tests -v
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The test suite includes round trips (inverse then forward, and forward then inverse), the example from the Williams paper, and a mirror-symmetry check.
|
|
67
|
+
|
|
68
|
+
## Author
|
|
69
|
+
|
|
70
|
+
Salim Toumache, mechatronics engineer: <salimtoumache@gmail.com>
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
MIT
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
deltakin/__init__.py,sha256=QS28eNDRlYvNBU6JzTTiQOpMfcT5MnXLDA_tBFBpm8A,422
|
|
2
|
+
deltakin/errors.py,sha256=ytTp_mLKfjzbzVfc58i_hUQaib2tE-ULNHYgtSbCbNA,401
|
|
3
|
+
deltakin/robot.py,sha256=RrOf8L-zC_koxeXuty9ptEhsCjY2_KSWbOpCzdXFxr8,8804
|
|
4
|
+
deltakin-0.1.0.dist-info/licenses/LICENSE,sha256=8gDrDAG3UZxSNLMzQIcQDm60FML92hx3Kdtz_kXaSF4,1097
|
|
5
|
+
deltakin-0.1.0.dist-info/METADATA,sha256=wNcRuDqXGCGWgpsAmlpin3ynWhLgUVbdmXxgGF6a4qE,2412
|
|
6
|
+
deltakin-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
7
|
+
deltakin-0.1.0.dist-info/top_level.txt,sha256=GzD1VvvHtvX2iv25BuCDJ8mgz78-kGC61g4JpkJTC3I,9
|
|
8
|
+
deltakin-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Salim Toumache <salimtoumache@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
deltakin
|