spatialmath-python icon indicating copy to clipboard operation
spatialmath-python copied to clipboard

Check type-check for NDArray under Animate-Run-Update

Open alsaibie opened this issue 1 year ago • 1 comments

In animate.py

The frame type check is done against NDArray, which gives an error when passing a Rotation matrix for example. It works if changd to np.ndarray

Error

elif isinstance(frame, NDArray):

fix

elif isinstance(frame, np.ndarray):

Here

Is this an error in animate.py or I need to fix something in my example?

Example

# imports
ax = plotvol3(new=True)
J = np.array([[ 2, -1, 0],
              [-1,  4, 0],
              [ 0,  0, 3]]);
orientation = UnitQuaternion();  # identity quaternion
w = 0.2 * np.array([1, 2, 2]);
dt = 0.05;  # time step
def update():
  global orientation, w
  for t in np.arange(0, 10, dt):
     wd = -np.linalg.inv(J) @ (np.cross(w, J @ w))  # (3.12)
     w += wd * dt
     orientation *= UnitQuaternion.EulerVec(w * dt)
     print(type(orientation.R))
     yield NDArray[orientation.R]

ani = tranimate(update(), ax=ax, frame='A', color='green');

plt.show()

NumPy version: 1.26.4 Matplotlib version: 3.8.4 Spatialmath version: 1.1.11

alsaibie avatar Sep 27 '24 06:09 alsaibie

Thank you so much @alsaibie

We tested and implemented the fix in this PR: https://github.com/bdaiinstitute/spatialmath-python/pull/138

jcao-bdai avatar Sep 27 '24 15:09 jcao-bdai