rational-linkages 1.2.dev4__tar.gz → 1.3.1__tar.gz
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.
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/PKG-INFO +18 -9
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/README.md +13 -4
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/pyproject.toml +5 -5
- rational-linkages-1.3.1/python/rational_linkages/CollisionFreeOptimization.py +271 -0
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/DualQuaternion.py +56 -31
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/ExudynAnalysis.py +12 -4
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/FactorizationProvider.py +27 -22
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/Linkage.py +5 -1
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/MotionFactorization.py +38 -3
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/MotionInterpolation.py +24 -9
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/NormalizedLine.py +18 -9
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/Plotter.py +51 -29
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/PointHomogeneous.py +6 -1
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/Quaternion.py +6 -1
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/RationalMechanism.py +112 -14
- rational-linkages-1.3.1/python/rational_linkages/SingularityAnalysis.py +57 -0
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/TransfMatrix.py +16 -9
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/__init__.py +1 -0
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages.egg-info/PKG-INFO +18 -9
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages.egg-info/SOURCES.txt +2 -0
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages.egg-info/requires.txt +3 -3
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/LICENSE +0 -0
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/AffineMatrix.py +0 -0
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/AffineMetric.py +0 -0
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/ButtonID.py +0 -0
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/DualQuaternionAction.py +0 -0
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/MiniBall.py +0 -0
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/MotionApproximation.py +0 -0
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/RationalBezier.py +0 -0
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/RationalCurve.py +0 -0
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/RationalDualQuaternion.py +0 -0
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/data/bennett_ark24.pkl +0 -0
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/data/collisions_free_6r.pkl +0 -0
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/models.py +0 -0
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages.egg-info/dependency_links.txt +0 -0
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages.egg-info/top_level.txt +0 -0
- {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: rational-linkages
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.1
|
|
4
4
|
Summary: Rational Linkages Toolbox
|
|
5
5
|
Author-email: Daniel Huczala <daniel.huczala@uibk.ac.at>
|
|
6
6
|
License: GNU GENERAL PUBLIC LICENSE
|
|
@@ -680,16 +680,16 @@ License: GNU GENERAL PUBLIC LICENSE
|
|
|
680
680
|
|
|
681
681
|
Project-URL: Homepage, https://git.uibk.ac.at/geometrie-vermessung/rational-linkages
|
|
682
682
|
Project-URL: Documentation, http://rational-linkages.readthedocs.io/
|
|
683
|
-
Project-URL: Issues, https://
|
|
683
|
+
Project-URL: Issues, https://github.com/hucik14/rl-issues/issues
|
|
684
684
|
Classifier: Programming Language :: Python :: 3
|
|
685
685
|
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
|
686
686
|
Classifier: Operating System :: OS Independent
|
|
687
687
|
Requires-Python: >=3.10
|
|
688
688
|
Description-Content-Type: text/markdown
|
|
689
689
|
License-File: LICENSE
|
|
690
|
-
Requires-Dist: scipy>=1.
|
|
691
|
-
Requires-Dist: sympy>=1.
|
|
692
|
-
Requires-Dist: matplotlib>=3.
|
|
690
|
+
Requires-Dist: scipy>=1.10.0
|
|
691
|
+
Requires-Dist: sympy>=1.10.0
|
|
692
|
+
Requires-Dist: matplotlib>=3.7.0
|
|
693
693
|
Requires-Dist: biquaternion-py>=1.2.0
|
|
694
694
|
Requires-Dist: PyQt5>=5.15.10
|
|
695
695
|
Provides-Extra: doc
|
|
@@ -709,10 +709,12 @@ Requires-Dist: isort; extra == "dev"
|
|
|
709
709
|
Requires-Dist: twine; extra == "dev"
|
|
710
710
|
|
|
711
711
|
[](https://git.uibk.ac.at/geometrie-vermessung/rational-linkages/-/jobs)
|
|
712
|
-
[](https://git.uibk.ac.at/geometrie-vermessung/rational-linkages/-/jobs)
|
|
713
712
|
[](https://rational-linkages.readthedocs.io/?badge=latest)
|
|
714
|
-
[]()
|
|
715
713
|
[](https://pypi.org/project/rational-linkages/)
|
|
714
|
+
[](https://git.uibk.ac.at/geometrie-vermessung/rational-linkages/-/jobs)
|
|
715
|
+
[](https://github.com/hucik14/rl-issues/issues)
|
|
716
|
+
[]()
|
|
717
|
+
|
|
716
718
|
|
|
717
719
|
# Rational Linkages
|
|
718
720
|
|
|
@@ -746,10 +748,17 @@ Using pip:
|
|
|
746
748
|
|
|
747
749
|
<code>pip install -e .</code>
|
|
748
750
|
|
|
749
|
-
##
|
|
751
|
+
## Tutorials, issues, usage, and contributions
|
|
752
|
+
|
|
753
|
+
See the [documentation examples](https://rational-linkages.readthedocs.io/latest/general/overview.html)
|
|
754
|
+
for tutorials and usage examples.
|
|
750
755
|
|
|
751
|
-
|
|
756
|
+
Since the self-hosted repository does not allow external users to create issues,
|
|
757
|
+
please, use the [external issue tracker](https://github.com/hucik14/rl-issues)
|
|
758
|
+
hosted on GitHub for submitting **issues** and **feature requests**.
|
|
752
759
|
|
|
760
|
+
In case of other questions or contributions, please, email the author at:
|
|
761
|
+
`daniel.huczala@uibk.ac.at`
|
|
753
762
|
|
|
754
763
|
## Acknowledgements
|
|
755
764
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
[](https://git.uibk.ac.at/geometrie-vermessung/rational-linkages/-/jobs)
|
|
2
|
-
[](https://git.uibk.ac.at/geometrie-vermessung/rational-linkages/-/jobs)
|
|
3
2
|
[](https://rational-linkages.readthedocs.io/?badge=latest)
|
|
4
|
-
[]()
|
|
5
3
|
[](https://pypi.org/project/rational-linkages/)
|
|
4
|
+
[](https://git.uibk.ac.at/geometrie-vermessung/rational-linkages/-/jobs)
|
|
5
|
+
[](https://github.com/hucik14/rl-issues/issues)
|
|
6
|
+
[]()
|
|
7
|
+
|
|
6
8
|
|
|
7
9
|
# Rational Linkages
|
|
8
10
|
|
|
@@ -36,10 +38,17 @@ Using pip:
|
|
|
36
38
|
|
|
37
39
|
<code>pip install -e .</code>
|
|
38
40
|
|
|
39
|
-
##
|
|
41
|
+
## Tutorials, issues, usage, and contributions
|
|
42
|
+
|
|
43
|
+
See the [documentation examples](https://rational-linkages.readthedocs.io/latest/general/overview.html)
|
|
44
|
+
for tutorials and usage examples.
|
|
40
45
|
|
|
41
|
-
|
|
46
|
+
Since the self-hosted repository does not allow external users to create issues,
|
|
47
|
+
please, use the [external issue tracker](https://github.com/hucik14/rl-issues)
|
|
48
|
+
hosted on GitHub for submitting **issues** and **feature requests**.
|
|
42
49
|
|
|
50
|
+
In case of other questions or contributions, please, email the author at:
|
|
51
|
+
`daniel.huczala@uibk.ac.at`
|
|
43
52
|
|
|
44
53
|
## Acknowledgements
|
|
45
54
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "rational-linkages"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.3.1"
|
|
8
8
|
description = "Rational Linkages Toolbox"
|
|
9
9
|
authors = [
|
|
10
10
|
{name = "Daniel Huczala", email = "daniel.huczala@uibk.ac.at"},
|
|
@@ -19,9 +19,9 @@ classifiers = [
|
|
|
19
19
|
]
|
|
20
20
|
|
|
21
21
|
dependencies = [
|
|
22
|
-
"scipy >= 1.
|
|
23
|
-
"sympy >= 1.
|
|
24
|
-
"matplotlib >= 3.
|
|
22
|
+
"scipy >= 1.10.0",
|
|
23
|
+
"sympy >= 1.10.0",
|
|
24
|
+
"matplotlib >= 3.7.0",
|
|
25
25
|
"biquaternion-py >= 1.2.0",
|
|
26
26
|
"PyQt5 >= 5.15.10",
|
|
27
27
|
]
|
|
@@ -55,7 +55,7 @@ include = ["rational_linkages*"]
|
|
|
55
55
|
[project.urls]
|
|
56
56
|
Homepage = "https://git.uibk.ac.at/geometrie-vermessung/rational-linkages"
|
|
57
57
|
Documentation = "http://rational-linkages.readthedocs.io/"
|
|
58
|
-
Issues = "https://
|
|
58
|
+
Issues = "https://github.com/hucik14/rl-issues/issues"
|
|
59
59
|
|
|
60
60
|
[tool.black]
|
|
61
61
|
line-length = 88
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
from .RationalMechanism import RationalMechanism
|
|
2
|
+
from .NormalizedLine import NormalizedLine
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
from itertools import product
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class CollisionFreeOptimization:
|
|
9
|
+
"""
|
|
10
|
+
Class for the optimization of the mechanism for full-cycle collision-free design.
|
|
11
|
+
"""
|
|
12
|
+
def __init__(self, mechanism: RationalMechanism):
|
|
13
|
+
"""
|
|
14
|
+
Initialize the combinatorial search algorithm.
|
|
15
|
+
|
|
16
|
+
:param RationalMechanism mechanism: The mechanism to optimize.
|
|
17
|
+
"""
|
|
18
|
+
self.mechanism = mechanism
|
|
19
|
+
|
|
20
|
+
def smallest_polyline(self) -> tuple:
|
|
21
|
+
"""
|
|
22
|
+
Get points on mechanism axes that form the smallest polyline.
|
|
23
|
+
|
|
24
|
+
This method calculates the smallest polyline that can be formed by points on
|
|
25
|
+
the mechanism axes. It uses scipy's minimize function to find the points on
|
|
26
|
+
the axes that minimize the total distance of the polyline.
|
|
27
|
+
|
|
28
|
+
:return: points on the mechanism axes that form the smallest polyline,
|
|
29
|
+
parameters of the points, result of the optimization
|
|
30
|
+
:rtype: tuple
|
|
31
|
+
"""
|
|
32
|
+
from scipy.optimize import minimize
|
|
33
|
+
|
|
34
|
+
# get the axes represented as normalized lines
|
|
35
|
+
dq_lines = (self.mechanism.factorizations[0].dq_axes
|
|
36
|
+
+ self.mechanism.factorizations[1].dq_axes[::-1])
|
|
37
|
+
lines = [NormalizedLine.from_dual_quaternion(dq_line) for dq_line in dq_lines]
|
|
38
|
+
|
|
39
|
+
def objective_function(x):
|
|
40
|
+
p = [line.point_on_line(x[i]) for i, line in enumerate(lines)]
|
|
41
|
+
|
|
42
|
+
total_distance = sum(
|
|
43
|
+
np.linalg.norm(p[i] - p[i + 1])
|
|
44
|
+
for i in range(self.mechanism.num_joints - 1))
|
|
45
|
+
# Add distance between last and first point
|
|
46
|
+
total_distance += np.linalg.norm(p[-1] - p[0])
|
|
47
|
+
return total_distance
|
|
48
|
+
|
|
49
|
+
x_init = np.zeros(self.mechanism.num_joints)
|
|
50
|
+
result = minimize(objective_function, x_init)
|
|
51
|
+
|
|
52
|
+
# double the parameters for the two joint connection points
|
|
53
|
+
points_params = result.x
|
|
54
|
+
points_params = [np.array([param, param]) for param in points_params]
|
|
55
|
+
|
|
56
|
+
points = [line.point_on_line(float(points_params[i][0]))
|
|
57
|
+
for i, line in enumerate(lines)]
|
|
58
|
+
|
|
59
|
+
return points, points_params, result
|
|
60
|
+
|
|
61
|
+
def optimize(self,
|
|
62
|
+
method: str,
|
|
63
|
+
step_length: float,
|
|
64
|
+
min_joint_segment_length: float,
|
|
65
|
+
max_iters: int):
|
|
66
|
+
"""
|
|
67
|
+
Optimize the mechanism for collision-free operation.
|
|
68
|
+
|
|
69
|
+
:param method: optimization method
|
|
70
|
+
:param step_length: length of the step, i.e. the shift distance value, see
|
|
71
|
+
:ref:`combinatorial_search` for more detail
|
|
72
|
+
:param min_joint_segment_length: minimum length of the joint segment
|
|
73
|
+
:param max_iters: maximum number of iterations
|
|
74
|
+
"""
|
|
75
|
+
# initial estimation - the smallest polyline
|
|
76
|
+
points, points_params, result = self.smallest_polyline()
|
|
77
|
+
|
|
78
|
+
# update the design of the mechanism - set initial design
|
|
79
|
+
self.mechanism.factorizations[0].set_joint_connection_points_by_parameters(
|
|
80
|
+
points_params[:len(self.mechanism.factorizations[0].dq_axes)])
|
|
81
|
+
self.mechanism.factorizations[1].set_joint_connection_points_by_parameters(
|
|
82
|
+
points_params[len(self.mechanism.factorizations[1].dq_axes):][::-1])
|
|
83
|
+
|
|
84
|
+
if method == 'combinatorial_search':
|
|
85
|
+
print("Starting combinatorial search algorithm...")
|
|
86
|
+
cs = CombinatorialSearch(self.mechanism,
|
|
87
|
+
linkage_length=result.fun,
|
|
88
|
+
step_length=step_length,
|
|
89
|
+
min_joint_segment_length=min_joint_segment_length,
|
|
90
|
+
max_iters=max_iters)
|
|
91
|
+
coll_free_points_params = cs.combinatorial_search()
|
|
92
|
+
|
|
93
|
+
return coll_free_points_params
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class CombinatorialSearch:
|
|
97
|
+
"""
|
|
98
|
+
Combinatorial search algorithm of collision-free linkages.
|
|
99
|
+
|
|
100
|
+
Algorithm by :footcite:t:`Li2020`.
|
|
101
|
+
"""
|
|
102
|
+
def __init__(self,
|
|
103
|
+
mechanism: RationalMechanism,
|
|
104
|
+
linkage_length: float,
|
|
105
|
+
step_length: float = 10.0, # TODO step length estimation
|
|
106
|
+
min_joint_segment_length: float = 0.001,
|
|
107
|
+
max_iters: int = 10):
|
|
108
|
+
"""
|
|
109
|
+
Initialize the combinatorial search algorithm.
|
|
110
|
+
|
|
111
|
+
:param RationalMechanism mechanism: The mechanism to optimize.
|
|
112
|
+
:param float linkage_length: length of the linkage
|
|
113
|
+
:param float step_length: length of the step, i.e. the shift distance value, see
|
|
114
|
+
:ref:`combinatorial_search` for more detail
|
|
115
|
+
:param float min_joint_segment_length: minimum length of the joint segment
|
|
116
|
+
:param int max_iters: maximum number of iterations
|
|
117
|
+
"""
|
|
118
|
+
self.mechanism = mechanism
|
|
119
|
+
self.linkage_length = linkage_length
|
|
120
|
+
self.step_length = step_length
|
|
121
|
+
self.min_joint_segment_length = min_joint_segment_length
|
|
122
|
+
self.max_iters = max_iters + 1
|
|
123
|
+
|
|
124
|
+
def combinatorial_search(self):
|
|
125
|
+
"""
|
|
126
|
+
Perform collision-free combinatorial search method.
|
|
127
|
+
|
|
128
|
+
:return: list of collision-free points parameters
|
|
129
|
+
:rtype: list
|
|
130
|
+
"""
|
|
131
|
+
# check design for collisions
|
|
132
|
+
init_collisions = self.mechanism.collision_check(only_links=True,
|
|
133
|
+
terminate_on_first=True)
|
|
134
|
+
|
|
135
|
+
if init_collisions is not None:
|
|
136
|
+
for i in range(1, self.max_iters):
|
|
137
|
+
coll_free_links_params = self.search_links(i)
|
|
138
|
+
|
|
139
|
+
if coll_free_links_params is not None:
|
|
140
|
+
print("")
|
|
141
|
+
print("Collision-free solution for links found, "
|
|
142
|
+
"starting joint search...")
|
|
143
|
+
coll_free_params = self.search_mechanism(coll_free_links_params)
|
|
144
|
+
|
|
145
|
+
if coll_free_params is not None:
|
|
146
|
+
return coll_free_params
|
|
147
|
+
else:
|
|
148
|
+
print("Search was unsuccessful, collisions found.")
|
|
149
|
+
return None
|
|
150
|
+
|
|
151
|
+
def search_links(self, iteration: int):
|
|
152
|
+
"""
|
|
153
|
+
Search for the solution of the combinatorial search algorithm, links only.
|
|
154
|
+
|
|
155
|
+
Searches for the smallest polyline that is collision free (only links).
|
|
156
|
+
|
|
157
|
+
:param iteration: iteration index
|
|
158
|
+
|
|
159
|
+
:return: list of collision-free points parameters
|
|
160
|
+
:rtype: list
|
|
161
|
+
"""
|
|
162
|
+
shift_val = iteration * self.linkage_length / self.step_length
|
|
163
|
+
|
|
164
|
+
combs = self._get_combinations_sequences(joints=False)
|
|
165
|
+
#combs = [(-1, -1, 0, 0, 0, 1),
|
|
166
|
+
# (1, 1, 0, 0, -1, -1),
|
|
167
|
+
# (1, 0, 1, 0, -1, 0),
|
|
168
|
+
# (1, 0, -1, 1, -1, 0)]
|
|
169
|
+
|
|
170
|
+
for i, sequence in enumerate(combs):
|
|
171
|
+
print("--- iteration: {}, shift_value: {}, sequence {} of {}: {}"
|
|
172
|
+
.format(iteration, shift_val, i + 1, len(combs), sequence))
|
|
173
|
+
points_params = shift_val * np.asarray(sequence)
|
|
174
|
+
points_params = [[param] for param in points_params]
|
|
175
|
+
|
|
176
|
+
# update the design of the mechanism
|
|
177
|
+
self.mechanism.factorizations[0].set_joint_connection_points_by_parameters(
|
|
178
|
+
points_params[:len(self.mechanism.factorizations[0].dq_axes)])
|
|
179
|
+
self.mechanism.factorizations[1].set_joint_connection_points_by_parameters(
|
|
180
|
+
points_params[len(self.mechanism.factorizations[1].dq_axes):][::-1])
|
|
181
|
+
|
|
182
|
+
colls = self.mechanism.collision_check(only_links=True,
|
|
183
|
+
terminate_on_first=True)
|
|
184
|
+
|
|
185
|
+
if colls is None:
|
|
186
|
+
return points_params
|
|
187
|
+
|
|
188
|
+
print("No collision-free solution found for iteration: {}".format(iter))
|
|
189
|
+
return None
|
|
190
|
+
|
|
191
|
+
def search_mechanism(self, coll_free_links_params: list):
|
|
192
|
+
"""
|
|
193
|
+
Search for the solution of the combinatorial search algorithm, including joints.
|
|
194
|
+
|
|
195
|
+
Searches for the mechanism that is collision free (including joint segments).
|
|
196
|
+
|
|
197
|
+
:param list coll_free_links_params: list of collision-free points parameters
|
|
198
|
+
|
|
199
|
+
:return: list of collision-free points parameters
|
|
200
|
+
:rtype: list
|
|
201
|
+
"""
|
|
202
|
+
shift_val = 0.5 * self.min_joint_segment_length
|
|
203
|
+
|
|
204
|
+
combs = self._get_combinations_sequences(joints=True)
|
|
205
|
+
|
|
206
|
+
coll_free_links_params = [item * 2 for item in coll_free_links_params]
|
|
207
|
+
|
|
208
|
+
for i, sequence in enumerate(combs):
|
|
209
|
+
print("--- joint search. Shift_value: {}, sequence {} of {}: {}"
|
|
210
|
+
.format(shift_val, i + 1, len(combs), sequence))
|
|
211
|
+
shift_seq = shift_val * np.asarray(sequence)
|
|
212
|
+
|
|
213
|
+
points_params = [[params[0] + shift_seq[ii * 2],
|
|
214
|
+
params[1] + shift_seq[ii * 2 + 1]]
|
|
215
|
+
for ii, params in enumerate(coll_free_links_params)]
|
|
216
|
+
|
|
217
|
+
# update the design of the mechanism
|
|
218
|
+
self.mechanism.factorizations[0].set_joint_connection_points_by_parameters(
|
|
219
|
+
points_params[:len(self.mechanism.factorizations[0].dq_axes)])
|
|
220
|
+
self.mechanism.factorizations[1].set_joint_connection_points_by_parameters(
|
|
221
|
+
points_params[len(self.mechanism.factorizations[1].dq_axes):][::-1])
|
|
222
|
+
|
|
223
|
+
colls = self.mechanism.collision_check(only_links=False,
|
|
224
|
+
terminate_on_first=True)
|
|
225
|
+
|
|
226
|
+
if colls is None:
|
|
227
|
+
return points_params
|
|
228
|
+
|
|
229
|
+
print("No collision-free solution found for iteration: {}".format(iter))
|
|
230
|
+
return None
|
|
231
|
+
|
|
232
|
+
def _get_combinations_sequences(self, joints: bool = False):
|
|
233
|
+
"""
|
|
234
|
+
Get all combinations of the joint angles and shuffle them.
|
|
235
|
+
|
|
236
|
+
:param bool joints: True if joints segments are searched for, False otherwise
|
|
237
|
+
|
|
238
|
+
:return: list of all combinations of joint angles
|
|
239
|
+
:rtype: list
|
|
240
|
+
"""
|
|
241
|
+
if not joints:
|
|
242
|
+
elements = [0, 1, -1]
|
|
243
|
+
combs = list(product(elements, repeat=self.mechanism.num_joints))
|
|
244
|
+
|
|
245
|
+
# remove the combination of all zeros, which was already tested
|
|
246
|
+
if 0 in elements:
|
|
247
|
+
combs.remove((0,) * self.mechanism.num_joints)
|
|
248
|
+
|
|
249
|
+
return combs
|
|
250
|
+
|
|
251
|
+
else:
|
|
252
|
+
elements = [-1, 1]
|
|
253
|
+
combs = list(product(elements, repeat=self.mechanism.num_joints * 2))
|
|
254
|
+
|
|
255
|
+
# filter out the combs that have the same value for the 2 connection pts
|
|
256
|
+
combs = [x for x in combs
|
|
257
|
+
if all(x[i] != x[i + 1] for i in range(0, len(x) - 1, 2))]
|
|
258
|
+
|
|
259
|
+
# place the most promising combs first
|
|
260
|
+
def generate_tuple(n):
|
|
261
|
+
return tuple(-1 if i % 2 == 0 else 1 for i in range(n))
|
|
262
|
+
|
|
263
|
+
tup = generate_tuple(6) + generate_tuple(6)[::-1]
|
|
264
|
+
tup2 = generate_tuple(6)[::-1] + generate_tuple(6)
|
|
265
|
+
|
|
266
|
+
combs.remove(tup)
|
|
267
|
+
combs.insert(0, tup)
|
|
268
|
+
combs.remove(tup2)
|
|
269
|
+
combs.insert(0, tup2)
|
|
270
|
+
|
|
271
|
+
return combs
|
{rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/DualQuaternion.py
RENAMED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
from typing import Optional, Sequence, Union
|
|
2
|
+
from warnings import warn
|
|
2
3
|
|
|
3
4
|
import numpy as np
|
|
4
|
-
from sympy import Expr
|
|
5
|
+
from sympy import Expr, Poly, Symbol, simplify
|
|
5
6
|
|
|
6
7
|
from .Quaternion import Quaternion
|
|
7
8
|
|
|
@@ -104,12 +105,13 @@ class DualQuaternion:
|
|
|
104
105
|
"""
|
|
105
106
|
Construct DualQuaternion from a biquaternion.
|
|
106
107
|
|
|
107
|
-
:param
|
|
108
|
+
:param biquaternion_py.biquaternion.BiQuaternion biquaternion: biquaternion
|
|
108
109
|
|
|
109
110
|
:return: DualQuaternion
|
|
110
111
|
:rtype: DualQuaternion
|
|
111
112
|
|
|
112
|
-
:raises ValueError: if the input is not a
|
|
113
|
+
:raises ValueError: if the input is not a
|
|
114
|
+
biquaternion_py.biquaternion.BiQuaternion object
|
|
113
115
|
|
|
114
116
|
:examples:
|
|
115
117
|
|
|
@@ -134,7 +136,8 @@ class DualQuaternion:
|
|
|
134
136
|
from biquaternion_py import BiQuaternion
|
|
135
137
|
|
|
136
138
|
if not isinstance(biquaternion, BiQuaternion):
|
|
137
|
-
raise ValueError("The input has to be a
|
|
139
|
+
raise ValueError("The input has to be a "
|
|
140
|
+
"biquaternion_py.biquaternion.BiQuaternion object"
|
|
138
141
|
"from biquaternion_py package.")
|
|
139
142
|
|
|
140
143
|
coeffs = biquaternion.coeffs
|
|
@@ -150,13 +153,14 @@ class DualQuaternion:
|
|
|
150
153
|
coefficients of the polynomial are negated and then assembled into a numpy
|
|
151
154
|
array.
|
|
152
155
|
|
|
153
|
-
:param
|
|
156
|
+
:param biquaternion_py.polynomials.Poly poly: biquaternion polynomial
|
|
154
157
|
:param sp.Symbol indet: indeterminant of the polynomial
|
|
155
158
|
|
|
156
159
|
:return: DualQuaternion
|
|
157
160
|
:rtype: DualQuaternion
|
|
158
161
|
|
|
159
|
-
:raises ValueError: if the input is not a biquaternion_py.Poly
|
|
162
|
+
:raises ValueError: if the input is not a biquaternion_py.polynomials.Poly
|
|
163
|
+
object
|
|
160
164
|
:raises ValueError: if the polynomial is not of degree 1
|
|
161
165
|
|
|
162
166
|
:examples:
|
|
@@ -179,8 +183,8 @@ class DualQuaternion:
|
|
|
179
183
|
from biquaternion_py import Poly
|
|
180
184
|
|
|
181
185
|
if not isinstance(poly, Poly):
|
|
182
|
-
raise ValueError("The input has to be a biquaternion_py.Poly
|
|
183
|
-
"biquaternion_py package.")
|
|
186
|
+
raise ValueError("The input has to be a biquaternion_py.polynomials.Poly "
|
|
187
|
+
"object from biquaternion_py package.")
|
|
184
188
|
elif poly.deg(indet) != 1:
|
|
185
189
|
raise ValueError("The polynomial has to be of degree 1.")
|
|
186
190
|
|
|
@@ -242,7 +246,12 @@ class DualQuaternion:
|
|
|
242
246
|
:return: DualQuaterion in readable form
|
|
243
247
|
:rtype: str
|
|
244
248
|
"""
|
|
245
|
-
|
|
249
|
+
dq = np.array2string(self.array(),
|
|
250
|
+
precision=10,
|
|
251
|
+
suppress_small=True,
|
|
252
|
+
separator=', ',
|
|
253
|
+
max_line_width=100000)
|
|
254
|
+
return f"{dq}"
|
|
246
255
|
|
|
247
256
|
def __getitem__(self, idx) -> np.ndarray:
|
|
248
257
|
"""
|
|
@@ -528,39 +537,55 @@ class DualQuaternion:
|
|
|
528
537
|
dq = self.array()
|
|
529
538
|
return np.array([dq[0], dq[5], dq[6], dq[7]])
|
|
530
539
|
|
|
531
|
-
def
|
|
540
|
+
def dq2line_vectors(self) -> tuple:
|
|
532
541
|
"""
|
|
533
542
|
Dual Quaternion directly to line coordinates
|
|
534
543
|
|
|
535
|
-
If the DQ is a sympy Expression, it is not converted to float and
|
|
536
|
-
normalized
|
|
544
|
+
If the DQ is a sympy Expression, it is not converted to float and not normalized
|
|
537
545
|
|
|
538
546
|
:return: tuple of 2 numpy arrays, 3-vector coordinates each
|
|
539
547
|
:rtype: tuple
|
|
540
548
|
"""
|
|
541
|
-
|
|
542
|
-
if any(isinstance(x, Expr) for x in
|
|
549
|
+
dq = self.array()
|
|
550
|
+
if any(isinstance(x, Expr) for x in dq):
|
|
543
551
|
try:
|
|
544
|
-
dq = np.asarray(
|
|
552
|
+
dq = np.asarray(dq, dtype="float64")
|
|
545
553
|
except Exception:
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
554
|
+
pass
|
|
555
|
+
|
|
556
|
+
if any(isinstance(x, Expr) for x in dq):
|
|
557
|
+
dq0_simple = simplify(dq[0])
|
|
558
|
+
dq4_simple = simplify(dq[4])
|
|
559
|
+
|
|
560
|
+
if not (dq0_simple == 0 or not dq4_simple == 0):
|
|
561
|
+
t = Symbol('t')
|
|
562
|
+
coeffs = []
|
|
563
|
+
if not dq0_simple == 0:
|
|
564
|
+
coeffs += Poly(dq0_simple, t).all_coeffs()
|
|
565
|
+
if not dq4_simple == 0:
|
|
566
|
+
coeffs += Poly(dq4_simple, t).all_coeffs()
|
|
549
567
|
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
g = dq[0] * dq[4]
|
|
568
|
+
coeffs = np.array(coeffs, dtype="float64")
|
|
569
|
+
all_close_to_zero = all(np.isclose(coeff, 0) for coeff in coeffs)
|
|
553
570
|
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
571
|
+
if not all_close_to_zero: # warn that the DQ is not a line
|
|
572
|
+
warn("dq2line_vectors method warning: the dual quaternion has NOT "
|
|
573
|
+
"zeros in 1st and 5th element, it is not a line.")
|
|
574
|
+
|
|
575
|
+
direction = dq[1:4]
|
|
576
|
+
moment = -1 * dq[5:8]
|
|
577
|
+
# TODO normalize the direction and moment when sympy expressions are used
|
|
558
578
|
|
|
559
|
-
# if the DQ is a sympy Expression, do not convert to float and do not normalize
|
|
560
|
-
if any(isinstance(x, Expr) for x in dir) or any(isinstance(x, Expr) for x in mom):
|
|
561
|
-
moment = -1 * mom
|
|
562
|
-
direction = -1 * dir
|
|
563
579
|
else:
|
|
580
|
+
k = dq[0] ** 2 - dq[1] ** 2 - dq[2] ** 2 - dq[3] ** 2 # differs from Study
|
|
581
|
+
f = k - dq[0] ** 2
|
|
582
|
+
g = dq[0] * dq[4]
|
|
583
|
+
|
|
584
|
+
dir = f * dq[1:4]
|
|
585
|
+
mom = np.array([g * dq[1] - f * dq[5],
|
|
586
|
+
g * dq[2] - f * dq[6],
|
|
587
|
+
g * dq[3] - f * dq[7]])
|
|
588
|
+
|
|
564
589
|
moment = -1 * mom / np.linalg.norm(dir)
|
|
565
590
|
direction = -1 * dir / np.linalg.norm(dir)
|
|
566
591
|
|
|
@@ -573,7 +598,7 @@ class DualQuaternion:
|
|
|
573
598
|
:return: array of 6-coordinates of screw
|
|
574
599
|
:rtype: np.ndarray
|
|
575
600
|
"""
|
|
576
|
-
direction, moment = self.
|
|
601
|
+
direction, moment = self.dq2line_vectors()
|
|
577
602
|
return np.concatenate((direction, moment))
|
|
578
603
|
|
|
579
604
|
def dq2point_via_line(self) -> np.ndarray:
|
|
@@ -583,7 +608,7 @@ class DualQuaternion:
|
|
|
583
608
|
:return: array of 3-coordinates of point
|
|
584
609
|
:rtype: np.ndarray
|
|
585
610
|
"""
|
|
586
|
-
direction, moment = self.
|
|
611
|
+
direction, moment = self.dq2line_vectors()
|
|
587
612
|
return np.cross(direction, moment)
|
|
588
613
|
|
|
589
614
|
def act(
|
{rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/ExudynAnalysis.py
RENAMED
|
@@ -19,7 +19,10 @@ class ExudynAnalysis:
|
|
|
19
19
|
"""
|
|
20
20
|
self.gravity = gravity
|
|
21
21
|
|
|
22
|
-
def get_exudyn_params(self,
|
|
22
|
+
def get_exudyn_params(self,
|
|
23
|
+
mechanism: RationalMechanism,
|
|
24
|
+
link_radius: float = 0.1,
|
|
25
|
+
scale: float = 1.0) -> tuple:
|
|
23
26
|
"""
|
|
24
27
|
Get parameters for Exudyn simulation.
|
|
25
28
|
|
|
@@ -33,6 +36,8 @@ class ExudynAnalysis:
|
|
|
33
36
|
relative_links_pts (links connection points relative to its center of gravity).
|
|
34
37
|
|
|
35
38
|
:param RationalMechanism mechanism: RationalMechanism object
|
|
39
|
+
:param float link_radius: width of links
|
|
40
|
+
:param float scale: scale length factor for links dimensions
|
|
36
41
|
|
|
37
42
|
:return: links_pts, links_lengths, body_dim, links_masses_pts, joint_axes,
|
|
38
43
|
relative_links_pts
|
|
@@ -41,6 +46,9 @@ class ExudynAnalysis:
|
|
|
41
46
|
# get positions of links connection points
|
|
42
47
|
links_pts = self._links_points(mechanism)
|
|
43
48
|
|
|
49
|
+
if scale != 1.0:
|
|
50
|
+
links_pts = [[scale * pt for pt in pts] for pts in links_pts]
|
|
51
|
+
|
|
44
52
|
# get joint axes
|
|
45
53
|
joint_axes = self._joints_axes(mechanism)
|
|
46
54
|
|
|
@@ -51,7 +59,7 @@ class ExudynAnalysis:
|
|
|
51
59
|
links_masses_pts = self._links_center_of_gravity(links_pts)
|
|
52
60
|
|
|
53
61
|
# body dimensions
|
|
54
|
-
body_dim = [[
|
|
62
|
+
body_dim = [[length, link_radius, link_radius] for length in links_lengths]
|
|
55
63
|
|
|
56
64
|
# relative link points
|
|
57
65
|
relative_links_pts = self._relative_links_points(links_pts, links_masses_pts)
|
|
@@ -131,12 +139,12 @@ class ExudynAnalysis:
|
|
|
131
139
|
"""
|
|
132
140
|
axes = []
|
|
133
141
|
for axis in mechanism.factorizations[0].dq_axes:
|
|
134
|
-
direction, moment = axis.
|
|
142
|
+
direction, moment = axis.dq2line_vectors()
|
|
135
143
|
axes.append(direction)
|
|
136
144
|
|
|
137
145
|
axes_branch2 = []
|
|
138
146
|
for axis in mechanism.factorizations[1].dq_axes:
|
|
139
|
-
direction, moment = axis.
|
|
147
|
+
direction, moment = axis.dq2line_vectors()
|
|
140
148
|
axes_branch2.append(direction)
|
|
141
149
|
|
|
142
150
|
return axes + axes_branch2[::-1]
|