/
robomath.py
2028 lines (1633 loc) · 76.7 KB
/
robomath.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2015-2024 - RoboDK Inc. - https://robodk.com/
# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# --------------------------------------------
# --------------- DESCRIPTION ----------------
"""This is a robotics toolbox to facilitate operations with the RoboDK API
and matrix (pose) operations. This toolbox includes a simple matrix class
for pose transformations (Mat class).
This toolbox has been inspired from Peter Corke's Robotics Toolbox:
http://petercorke.com/wordpress/toolboxes/robotics-toolbox
In this module:
pose = transformation matrix = homogeneous matrix = 4x4 matrix = Mat class
More information about the RoboDK API for Python here:
https://robodk.com/doc/en/RoboDK-API.html
https://robodk.com/doc/en/PythonAPI/robodk.html#robomath-py
https://robodk.com/doc/en/Add-ins.html
"""
# --------------------------------------------
import sys
import math
import time
if sys.version_info.major >= 3 and sys.version_info.minor >= 5:
# Python 3.5+ type hints. Type hints are stripped for <3.5
from typing import List, Union, Tuple
#----------------------------------------------------
#-------- Generic math usage ---------------
pi: float = math.pi #: PI
def pause(seconds: float):
"""
Pause the execution for a specified duration.
:param seconds: time in seconds
:type seconds: float
"""
time.sleep(seconds)
def sqrt(value: float) -> float:
"""
Computes the square root of a given value.
:param value: Value to find the square root of.
:type value: float
:return: Square root of the input value.
:rtype: float
"""
return math.sqrt(value)
def sqrtA(value: float) -> float:
"""
Computes the square root of a value if it's positive; returns 0 for non-positive values (differs from IEEE-754).
:param value: Value to compute the square root of.
:type value: float
:return: Square root of the input value if positive, otherwise 0.
:rtype: float
"""
if value <= 0:
return 0
return sqrt(value)
def sin(value: float) -> float:
"""
Calculates the sine of an angle given in radians.
:param value: Angle in radians.
:type value: float
:return: Sine of the angle.
:rtype: float
"""
return math.sin(value)
def cos(value: float) -> float:
"""
Calculates the cosine of an angle given in radians.
:param value: Angle in radians.
:type value: float
:return: Cosine of the angle.
:rtype: float
"""
return math.cos(value)
def tan(value: float) -> float:
"""
Calculates the tangent of an angle given in radians.
:param value: Angle in radians.
:type value: float
:return: Tangent of the angle.
:rtype: float
"""
return math.tan(value)
def asin(value: float) -> float:
"""
Calculates the arc sine of a value, result in radians.
:param value: Value to compute the arc sine for.
:type value: float
:return: Arc sine of the input value in radians.
:rtype: float
"""
return math.asin(value)
def acos(value: float) -> float:
"""
Calculates the arc cosine of a value, result in radians.
:param value: Value to compute the arc cosine for.
:type value: float
:return: Arc cosine of the input value in radians.
:rtype: float
"""
return math.acos(value)
def atan2(y: float, x: float) -> float:
"""
Calculates the angle of a point from the origin in the XY plane.
:param y: Y-coordinate of the point.
:type y: float
:param x: X-coordinate of the point.
:type x: float
:return: Angle of the point in radians.
:rtype: float
"""
return math.atan2(y, x)
def name_2_id(str_name_id: str) -> float:
"""
Extracts the numerical ID from a string containing a named object.
For example: "Frame 3", "Frame3", "Fram3 3" returns 3."
:param str_name_id: String containing the named object and its ID.
:type str_name_id: str
:return: Numerical ID found in the string, or -1 if none found.
:rtype: float
"""
import re
numbers = re.findall(r'[0-9]+', str_name_id)
if len(numbers) > 0:
return float(numbers[-1])
return -1
#----------------------------------------------------
#-------- Generic matrix usage ---------------
def rotx(rx: float) -> 'Mat':
r"""Returns a rotation matrix around the X axis (radians)
.. math::
R_x(\theta) = \begin{bmatrix} 1 & 0 & 0 & 0 \\
0 & c_\theta & -s_\theta & 0 \\
0 & s_\theta & c_\theta & 0 \\
0 & 0 & 0 & 1
\end{bmatrix}
:param rx: rotation around X axis in radians
:type rx: float
:rtype: :class:`.Mat`
.. seealso:: :func:`~robodk.robomath.transl`, :func:`~robodk.robomath.roty`, :func:`~robodk.robomath.rotz`
"""
ct = math.cos(rx)
st = math.sin(rx)
return Mat([
[1, 0, 0, 0],
[0, ct, -st, 0],
[0, st, ct, 0],
[0, 0, 0, 1],
])
def roty(ry: float) -> 'Mat':
r"""Returns a rotation matrix around the Y axis (radians)
.. math::
R_y(\theta) = \begin{bmatrix} c_\theta & 0 & s_\theta & 0 \\
0 & 1 & 0 & 0 \\
-s_\theta & 0 & c_\theta & 0 \\
0 & 0 & 0 & 1
\end{bmatrix}
:param ry: rotation around Y axis in radians
:type ry: float
:rtype: :class:`.Mat`
.. seealso:: :func:`~robodk.robomath.transl`, :func:`~robodk.robomath.rotx`, :func:`~robodk.robomath.rotz`
"""
ct = math.cos(ry)
st = math.sin(ry)
return Mat([
[ct, 0, st, 0],
[0, 1, 0, 0],
[-st, 0, ct, 0],
[0, 0, 0, 1],
])
def rotz(rz: float) -> 'Mat':
r"""Returns a rotation matrix around the Z axis (radians)
.. math::
R_x(\theta) = \begin{bmatrix} c_\theta & -s_\theta & 0 & 0 \\
s_\theta & c_\theta & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1
\end{bmatrix}
:param rz: rotation around Z axis in radians
:type rz: float
:rtype: :class:`.Mat`
.. seealso:: :func:`~robodk.robomath.transl`, :func:`~robodk.robomath.rotx`, :func:`~robodk.robomath.roty`
"""
ct = math.cos(rz)
st = math.sin(rz)
return Mat([
[ct, -st, 0, 0],
[st, ct, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1],
])
def transl(tx: Union[float, List[float]] = 0, ty: float = 0, tz: float = 0) -> 'Mat':
r"""Returns a translation matrix (mm) given translations in each dimension.
Supports passing inputs as a list through the tx argument, but this ignores ty and tz.
.. math::
T(t_x, t_y, t_z) = \begin{bmatrix} 1 & 0 & 0 & t_x \\
0 & 1 & 0 & t_y \\
0 & 0 & 1 & t_z \\
0 & 0 & 0 & 1
\end{bmatrix}
:param tx: translation along the X axis (mm) or list of the supported parameters (i.e. [tx, ty, tz])
:type tx: float or list of float, optional
:param ty: translation along the Y axis (mm), defaults to 0
:type ty: float, optional
:param tz: translation along the Z axis (mm)
:type tz: float, optional
:rtype: :class:`.Mat`
.. seealso:: :func:`~robodk.robomath.rotx`, :func:`~robodk.robomath.roty`, :func:`~robodk.robomath.rotz`
"""
if isinstance(tx, list):
xx = tx[0]
yy = tx[1]
zz = tx[2]
else:
xx = tx
yy = ty
zz = tz
return Mat([
[1, 0, 0, xx],
[0, 1, 0, yy],
[0, 0, 1, zz],
[0, 0, 0, 1],
])
def RelTool(target_pose: 'Mat', x: float, y: float, z: float, rx: float = 0, ry: float = 0, rz: float = 0) -> 'Mat':
"""Calculates a relative target with respect to the tool coordinates. This procedure has exactly the same behavior as ABB's RelTool instruction.
X,Y,Z are in mm, RX,RY,RZ are in degrees.
:param target_pose: Reference pose
:type target_pose: :class:`.Mat`
:param x: translation along the Tool X axis (mm)
:type x: float
:param y: translation along the Tool Y axis (mm)
:type y: float
:param z: translation along the Tool Z axis (mm)
:type z: float
:param rx: rotation around the Tool X axis (deg), optional
:type rx: float
:param ry: rotation around the Tool Y axis (deg), optional
:type ry: float
:param rz: rotation around the Tool Z axis (deg), optional
:type rz: float
:rtype: :class:`.Mat`
.. seealso:: :func:`~robodk.robomath.Offset`, :func:`~robodk.robomath.transl`, :func:`~robodk.robomath.rotx`, :func:`~robodk.robomath.roty`, :func:`~robodk.robomath.rotz`
"""
if type(target_pose) != Mat:
target_pose = target_pose.Pose()
new_target = target_pose * transl(x, y, z) * rotx(rx * pi / 180) * roty(ry * pi / 180) * rotz(rz * pi / 180)
return new_target
def Offset(target_pose: 'Mat', x: float, y: float, z: float, rx: float = 0, ry: float = 0, rz: float = 0) -> 'Mat':
"""Calculates a relative target with respect to the reference frame coordinates.
X,Y,Z are in mm, RX,RY,RZ are in degrees.
:param target_pose: Reference pose
:type target_pose: :class:`.Mat`
:param x: translation along the Reference X axis (mm)
:type x: float
:param y: translation along the Reference Y axis (mm)
:type y: float
:param z: translation along the Reference Z axis (mm)
:type z: float
:param rx: rotation around the Reference X axis (deg), optional
:type rx: float
:param ry: rotation around the Reference Y axis (deg), optional
:type ry: float
:param rz: rotation around the Reference Z axis (deg), optional
:type rz: float
:rtype: :class:`.Mat`
.. seealso:: :func:`~robodk.robomath.RelTool`, :func:`~robodk.robomath.transl`, :func:`~robodk.robomath.rotx`, :func:`~robodk.robomath.roty`, :func:`~robodk.robomath.rotz`
"""
if type(target_pose) != Mat:
# item object assumed:
target_pose = target_pose.Pose()
if not target_pose.isHomogeneous():
raise Exception(MatrixError, "Pose matrix is not homogeneous!")
new_target = transl(x, y, z) * rotx(rx * pi / 180.0) * roty(ry * pi / 180.0) * rotz(rz * pi / 180.0) * target_pose
return new_target
def point_Xaxis_2_pose(point: List[float], xaxis: List[float], zaxis_hint1: List[float] = [0, 0, -1], zaxis_hint2: List[float] = [0, -1, 0]) -> 'Mat':
"""Returns a pose given the origin as a point, a X axis and a preferred orientation for the Z axis"""
pose = eye(4)
pose.setPos(point)
pose.setVX(xaxis)
zaprox = zaxis_hint1
delta = abs(angle3(xaxis, zaprox))
if delta < 0.03 or abs(delta - pi) < 0.03:
zaprox = zaxis_hint2
yaxis = normalize3(cross(zaprox, xaxis))
zaxis = cross(xaxis, yaxis)
pose.setVY(yaxis)
pose.setVZ(zaxis)
return pose
def point_Yaxis_2_pose(point: List[float], yaxis: List[float], zaxis_hint1: List[float] = [0, 0, -1], zaxis_hint2: List[float] = [-1, 0, 0]) -> 'Mat':
"""Returns a pose given the origin as a point, a Y axis and a preferred orientation for the Z axis"""
pose = eye(4)
pose.setPos(point)
pose.setVY(yaxis)
zaprox = zaxis_hint1
delta = abs(angle3(yaxis, zaprox))
if delta < 0.03 or abs(delta - pi) < 0.03:
zaprox = zaxis_hint2
xaxis = normalize3(cross(yaxis, zaprox))
zaxis = cross(xaxis, yaxis)
pose.setVX(xaxis)
pose.setVZ(zaxis)
return pose
def point_Zaxis_2_pose(point: List[float], zaxis: List[float], yaxis_hint1: List[float] = [0, 0, 1], yaxis_hint2: List[float] = [0, 1, 1]) -> 'Mat':
"""Returns a pose given the origin as a point, a Z axis and a preferred orientation for the Y axis"""
pose = eye(4)
pose.setPos(point)
pose.setVZ(zaxis)
yaprox = yaxis_hint1
delta = abs(angle3(zaxis, yaprox))
if delta < 0.03 or abs(delta - pi) < 0.03:
yaprox = yaxis_hint2
xaxis = normalize3(cross(yaprox, zaxis))
yaxis = cross(zaxis, xaxis)
pose.setVX(xaxis)
pose.setVY(yaxis)
return pose
def eye(size: int = 4) -> 'Mat':
r"""Returns the identity matrix
.. math::
T(t_x, t_y, t_z) = \begin{bmatrix} 1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1
\end{bmatrix}
:param size: square matrix size (4x4 Identity matrix by default, otherwise it is initialized to 0)
:type size: int
.. seealso:: :func:`~robodk.robomath.transl`, :func:`~robodk.robomath.rotx`, :func:`~robodk.robomath.roty`, :func:`~robodk.robomath.rotz`
"""
if size == 4:
return Mat([
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1],
])
else:
newmat = Mat(size, size)
for i in range(size):
newmat[i, i] = 1
return newmat
def size(matrix: 'Mat', dim: int = None) -> Union[Tuple[int, int], int]:
"""Returns the size of a matrix (m,n).
Dim can be set to 0 to return m (rows) or 1 to return n (columns)
:param matrix: pose
:type matrix: :class:`.Mat`
:param dim: dimension
:type dim: int
"""
return matrix.size(dim)
def tr(matrix: 'Mat') -> 'Mat':
"""Returns the transpose of the matrix
:param matrix: pose
:type matrix: :class:`.Mat`"""
return matrix.tr()
def invH(matrix: 'Mat') -> 'Mat':
"""Returns the inverse of a homogeneous matrix
:param matrix: pose
:type matrix: :class:`.Mat`
.. seealso:: :func:`~robodk.robomath.transl`, :func:`~robodk.robomath.rotx`, :func:`~robodk.robomath.roty`, :func:`~robodk.robomath.rotz`
"""
return matrix.invH()
def catV(mat1: 'Mat', mat2: 'Mat') -> 'Mat':
"""Concatenate 2 matrices (vertical concatenation)"""
return mat1.catV(mat2)
def catH(mat1: 'Mat', mat2: 'Mat') -> 'Mat':
"""Concatenate 2 matrices (horizontal concatenation)"""
return mat1.catH(mat2)
def tic():
"""Start a stopwatch timer"""
import time
global TICTOC_START_TIME
TICTOC_START_TIME = time.time()
def toc():
"""Read the stopwatch timer"""
import time
if 'TICTOC_START_TIME' in globals():
elapsed = time.time() - TICTOC_START_TIME
#print("Elapsed time is " + str(elapsed) + " seconds.")
return elapsed
else:
print("Toc: start time not set")
return -1
#----------------------------------------------------
#------ Pose to xyzrpw and xyzrpw to pose------------
def PosePP(x: float, y: float, z: float, r: float, p: float, w: float) -> 'Mat':
"""Create a pose from XYZRPW coordinates. The pose format is the one used by KUKA (XYZABC coordinates). This is function is the same as KUKA_2_Pose (with the difference that the input values are not a list). This function is used as "p" by the intermediate file when generating a robot program.
.. seealso:: :func:`~robodk.robomath.KUKA_2_Pose`, :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Pose_2_Staubli`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`
"""
a = r * math.pi / 180.0
b = p * math.pi / 180.0
c = w * math.pi / 180.0
ca = math.cos(a)
sa = math.sin(a)
cb = math.cos(b)
sb = math.sin(b)
cc = math.cos(c)
sc = math.sin(c)
return Mat([
[cb * ca, ca * sc * sb - cc * sa, sc * sa + cc * ca * sb, x],
[cb * sa, cc * ca + sc * sb * sa, cc * sb * sa - ca * sc, y],
[-sb, cb * sc, cc * cb, z],
[0.0, 0.0, 0.0, 1.0],
])
def pose_2_xyzrpw(H: 'Mat') -> List[float]:
"""Calculates the equivalent position (mm) and Euler angles (deg) as an [x,y,z,r,p,w] array, given a pose.
It returns the values that correspond to the following operation:
transl(x,y,z)*rotz(w*pi/180)*roty(p*pi/180)*rotx(r*pi/180)
:param H: pose
:type H: :class:`.Mat`
:return: [x,y,z,r,p,w] in mm and deg
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Pose_2_Staubli`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`
"""
x = H[0, 3]
y = H[1, 3]
z = H[2, 3]
if (H[2, 0] > (1.0 - 1e-10)):
p = -pi / 2
r = 0
w = math.atan2(-H[1, 2], H[1, 1])
elif H[2, 0] < -1.0 + 1e-10:
p = pi / 2
r = 0
w = math.atan2(H[1, 2], H[1, 1])
else:
p = math.atan2(-H[2, 0], sqrt(H[0, 0] * H[0, 0] + H[1, 0] * H[1, 0]))
w = math.atan2(H[1, 0], H[0, 0])
r = math.atan2(H[2, 1], H[2, 2])
return [x, y, z, r * 180 / pi, p * 180 / pi, w * 180 / pi]
def xyzrpw_2_pose(xyzrpw: List[float]) -> 'Mat':
"""Calculates the pose from the position (mm) and Euler angles (deg), given a [x,y,z,r,p,w] array.
The result is the same as calling: H = transl(x,y,z)*rotz(w*pi/180)*roty(p*pi/180)*rotx(r*pi/180)
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Pose_2_Staubli`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`
"""
[x, y, z, r, p, w] = xyzrpw
a = r * pi / 180
b = p * pi / 180
c = w * pi / 180
ca = math.cos(a)
sa = math.sin(a)
cb = math.cos(b)
sb = math.sin(b)
cc = math.cos(c)
sc = math.sin(c)
H = Mat([
[cb * cc, cc * sa * sb - ca * sc, sa * sc + ca * cc * sb, x],
[cb * sc, ca * cc + sa * sb * sc, ca * sb * sc - cc * sa, y],
[-sb, cb * sa, ca * cb, z],
[0, 0, 0, 1],
])
return H
def Pose(x: float, y: float, z: float, rxd: float, ryd: float, rzd: float) -> 'Mat':
"""Returns the pose (:class:`.Mat`) given the position (mm) and Euler angles (deg) as an array [x,y,z,rx,ry,rz].
The result is the same as calling: H = transl(x,y,z)*rotx(rx*pi/180)*roty(ry*pi/180)*rotz(rz*pi/180)
This pose format is printed for homogeneous poses automatically. This Pose is the same representation used by Mecademic or Staubli robot controllers.
:param tx: position (X coordinate)
:type tx: float
:param ty: position (Y coordinate)
:type ty: float
:param tz: position (Z coordinate)
:type tz: float
:param rxd: first rotation in deg (X coordinate)
:type rxd: float
:param ryd: first rotation in deg (Y coordinate)
:type ryd: float
:param rzd: first rotation in deg (Z coordinate)
:type rzd: float
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`
"""
rx = rxd * pi / 180
ry = ryd * pi / 180
rz = rzd * pi / 180
srx = math.sin(rx)
crx = math.cos(rx)
sry = math.sin(ry)
cry = math.cos(ry)
srz = math.sin(rz)
crz = math.cos(rz)
return Mat([
[cry * crz, -cry * srz, sry, x],
[crx * srz + crz * srx * sry, crx * crz - srx * sry * srz, -cry * srx, y],
[srx * srz - crx * crz * sry, crz * srx + crx * sry * srz, crx * cry, z],
[0, 0, 0, 1],
])
def TxyzRxyz_2_Pose(xyzrpw: List[float]) -> 'Mat':
"""Returns the pose given the position (mm) and Euler angles (rad) as an array [x,y,z,rx,ry,rz].
The result is the same as calling: H = transl(x,y,z)*rotx(rx)*roty(ry)*rotz(rz)
:param xyzrpw: [x,y,z,rx,ry,rz] in mm and radians
:type xyzrpw: list of float
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Pose_2_Staubli`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`
"""
[x, y, z, rx, ry, rz] = xyzrpw
srx = math.sin(rx)
crx = math.cos(rx)
sry = math.sin(ry)
cry = math.cos(ry)
srz = math.sin(rz)
crz = math.cos(rz)
H = Mat([
[cry * crz, -cry * srz, sry, x],
[crx * srz + crz * srx * sry, crx * crz - srx * sry * srz, -cry * srx, y],
[srx * srz - crx * crz * sry, crz * srx + crx * sry * srz, crx * cry, z],
[0, 0, 0, 1],
])
return H
def Pose_2_TxyzRxyz(H: 'Mat') -> List[float]:
"""Retrieve the position (mm) and Euler angles (rad) as an array [x,y,z,rx,ry,rz] given a pose.
It returns the values that correspond to the following operation:
H = transl(x,y,z)*rotx(rx)*roty(ry)*rotz(rz).
:param H: pose
:type H: :class:`.Mat`
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Pose_2_Staubli`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`
"""
x = H[0, 3]
y = H[1, 3]
z = H[2, 3]
a = H[0, 0]
b = H[0, 1]
c = H[0, 2]
d = H[1, 2]
e = H[2, 2]
if c > (1.0 - 1e-10):
ry1 = pi / 2
rx1 = 0
rz1 = atan2(H[1, 0], H[1, 1])
elif c < (-1.0 + 1e-10):
ry1 = -pi / 2
rx1 = 0
rz1 = atan2(H[1, 0], H[1, 1])
else:
sy = c
cy1 = +sqrt(1 - sy * sy)
sx1 = -d / cy1
cx1 = e / cy1
sz1 = -b / cy1
cz1 = a / cy1
rx1 = atan2(sx1, cx1)
ry1 = atan2(sy, cy1)
rz1 = atan2(sz1, cz1)
return [x, y, z, rx1, ry1, rz1]
def Pose_2_Staubli(H: 'Mat') -> List[float]:
"""Converts a pose (4x4 matrix) to a Staubli XYZWPR target
:param H: pose
:type H: :class:`.Mat`
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Staubli_2_Pose`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`
"""
xyzwpr = Pose_2_TxyzRxyz(H)
xyzwpr[3] = xyzwpr[3] * 180.0 / pi
xyzwpr[4] = xyzwpr[4] * 180.0 / pi
xyzwpr[5] = xyzwpr[5] * 180.0 / pi
return xyzwpr
def Staubli_2_Pose(xyzwpr: List[float]) -> 'Mat':
"""Converts a Staubli XYZWPR target to a pose (4x4 matrix)
:param H: pose
:type H: :class:`.Mat`
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Pose_2_Staubli`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`
"""
xyzwpr[3] = xyzwpr[3] * pi / 180.0
xyzwpr[4] = xyzwpr[4] * pi / 180.0
xyzwpr[5] = xyzwpr[5] * pi / 180.0
return TxyzRxyz_2_Pose(xyzwpr)
def Pose_2_Motoman(H: 'Mat') -> List[float]:
"""Converts a pose (4x4 matrix) to a Motoman XYZWPR target (mm and deg)
:param H: pose
:type H: :class:`.Mat`
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Pose_2_Staubli`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`
"""
xyzwpr = pose_2_xyzrpw(H)
return xyzwpr
def Pose_2_Fanuc(H: 'Mat') -> List[float]:
"""Converts a pose (4x4 matrix) to a Fanuc XYZWPR target (mm and deg)
:param H: pose
:type H: :class:`.Mat`
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Pose_2_Staubli`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`
"""
xyzwpr = pose_2_xyzrpw(H)
return xyzwpr
def Pose_2_Techman(H: 'Mat') -> List[float]:
"""Converts a pose (4x4 matrix) to a Techman XYZWPR target (mm and deg)
:param H: pose
:type H: :class:`.Mat`
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Pose_2_Staubli`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`
"""
xyzwpr = pose_2_xyzrpw(H)
return xyzwpr
def Motoman_2_Pose(xyzwpr: List[float]) -> 'Mat':
"""Converts a Motoman target to a pose (4x4 matrix)
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Pose_2_Staubli`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`
"""
return xyzrpw_2_pose(xyzwpr)
def Fanuc_2_Pose(xyzwpr: List[float]) -> 'Mat':
"""Converts a Fanuc target to a pose (4x4 matrix)
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Pose_2_Staubli`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`
"""
return xyzrpw_2_pose(xyzwpr)
def Techman_2_Pose(xyzwpr: List[float]) -> 'Mat':
"""Converts a Techman target to a pose (4x4 matrix)
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Pose_2_Staubli`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`
"""
return xyzrpw_2_pose(xyzwpr)
def Pose_2_KUKA(H: 'Mat') -> List[float]:
"""Converts a pose (4x4 matrix) to an XYZABC KUKA target (Euler angles), required by KUKA KRC controllers.
:param H: pose
:type H: :class:`.Mat`
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Pose_2_Staubli`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`
"""
x = H[0, 3]
y = H[1, 3]
z = H[2, 3]
if (H[2, 0]) > (1.0 - 1e-10):
p = -pi / 2
r = 0
w = atan2(-H[1, 2], H[1, 1])
elif (H[2, 0]) < (-1.0 + 1e-10):
p = pi / 2
r = 0
w = atan2(H[1, 2], H[1, 1])
else:
p = atan2(-H[2, 0], sqrt(H[0, 0] * H[0, 0] + H[1, 0] * H[1, 0]))
w = atan2(H[1, 0], H[0, 0])
r = atan2(H[2, 1], H[2, 2])
return [x, y, z, w * 180 / pi, p * 180 / pi, r * 180 / pi]
def KUKA_2_Pose(xyzrpw: List[float]) -> 'Mat':
"""Converts a KUKA XYZABC target to a pose (4x4 matrix), required by KUKA KRC controllers.
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Pose_2_Staubli`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`
"""
[x, y, z, r, p, w] = xyzrpw
a = r * math.pi / 180.0
b = p * math.pi / 180.0
c = w * math.pi / 180.0
ca = math.cos(a)
sa = math.sin(a)
cb = math.cos(b)
sb = math.sin(b)
cc = math.cos(c)
sc = math.sin(c)
return Mat([
[cb * ca, ca * sc * sb - cc * sa, sc * sa + cc * ca * sb, x],
[cb * sa, cc * ca + sc * sb * sa, cc * sb * sa - ca * sc, y],
[-sb, cb * sc, cc * cb, z],
[0.0, 0.0, 0.0, 1.0],
])
def Adept_2_Pose(xyzrpw: List[float]) -> 'Mat':
"""Converts an Adept XYZRPW target to a pose (4x4 matrix)
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Pose_2_Staubli`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`
"""
[x, y, z, r, p, w] = xyzrpw
a = r * math.pi / 180.0
b = p * math.pi / 180.0
c = w * math.pi / 180.0
ca = math.cos(a)
sa = math.sin(a)
cb = math.cos(b)
sb = math.sin(b)
cc = math.cos(c)
sc = math.sin(c)
return Mat([
[ca * cb * cc - sa * sc, -cc * sa - ca * cb * sc, ca * sb, x],
[ca * sc + cb * cc * sa, ca * cc - cb * sa * sc, sa * sb, y],
[-cc * sb, sb * sc, cb, z],
[0.0, 0.0, 0.0, 1.0],
])
def Pose_2_Adept(H: 'Mat') -> List[float]:
"""Converts a pose to an Adept target
:param H: pose
:type H: :class:`.Mat`
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Pose_2_Staubli`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`
"""
x = H[0, 3]
y = H[1, 3]
z = H[2, 3]
if H[2, 2] > (1.0 - 1e-10):
r = 0
p = 0
w = atan2(H[1, 0], H[0, 0])
elif H[2, 2] < (-1.0 + 1e-10):
r = 0
p = pi
w = atan2(H[1, 0], H[1, 1])
else:
cb = H[2, 2]
sb = +sqrt(1 - cb * cb)
sc = H[2, 1] / sb
cc = -H[2, 0] / sb
sa = H[1, 2] / sb
ca = H[0, 2] / sb
r = atan2(sa, ca)
p = atan2(sb, cb)
w = atan2(sc, cc)
return [x, y, z, r * 180 / pi, p * 180 / pi, w * 180 / pi]
def Pose_2_Catia(H: 'Mat') -> List[float]:
"""Converts a pose to Catia or Solidworks format, in mm and deg. It returns the values that correspond to the following operation:
H = transl(x,y,z)*rotz(a)*rotx(b)*rotz(c).
:param H: pose
:type H: :class:`.Mat`
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Pose_2_Staubli`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`
"""
x = H[0, 3]
y = H[1, 3]
z = H[2, 3]
if H[2, 2] > (1.0 - 1e-10):
r = 0
p = 0
w = atan2(H[1, 0], H[0, 0])
elif H[2, 2] < (-1.0 + 1e-10):
r = 0
p = pi
w = atan2(H[1, 0], H[0, 0])
else:
r = atan2(H[0, 2], -H[1, 2])
p = atan2(sqrt(H[0, 2] * H[0, 2] + H[1, 2] * H[1, 2]), H[2, 2])
w = atan2(H[2, 0], H[2, 1])
return [x, y, z, r * 180 / pi, p * 180 / pi, w * 180 / pi]
def Comau_2_Pose(xyzrpw: List[float]) -> 'Mat':
"""Converts a Comau XYZRPW target to a pose (4x4 matrix), the same representation required by PDL Comau programs.
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Pose_2_Staubli`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`
"""
return Adept_2_Pose(xyzrpw)
def Pose_2_Comau(H: 'Mat') -> List[float]:
"""Converts a pose to a Comau target, the same representation required by PDL Comau programs.
:param H: pose
:type H: :class:`.Mat`
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Pose_2_Staubli`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`"""
return Pose_2_Adept(H)
def Pose_2_Nachi(pose: 'Mat') -> List[float]:
"""Converts a pose to a Nachi XYZRPW target
:param pose: pose
:type pose: :class:`.Mat`
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Pose_2_Staubli`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`
"""
[x, y, z, r, p, w] = pose_2_xyzrpw(pose)
return [x, y, z, w, p, r]
def Nachi_2_Pose(xyzwpr: List[float]) -> 'Mat':
"""Converts a Nachi XYZRPW target to a pose (4x4 matrix)
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Pose_2_Staubli`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`
"""
return xyzrpw_2_pose(xyzwpr)
def pose_2_quaternion(Ti: 'Mat') -> List[float]:
"""Returns the quaternion orientation vector of a pose (4x4 matrix)
:param Ti: pose
:type Ti: :class:`.Mat`
.. seealso:: :class:`.Mat`, :func:`~robodk.robomath.TxyzRxyz_2_Pose`, :func:`~robodk.robomath.Pose_2_TxyzRxyz`, :func:`~robodk.robomath.Pose_2_ABB`, :func:`~robodk.robomath.Pose_2_Adept`, :func:`~robodk.robomath.Pose_2_Comau`, :func:`~robodk.robomath.Pose_2_Fanuc`, :func:`~robodk.robomath.Pose_2_KUKA`, :func:`~robodk.robomath.Pose_2_Motoman`, :func:`~robodk.robomath.Pose_2_Nachi`, :func:`~robodk.robomath.Pose_2_Staubli`, :func:`~robodk.robomath.Pose_2_UR`, :func:`~robodk.robomath.quaternion_2_pose`
"""
TOLERANCE_0 = 1e-9
TOLERANCE_180 = 1e-7
cosangle = min(max(((Ti[0, 0] + Ti[1, 1] + Ti[2, 2] - 1.0) * 0.5), -1.0), 1.0) # Calculate the rotation angle
if cosangle > 1.0 - TOLERANCE_0:
# Identity matrix
q1 = 1.0
q2 = 0.0
q3 = 0.0
q4 = 0.0
elif cosangle < -1.0 + TOLERANCE_180:
# 180 rotation around an axis
diag = [Ti[0, 0], Ti[1, 1], Ti[2, 2]]
k = diag.index(max(diag))
col = [Ti[0, k], Ti[1, k], Ti[2, k]]
col[k] = col[k] + 1.0
rotvector = [n / sqrtA(2.0 * (1.0 + diag[k])) for n in col]
q1 = 0.0
q2 = rotvector[0]
q3 = rotvector[1]
q4 = rotvector[2]
else:
# No edge case, normal calculation
a = Ti[0, 0]
b = Ti[1, 1]
c = Ti[2, 2]
sign2 = 1.0
sign3 = 1.0
sign4 = 1.0
if Ti[2, 1] - Ti[1, 2] < 0.0:
sign2 = -1.0
if Ti[0, 2] - Ti[2, 0] < 0.0:
sign3 = -1.0
if Ti[1, 0] - Ti[0, 1] < 0.0:
sign4 = -1.0
q1 = sqrt(max(a + b + c + 1.0, 0.0)) / 2.0
q2 = sign2 * sqrt(max(a - b - c + 1.0, 0.0)) / 2.0
q3 = sign3 * sqrt(max(-a + b - c + 1.0, 0.0)) / 2.0
q4 = sign4 * sqrt(max(-a - b + c + 1.0, 0.0)) / 2.0
return [q1, q2, q3, q4]
def Pose_Split(pose1: 'Mat', pose2: 'Mat', delta_mm: float = 1.0) -> 'Mat':
"""Create a sequence of poses that transitions from pose1 to pose2 by steps of delta_mm in mm (the first and last pose are not included in the list)"""
pose_delta = invH(pose1) * pose2
distance = norm(pose_delta.Pos())
if distance <= delta_mm:
return [pose2]
pose_list = []
x, y, z, w, p, r = Pose_2_UR(pose_delta)
steps = max(1, int(distance / delta_mm))