Skip to content

Fix drone 3D trajectory animation with NumPy 2.5 - #1522

Open
b84330808 wants to merge 1 commit into
AtsushiSakai:masterfrom
b84330808:fix-drone-animation-numpy-scalars
Open

b84330808 wants to merge 1 commit into
AtsushiSakai:masterfrom
b84330808:fix-drone-animation-numpy-scalars

Conversation

@b84330808

Copy link
Copy Markdown

Reference issue

None, found while running the examples with the pinned requirements.

What does this implement/fix?

Running the drone example with animation on (the default) fails on the first frame with the pinned NumPy 2.5.4:

$ cd AerialNavigation/drone_3d_trajectory_following
$ python drone_3d_trajectory_following.py
  File ".../Quadrotor.py", line 56, in transformation_matrix
    [[cos(yaw) * cos(pitch), ...
TypeError: only 0-dimensional arrays can be converted to Python scalars

TrajectoryGenerator.solve() returns the coefficients as 6x1 column vectors, so the simulated roll and pitch end up as 1-element arrays. #861 worked around this in rotation_matrix() with roll_array[0], but Quadrotor.transformation_matrix() still passes the arrays to math.cos/math.sin. test1 runs with show_animation = False, so CI never reaches that code.

This flattens the coefficients in main(), so every simulated state is a scalar, and drops the roll_array[0] workaround. The simulated poses are unchanged: I compared all 409 poses before and after and they are identical.

Additional information

The new test test_poses_can_be_drawn computes transformation_matrix() for every pose, as Quadrotor.plot() does, without opening a figure. It fails on master with the TypeError above and passes with this change.

Ran on Windows 11, Python 3.13 with the pinned requirements:

  • pytest tests/test_drone_3d_trajectory_following.py -Werror: 2 passed
  • python drone_3d_trajectory_following.py with the Agg backend runs to Done
  • ruff and mypy are clean for the touched files

CheckList

  • Did you add an unittest for your new example or defect fix?
  • Did you add documents for your new example?
  • All CIs are green? (You can check it after submitting)

TrajectoryGenerator.solve() returns the polynomial coefficients as 6x1
column vectors, so the simulated roll and pitch are 1-element arrays.
AtsushiSakai#861 worked around this in rotation_matrix(), but with show_animation on
Quadrotor.transformation_matrix() still passes them to math.cos/sin, and
the pinned NumPy 2.5.4 raises "TypeError: only 0-dimensional arrays can
be converted to Python scalars" on the first frame.

Flatten the coefficients so every state is a scalar, and drop the
workaround in rotation_matrix(). The simulated poses are unchanged.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant