jgerstmayr / EXUDYN

Multibody Dynamics Simulation: Rigid and flexible multibody systems
https://www.youtube.com/channel/UCsQD2bIPBXB_4J23WtqKkVw/playlists
Other
173 stars 23 forks source link

ValueError when trying to use initialRotationMatrix in CreateRigidBody #66

Closed ManuelZ closed 6 months ago

ManuelZ commented 6 months ago

When trying to use initialRotationMatrix in CreateRigidBody, I'm getting an error.

Minimally reproducible example:

import numpy as np
import exudyn as exu
from exudyn.rigidBodyUtilities import RigidBodyInertia, RotationMatrixZ

SC = exu.SystemContainer()
mbs = SC.AddSystem()

mbs.CreateRigidBody(
    inertia=RigidBodyInertia(mass=1, inertiaTensor=np.ones([3, 3])),
    initialRotationMatrix=RotationMatrixZ(np.deg2rad(45)),
    create2D=True,
)

mbs.Assemble()
mbs.SolveDynamic()
    ...
    d = mbs.CreateRigidBody(
        ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\...\Lib\site-packages\exudyn\mainSystemExtensions.py", line 370, in MainSystemCreateRigidBody
    if initialRotationMatrix != None and not IsSquareMatrix(initialRotationMatrix, 3):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Changing all the != None checks to is not None in mainSystemExtensions.py solves it. (And maybe changing the == Nones to is None would be worth it as well).

jgerstmayr commented 6 months ago

you are totally right and sorry for that. Checks are changed in 1.8.7. There are some errors in the CreateRigidBody function, in particular the comparison (matrix == None) does not work for numpy and is changed to (matrix is None). I will try to update on GitHub and pypi this week. For now, I recommend to use rigid bodies directly. There are some further errors in the CreateRigidBody function related to initial rotation matrices in this function that is resolved.