Skip to content

Commit 3bc0c4e

Browse files
committed
lots of bug fixes
Featherstone's ID now working
1 parent 13f491b commit 3bc0c4e

1 file changed

Lines changed: 38 additions & 15 deletions

File tree

spatialmath/spatialvector.py

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __init__(self, value):
6464
6565
:seealso: :func:`SpatialVelocity`, :func:`SpatialAcceleration`, :func:`SpatialForce`, :func:`SpatialMomentum`.
6666
"""
67-
print('spatialVec6 init')
67+
# print('spatialVec6 init')
6868
super().__init__()
6969

7070
if value is None:
@@ -89,6 +89,8 @@ def isvalid(self, x, check):
8989
def shape(self):
9090
return (6,)
9191

92+
def __getitem__(self, i):
93+
return self.__class__(self.data[i])
9294
# ------------------------------------------------------------------------ #
9395
@property
9496
def V(self):
@@ -266,9 +268,9 @@ def cross(self, other):
266268
[0, 0, 0, -v[4], v[3], 0]
267269
])
268270
if isinstance(other, SpatialVelocity):
269-
return SpatialAcceleration(vcross * other.V) # * operator
271+
return SpatialAcceleration(vcross @ other.V) # * operator
270272
elif isinstance(other, SpatialF6):
271-
return SpatialAcceleration(-vcross * other.V) # x* operator
273+
return SpatialForce(-vcross @ other.V) # x* operator
272274
else:
273275
raise TypeError('type mismatch')
274276

@@ -477,19 +479,40 @@ def __init__(self, m=None, c=None, I=None):
477479
- ``SpatialInertia(I)`` is a spatial inertia object with a value equal
478480
to ``I`` (6x6).
479481
"""
480-
if m is not None and c is not None:
481-
assert arg.isvector(c, 3), 'c must be 3-vector'
482+
super().__init__()
483+
484+
if m is None and c is None and I is None:
485+
I = np.zeros((6,6))
486+
elif m is None and c is None and I is not None:
487+
I = arg.getmatrix(I, (6,6))
488+
elif m is not None and c is not None:
489+
c = arg.getvector(c, 3)
482490
if I is None:
483491
I = np.zeros((3,3))
484492
else:
485-
assert arg.ismatrix(I, (3,3)), 'I must be 3x3 matrix'
493+
I = arg.getmatrix(I, (3,3))
486494
C = tr.skew(c)
487-
self.I = np.array([
488-
[m * np.eye(3), m @ C.T],
489-
[m @ C, I + m * C @ C.T]
490-
])
491-
elif m is None and c is None and I is not None:
492-
assert arg.ismatrix(I, (6, 6)), 'I must be 6x6 matrix'
495+
I = np.block([
496+
[m * np.eye(3), m * C.T],
497+
[m * C, I + m * C @ C.T]
498+
])
499+
else:
500+
raise ValueError('bad values')
501+
502+
self.data = [I]
503+
504+
@staticmethod
505+
def _identity():
506+
return np.zeros((3,3))
507+
508+
def isvalid(self, x, check):
509+
return True
510+
511+
def shape(self):
512+
return (3,3)
513+
514+
def __getitem__(self, i):
515+
return SpatialInertia(self.data[i])
493516

494517
def __repr__(self):
495518

@@ -506,7 +529,7 @@ def __repr__(self):
506529
return self.__str__()
507530

508531
def __str__(self):
509-
return str(self.I)
532+
return str(self.A)
510533

511534

512535
def __add__(left, right): # pylint: disable=no-self-argument
@@ -538,11 +561,11 @@ def __mul__(self, right): # pylint: disable=no-self-argument
538561
left = self
539562

540563
if isinstance(right, SpatialAcceleration):
541-
v = SpatialForce(left.I @ right.V) # F = ma
564+
return SpatialForce(left.A @ right.V) # F = ma
542565
elif isinstance(right, SpatialVelocity):
543566
# crf(v(i).vw)*model.I(i).I*v(i).vw;
544567
# v = Wrench( a.cross() * I.I * a.vw );
545-
v = SpatialMomentum(left.I * right.V) # M = mv
568+
return SpatialMomentum(left.A @ right.V) # M = mv
546569
else:
547570
raise TypeError('bad postmultiply operands for Inertia *')
548571

0 commit comments

Comments
 (0)