uzh-rpg / data_driven_mpc

GNU General Public License v3.0
264 stars 53 forks source link

Libraries for real-time Matplotlib animation #2

Closed JulioLP closed 2 years ago

JulioLP commented 3 years ago

When executing trajectory_test.py with custom_sim_gui = True in:

https://github.com/uzh-rpg/data_driven_mpc/blob/c3198cba15340f3cb4bd282334509b9fc807554c/ros_gp_mpc/config/configuration_parameters.py#L34-L36

The following error arises:

Traceback (most recent call last): File "src/experiments/trajectory_test.py", line 194, in main(input_arguments) File "src/experiments/trajectory_test.py", line 78, in main world_rad=world_radius, full_traj=reference_traj) File "/home/user/catkin_ws/src/data_driven_mpc/ros_gp_mpc/src/utils/visualization.py", line 377, in initialize_drone_plotter mng.resize(*mng.window.maxsize()) AttributeError: 'MainWindow' object has no attribute 'maxsize'

I guess it is related to the missing libraries required to show the animation. It would be great to have a guide on how to install them (or at least a list of them)

tmguillem commented 3 years ago

Hi @JulioLP . Thanks for trying out our code. May I ask you to just comment out this line in particular? And the line above aswell.

These two lines will just maximize the GUI window to full screen, so they are definitely non-essential. If removing them solves your problem we might use this as a temporary workaround.

JulioLP commented 3 years ago

Thanks for the fast response! I have commented the line and now there is a different error:

Traceback (most recent call last): File "src/experiments/trajectory_test.py", line 194, in main(input_arguments) File "src/experiments/trajectory_test.py", line 119, in main targets_reached=None, pred_traj=x_pred, x_pred_cov=None) File "/home/user/catkin_ws/src/data_driven_mpc/ros_gp_mpc/src/utils/visualization.py", line 478, in draw_drone_simulation projected_traj_artists[1].set_3d_properties(x_trajectory[trajectory_start_pt:, 2]) File "/home/user/temp/virtualenv_acados/gp_mpc_venv/lib/python3.6/site-packages/mpl_toolkits/mplot3d/art3d.py", line 143, in set_3d_properties zs = np.broadcast_to(zs, xs.shape) File "<__array_function__ internals>", line 6, in broadcast_to File "/home/user/temp/virtualenv_acados/gp_mpc_venv/lib/python3.6/site-packages/numpy/lib/stride_tricks.py", line 180, in broadcast_to return _broadcast_to(array, shape, subok=subok, readonly=True) File "/home/user/temp/virtualenv_acados/gp_mpc_venv/lib/python3.6/site-packages/numpy/lib/stride_tricks.py", line 118, in _broadcast_to raise ValueError('cannot broadcast a non-scalar to a scalar array') ValueError: cannot broadcast a non-scalar to a scalar array

Just for clarification, I have only modified the lines that you commented, and the "custom_sim_gui = True" that is needed.

kelia commented 3 years ago

Hi @JulioLP . I could reproduce your issue. It is caused by an incompatibility of matplotlib. Make sure that you have matplotlib==3.2.2 installed. You can check the version by activating your virtualenv and pasting the following in a python shell:

import matplotlib as mpl
mpl.__version__
JulioLP commented 3 years ago

Now with the new matplotlib version it runs, but the plot window is rendered black, and the following message arises:

Running simulation... 0%| | 0/1000 [00:00<?, ?it/s]/home/julio/temprpg/virtualenv_acados/gp_mpc_venv/lib/python3.6/site-packages/mpl_toolkits/mplot3d/proj3d.py:189: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray return np.array([xs, ys, zs, np.ones_like(xs) ]) 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1000/1000 [00:20<00:00, 48.86it/s]

xlsufo commented 2 years ago

Now with the new matplotlib version it runs, but the plot window is rendered black, and the following message arises:

Running simulation... 0%| | 0/1000 [00:00<?, ?it/s]/home/julio/temprpg/virtualenv_acados/gp_mpc_venv/lib/python3.6/site-packages/mpl_toolkits/mplot3d/proj3d.py:189: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray return np.array([xs, ys, zs, np.ones_like(xs) ]) 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1000/1000 [00:20<00:00, 48.86it/s]

I have the same problem. Have you solved it?

JulioLP commented 2 years ago

I never solved it since it was fairly easy to use Gazebo/Rviz as visualizers instead. I recommend you to go that way!