12
12
"""
13
13
14
14
from abc import abstractmethod
15
- import spatialmath .base .argcheck as arg
16
- import spatialmath .base as tr
17
15
import numpy as np
18
16
from spatialmath .smuserlist import SMUserList
17
+ import spatialmath .base as base
19
18
20
19
class SpatialVector (SMUserList ):
21
20
"""
@@ -75,12 +74,14 @@ def __init__(self, value):
75
74
76
75
if value is None :
77
76
self .data = [np .zeros ((6 ,))]
78
- elif arg .isvector (value , 6 ):
77
+ elif base .isvector (value , 6 ):
79
78
self .data = [np .array (value )]
79
+ elif isinstance (value , SpatialVector ):
80
+ self .data = [value .A ]
80
81
elif isinstance (value , list ):
81
- assert all (map (lambda x : arg .isvector (x , 6 ), value )), 'all elements of list must have valid shape and value for the class'
82
+ assert all (map (lambda x : base .isvector (x , 6 ), value )), 'all elements of list must have valid shape and value for the class'
82
83
self .data = [np .array (x ) for x in value ]
83
- elif arg .ismatrix (value , (6 , None )):
84
+ elif base .ismatrix (value , (6 , None )):
84
85
self .data = [x for x in value .T ]
85
86
else :
86
87
raise ValueError ('bad arguments to constructor' )
@@ -258,9 +259,9 @@ def cross(self, other):
258
259
[0 , 0 , 0 , - v [4 ], v [3 ], 0 ]
259
260
])
260
261
if isinstance (other , SpatialVelocity ):
261
- return SpatialM6 (vcross @ other .A ) # * operator
262
+ return SpatialAcceleration (vcross @ other .A ) # * operator
262
263
elif isinstance (other , SpatialF6 ):
263
- return SpatialF6 (- vcross @ other .A ) # x* operator
264
+ return SpatialForce (- vcross @ other .A ) # x* operator
264
265
else :
265
266
raise TypeError ('type mismatch' )
266
267
@@ -279,6 +280,9 @@ class SpatialF6(SpatialVector):
279
280
def __init__ (self , value ):
280
281
super ().__init__ (value )
281
282
283
+ def dot (self , value ):
284
+ return np .dot (self .A , base .getvector (value , 6 ))
285
+
282
286
# ------------------------------------------------------------------------- #
283
287
284
288
class SpatialVelocity (SpatialM6 ):
@@ -298,28 +302,30 @@ class SpatialVelocity(SpatialM6):
298
302
def __init__ (self , value = None ):
299
303
super ().__init__ (value )
300
304
301
- def cross (self , other ):
302
- r"""
303
- Spatial vector cross product
305
+ # def cross(self, other):
306
+ # r"""
307
+ # Spatial vector cross product
304
308
305
- :param other: spatial velocity vector
306
- :type other: SpatialVelocity or SpatialMomentum instance
307
- :return: cross product of spatial vectors
308
- :rtype: SpatialAcceleration instance if ``other`` is SpatialVelocity instance
309
- :rtype: SpatialMomentum instance if ``other`` is SpatialForce instance
309
+ # :param other: spatial velocity vector
310
+ # :type other: SpatialVelocity or SpatialMomentum instance
311
+ # :return: cross product of spatial vectors
312
+ # :rtype: SpatialAcceleration instance if ``other`` is SpatialVelocity instance
313
+ # :rtype: SpatialMomentum instance if ``other`` is SpatialForce instance
310
314
311
- - ``v1.cross(v2)`` is spatial acceleration given spatial velocities
312
- ``v1`` and ``v2`` or :math:`\vec{v}_1 \times \vec{v}_2`
313
- - ``v1.cross(m2)`` is spatial force given spatial velocity
314
- ``v1`` and spatial momentum ``m2`` or :math:`\vec{v}_1 \times^* \vec{m}_2`
315
+ # - ``v1.cross(v2)`` is spatial acceleration given spatial velocities
316
+ # ``v1`` and ``v2`` or :math:`\vec{v}_1 \times \vec{v}_2`
317
+ # - ``v1.cross(m2)`` is spatial force given spatial velocity
318
+ # ``v1`` and spatial momentum ``m2`` or :math:`\vec{v}_1 \times^* \vec{m}_2`
315
319
316
- :seealso: :func:`~spatialmath.spatialvector.SpatialM6`, :func:`~spatialmath.spatialvector.SpatialVelocity.__xor__`
317
- """
318
- return SpatialAcceleration (super ().cross (other ))
320
+ # :seealso: :func:`~spatialmath.spatialvector.SpatialM6`, :func:`~spatialmath.spatialvector.SpatialVelocity.__xor__`
321
+ # """
322
+ # if not len(self) == 1 or not len(other) == 1:
323
+ # raise ValueError("can only perform cross product on single-valued spatial vectors")
324
+ # return SpatialAcceleration(super().cross(other))
319
325
320
- def __xor__ (self , other ):
326
+ def __matmul__ (self , other ):
321
327
r"""
322
- Overloaded ``^ `` operator (superclass method)
328
+ Overloaded ``@ `` operator (superclass method)
323
329
324
330
:param other: spatial velocity vector
325
331
:type other: SpatialVelocity or SpatialMomentum instance
@@ -334,7 +340,7 @@ def __xor__(self, other):
334
340
335
341
:seealso: :func:`~spatialmath.spatialvector.SpatialVelocity.cross`
336
342
"""
337
- return cross (self , other )
343
+ return self . cross (other )
338
344
339
345
def __rmul (right , left ): # pylint: disable=no-self-argument
340
346
if isinstance (left , SpatialInertia ):
@@ -451,16 +457,17 @@ def __init__(self, m=None, c=None, I=None):
451
457
super ().__init__ ()
452
458
453
459
if m is None and c is None and I is None :
454
- I = np .zeros ((6 ,6 ))
455
- elif m is None and c is None and I is not None :
456
- I = arg .getmatrix (I , (6 ,6 ))
460
+ # no arguments
461
+ I = SpatialInertia ._identity ()
462
+ elif m is not None and c is None and I is None and base .ismatrix (m , (6 ,6 )):
463
+ I = base .getmatrix (m , (6 ,6 ))
457
464
elif m is not None and c is not None :
458
- c = arg .getvector (c , 3 )
465
+ c = base .getvector (c , 3 )
459
466
if I is None :
460
467
I = np .zeros ((3 ,3 ))
461
468
else :
462
- I = arg .getmatrix (I , (3 ,3 ))
463
- C = tr .skew (c )
469
+ I = base .getmatrix (I , (3 ,3 ))
470
+ C = base .skew (c )
464
471
I = np .block ([
465
472
[m * np .eye (3 ), m * C .T ],
466
473
[m * C , I + m * C @ C .T ]
@@ -577,28 +584,33 @@ def __rmul__(self, left): # pylint: disable=no-self-argument
577
584
import numpy .testing as nt
578
585
import pathlib
579
586
580
- v = SpatialVelocity ()
581
- print (v )
582
- print (len (v ))
583
- v .append (v )
584
- print (v )
585
- print (len (v ))
586
-
587
- I = SpatialInertia ()
588
- print (I )
589
- print (len (I ))
590
- I .append (I )
591
- print (I )
592
- print (len (I ))
593
-
594
- z = SpatialForce ([1 ,2 ,3 ,4 ,5 ,6 ])
595
- print (z )
596
- z = SpatialMomentum ([1 ,2 ,3 ,4 ,5 ,6 ])
597
- print (z )
587
+ # v = SpatialVelocity()
588
+ # print(v)
589
+ # print(len(v))
590
+ # v.append(v)
591
+ # print(v)
592
+ # print(len(v))
593
+
594
+ vj = SpatialVelocity ()
595
+ x = vj ^ vj
596
+ print (x )
597
+
598
+ # I = SpatialInertia()
599
+ # print(I)
600
+ # print(len(I))
601
+ # I.append(I)
602
+ # print(I)
603
+ # print(len(I))
604
+
605
+ # z = SpatialForce([1,2,3,4,5,6])
606
+ # print(z)
607
+ # z = SpatialMomentum([1,2,3,4,5,6])
608
+ # print(z)
598
609
599
610
v = SpatialVelocity ()
600
611
a = SpatialAcceleration ()
601
612
I = SpatialInertia ()
613
+ x = I * v
602
614
print (I * v )
603
615
print (I * a )
604
616
0 commit comments