dfki-ric-underactuated-lab / double_pendulum

Dual purpose Acrobot and Pendubot Platform
BSD 3-Clause "New" or "Revised" License
33 stars 22 forks source link

error while running examples #2

Closed varunvenna closed 1 year ago

varunvenna commented 1 year ago

The U array in plot_timeseries(T, X, U) is empty (U=[]) the simulate_and_animate function is returning:

T = [0.0]
X = [[0.0, 0.0, -7.37344695478681e-05, -0.000171805470714]]
U = []

Error while running:

$ python3 pid_traj.py
/double_pendulum/lib/python3.10/site-packages/double_pendulum/simulation/simulation.py:1063: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
  plt.show()
Traceback (most recent call last):
  File "/double_pendulum/examples/ideal/pid_traj.py", line 60, in <module>
    plot_timeseries(T, X, U,
  File "/double_pendulum/lib/python3.10/site-packages/double_pendulum/utils/plotting.py", line 213, in plot_timeseries
    T[: len(U)], np.asarray(U).T[0, : len(T)], label=r"$u_1$", color="blue"
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
fwiebe commented 1 year ago

Hi @varunvenna , the problem is that your matplotlib is using a non-GUI backend (see the warning after your command). If you would like to see the animation switch to a gui backend e.g. with

import matplotlib matplotlib.use('TkAgg')

If you want to simulate the double pendulum without animation you can use the sim.simulate(...) function which is commented below the sim.simulate_and_animate(...) function in the pid_traj.py script you are testing.

varunvenna commented 1 year ago

okay. thank you! The problem is resolved by just installing python3-tk

sudo apt-get install python3-tk