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.
Files changed (37) hide show
  1. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/PKG-INFO +18 -9
  2. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/README.md +13 -4
  3. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/pyproject.toml +5 -5
  4. rational-linkages-1.3.1/python/rational_linkages/CollisionFreeOptimization.py +271 -0
  5. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/DualQuaternion.py +56 -31
  6. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/ExudynAnalysis.py +12 -4
  7. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/FactorizationProvider.py +27 -22
  8. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/Linkage.py +5 -1
  9. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/MotionFactorization.py +38 -3
  10. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/MotionInterpolation.py +24 -9
  11. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/NormalizedLine.py +18 -9
  12. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/Plotter.py +51 -29
  13. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/PointHomogeneous.py +6 -1
  14. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/Quaternion.py +6 -1
  15. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/RationalMechanism.py +112 -14
  16. rational-linkages-1.3.1/python/rational_linkages/SingularityAnalysis.py +57 -0
  17. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/TransfMatrix.py +16 -9
  18. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/__init__.py +1 -0
  19. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages.egg-info/PKG-INFO +18 -9
  20. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages.egg-info/SOURCES.txt +2 -0
  21. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages.egg-info/requires.txt +3 -3
  22. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/LICENSE +0 -0
  23. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/AffineMatrix.py +0 -0
  24. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/AffineMetric.py +0 -0
  25. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/ButtonID.py +0 -0
  26. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/DualQuaternionAction.py +0 -0
  27. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/MiniBall.py +0 -0
  28. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/MotionApproximation.py +0 -0
  29. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/RationalBezier.py +0 -0
  30. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/RationalCurve.py +0 -0
  31. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/RationalDualQuaternion.py +0 -0
  32. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/data/bennett_ark24.pkl +0 -0
  33. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/data/collisions_free_6r.pkl +0 -0
  34. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages/models.py +0 -0
  35. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages.egg-info/dependency_links.txt +0 -0
  36. {rational-linkages-1.2.dev4 → rational-linkages-1.3.1}/python/rational_linkages.egg-info/top_level.txt +0 -0
  37. {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.2.dev4
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://git.uibk.ac.at/geometrie-vermessung/rational-linkages/-/issues
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.7.0
691
- Requires-Dist: sympy>=1.8.0
692
- Requires-Dist: matplotlib>=3.4.0
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
  [![build](https://git.uibk.ac.at/geometrie-vermessung/rational-linkages/badges/main/pipeline.svg)](https://git.uibk.ac.at/geometrie-vermessung/rational-linkages/-/jobs)
712
- [![coverage](https://git.uibk.ac.at/geometrie-vermessung/rational-linkages/badges/main/coverage.svg?job=run_tests)](https://git.uibk.ac.at/geometrie-vermessung/rational-linkages/-/jobs)
713
712
  [![Documentation Status](https://readthedocs.org/projects/rational-linkages/badge/?version=latest)](https://rational-linkages.readthedocs.io/?badge=latest)
714
- [![Python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue.svg)]()
715
713
  [![PyPI version](https://badge.fury.io/py/rational-linkages.svg)](https://pypi.org/project/rational-linkages/)
714
+ [![coverage](https://git.uibk.ac.at/geometrie-vermessung/rational-linkages/badges/main/coverage.svg?job=run_tests)](https://git.uibk.ac.at/geometrie-vermessung/rational-linkages/-/jobs)
715
+ [![GitHub issues](https://img.shields.io/github/issues/hucik14/rl-issues)](https://github.com/hucik14/rl-issues/issues)
716
+ [![Python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue.svg)]()
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
- ## Usage
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
- See the [documentation examples](https://rational-linkages.readthedocs.io/) for more details.
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
  [![build](https://git.uibk.ac.at/geometrie-vermessung/rational-linkages/badges/main/pipeline.svg)](https://git.uibk.ac.at/geometrie-vermessung/rational-linkages/-/jobs)
2
- [![coverage](https://git.uibk.ac.at/geometrie-vermessung/rational-linkages/badges/main/coverage.svg?job=run_tests)](https://git.uibk.ac.at/geometrie-vermessung/rational-linkages/-/jobs)
3
2
  [![Documentation Status](https://readthedocs.org/projects/rational-linkages/badge/?version=latest)](https://rational-linkages.readthedocs.io/?badge=latest)
4
- [![Python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue.svg)]()
5
3
  [![PyPI version](https://badge.fury.io/py/rational-linkages.svg)](https://pypi.org/project/rational-linkages/)
4
+ [![coverage](https://git.uibk.ac.at/geometrie-vermessung/rational-linkages/badges/main/coverage.svg?job=run_tests)](https://git.uibk.ac.at/geometrie-vermessung/rational-linkages/-/jobs)
5
+ [![GitHub issues](https://img.shields.io/github/issues/hucik14/rl-issues)](https://github.com/hucik14/rl-issues/issues)
6
+ [![Python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue.svg)]()
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
- ## Usage
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
- See the [documentation examples](https://rational-linkages.readthedocs.io/) for more details.
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.2.dev4"
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.7.0",
23
- "sympy >= 1.8.0",
24
- "matplotlib >= 3.4.0",
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://git.uibk.ac.at/geometrie-vermessung/rational-linkages/-/issues"
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
@@ -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 bq.BiQuaternion biquaternion: biquaternion
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 biquaternion_py.BiQuaternion object
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 biquaternion_py.BiQuaternion object"
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 bq.Poly poly: biquaternion polynomial
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 object
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 object from"
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
- return f"{self.p.array()} + eps{self.d.array()}"
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 dq2line(self) -> tuple:
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 do not
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
- # if the DQ is a sympy Expression, do not convert to float and do not normalize
542
- if any(isinstance(x, Expr) for x in self.array()):
549
+ dq = self.array()
550
+ if any(isinstance(x, Expr) for x in dq):
543
551
  try:
544
- dq = np.asarray(self.array(), dtype="float64")
552
+ dq = np.asarray(dq, dtype="float64")
545
553
  except Exception:
546
- dq = self.array()
547
- else:
548
- dq = np.asarray(self.array(), dtype="float64")
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
- k = dq[0] ** 2 - dq[1] ** 2 - dq[2] ** 2 - dq[3] ** 2 # Different from Study
551
- f = k - dq[0] ** 2
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
- dir = f * dq[1:4]
555
- mom = np.array([g * dq[1] - f * dq[5],
556
- g * dq[2] - f * dq[6],
557
- g * dq[3] - f * dq[7]])
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.dq2line()
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.dq2line()
611
+ direction, moment = self.dq2line_vectors()
587
612
  return np.cross(direction, moment)
588
613
 
589
614
  def act(
@@ -19,7 +19,10 @@ class ExudynAnalysis:
19
19
  """
20
20
  self.gravity = gravity
21
21
 
22
- def get_exudyn_params(self, mechanism: RationalMechanism) -> tuple:
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 = [[l, 0.06, 0.06] for l in links_lengths] # TODO width
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.dq2line()
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.dq2line()
147
+ direction, moment = axis.dq2line_vectors()
140
148
  axes_branch2.append(direction)
141
149
 
142
150
  return axes + axes_branch2[::-1]