bdaiinstitute / spatialmath-python

Create, manipulate and convert representations of position and orientation in 2D or 3D using Python
MIT License
497 stars 82 forks source link

Adding inertias yields: AttributeError: 'SpatialInertia' object has no attribute 'I' #101

Closed niederha closed 9 months ago

niederha commented 10 months ago

When adding two spatial inertia using the + override I get a AttributeError: 'SpatialInertia' object has no attribute 'I'.

I think I'm noticing 3 potential mistakes in the source code at line 637

return SpatialInertia(left.I + left.I)
  1. It seems SpatialInertia has no member I but rather a data[0]
  2. We're adding left twice and not right.
  3. I am not sure the syntax matches the definition in the constructor...

To make minimum changes, I would suggest rewritting this line as such:

total_inertia=SpatialInertia()
total_inertia.data[0] = left.data[0] + right.data[0]
return total_inertia

But I'm not familiar with the whole code corpus, and I just infer that from quickly reading the class. Does that seem correct? If so could we fix it? If it helps I am happy making a PR and expending tests so this doesn't happen anymore.

Otherwise, thanks for a cool library!

jcao-bdai commented 9 months ago

Thank you for pointing this out, @niederha

We'll look into this and apply a fix. Will update in this thread.

jcao-bdai commented 9 months ago

@niederha Thanks again for finding this issue.

I have created a PR with changes similar to what you proposed: https://github.com/bdaiinstitute/spatialmath-python/pull/109 Could you please take a look?

Also, if you notice other issues, you are welcome to either post an issue here, or create a pull request. Again, much appreciated!