I can´t use plotter

I have problem with one of my odrives and would like to monitor it but I don´t know what is wrong with the plotter.

Here is what I try to do:

start_liveplotter(lambda:[odrv2.vbus_voltage,odrv2.axis0.motor.current_control.Iq_measured,odrv2.axis1.motor.current_control.Iq_measured,odrv2.brake_resistor_current])

After that line the plotter window or some kind of window tries to open and it flashes really fast on the screen. In odrivetool it looks like this:

In [1]: start_liveplotter(lambda:[odrv2.vbus_voltage,odrv2.axis0.motor.current_control.Iq_measured,odrv2.axis1.motor.cu
   ...: rrent_control.Iq_measured,odrv2.brake_resistor_current])
Out[1]: <threading.Event at 0x2ae1ae255e0>

C:\Users\SimuPC\anaconda3\envs\new_environment\lib\site-packages\odrive\utils.py:310: UserWarning: Starting a Matplotli.
  fig = plt.figure()
Exception in thread Thread-3:
Traceback (most recent call last):
  File "C:\Users\SimuPC\anaconda3\envs\new_environment\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\SimuPC\anaconda3\envs\new_environment\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\SimuPC\anaconda3\envs\new_environment\lib\site-packages\odrive\utils.py", line 318, in plot_data
    fig.canvas.start_event_loop(1/plot_rate)
  File "C:\Users\SimuPC\anaconda3\envs\new_environment\lib\site-packages\matplotlib\backends\backend_qt.py", line 430, p
    with _maybe_allow_interrupt(event_loop):
  File "C:\Users\SimuPC\anaconda3\envs\new_environment\lib\contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "C:\Users\SimuPC\anaconda3\envs\new_environment\lib\site-packages\matplotlib\backends\qt_compat.py", line 240, it
    old_wakeup_fd = signal.set_wakeup_fd(wsock.fileno())
ValueError: set_wakeup_fd only works in main thread

I use Anaconda prompt with windows 11. Python version is 3.9.12. Getting started page there read: Standalone Python: Download the installer for 3.8.6 from here. Execute the downloaded file and follow the instructions. As of Oct 2020, Matplotlib (required by odrivetool) had not been updated to work with 3.9, so please use 3.8.6.". Last time when I plotter these I made it with different PC and Win10.

I don´t know does this affects Anaconda prompt too? Any how, I made new environment to anaconda with python 3.8.15. I get same result with little bit different text:

In [1]: start_liveplotter(lambda:[odrv2.vbus_voltage,odrv2.axis0.motor.current_control.Iq_measured,odrv2.axis1.motor.cu
   ...: rrent_control.Iq_measured,odrv2.brake_resistor_current])
Out[1]: <threading.Event at 0x215bdf42cd0>

C:\Users\SimuPC\anaconda3\envs\new_environment\lib\site-packages\odrive\utils.py:310: UserWarning: Starting a Matplotli.
  fig = plt.figure()
Exception in thread Thread-3:
Traceback (most recent call last):
  File "C:\Users\SimuPC\anaconda3\envs\new_environment\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\SimuPC\anaconda3\envs\new_environment\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\SimuPC\anaconda3\envs\new_environment\lib\site-packages\odrive\utils.py", line 318, in plot_data
    fig.canvas.start_event_loop(1/plot_rate)
  File "C:\Users\SimuPC\anaconda3\envs\new_environment\lib\site-packages\matplotlib\backends\backend_qt.py", line 430, p
    with _maybe_allow_interrupt(event_loop):
  File "C:\Users\SimuPC\anaconda3\envs\new_environment\lib\contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "C:\Users\SimuPC\anaconda3\envs\new_environment\lib\site-packages\matplotlib\backends\qt_compat.py", line 240, it
    old_wakeup_fd = signal.set_wakeup_fd(wsock.fileno())
ValueError: set_wakeup_fd only works in main thread

What should I do to get the plotter work?

HI,
Give this a try

import matplotlib
matplotlib.use('TkAgg')
cancellation_token = start_liveplotter(lambda: [odrv0.axis0.motor.foc.Iq_setpoint, odrv0.axis0.motor.foc.Iq_measured,odrv0.axis0.motor.foc.Id_measured,odrv0.axis0.motor.foc.Iq_setpoint*0.15, odrv0.axis0.pos_vel_mapper.vel, 
odrv0.vbus_voltage],['I_setpoint','I_mesured','I_bus','mesured_torque','speed','voltage'])

Hi,

Now I was able to test this again and it works. Thank you!

-Ari

1 Like