odrive liveplotter 报错 “set_wakeup_fd only works in main thread of the main interpreter”
最近在弄FOC,电脑装的是odrive 0.5.1。在进行实时画图的时候需要运行下面的代码
start_liveplotter(lambda:[odrv0.axis0.encoder.pos_estimate, odrv0.axis0.controller.pos_setpoint])
但是,在运行这行代码的时候爆出如下错误,
In [1]: start_liveplotter(lambda:[odrv0.axis0.encoder.pos_estimate, odrv0.axis0.controller.pos_setpoint])
Out[1]: <fibre.utils.Event at 0x1d511e5fa00>
Installed qt6 event loop hook.
C:\Users\ruiga\.conda\envs\py39\lib\site-packages\odrive\utils.py:154: UserWarning: Starting a Matplotlib GUI outside o.
fig = plt.figure()
Exception in thread Thread-4:
Traceback (most recent call last):
File "C:\Users\ruiga\.conda\envs\py39\lib\threading.py", line 980, in _bootstrap_inner
self.run()
File "C:\Users\ruiga\.conda\envs\py39\lib\threading.py", line 917, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\ruiga\.conda\envs\py39\lib\site-packages\odrive\utils.py", line 162, in plot_data
fig.canvas.start_event_loop(1/plot_rate)
File "C:\Users\ruiga\.conda\envs\py39\lib\site-packages\matplotlib\backends\backend_qt.py", line 412, in start_event_p
with _maybe_allow_interrupt(event_loop):
File "C:\Users\ruiga\.conda\envs\py39\lib\contextlib.py", line 119, in __enter__
return next(self.gen)
File "C:\Users\ruiga\.conda\envs\py39\lib\site-packages\matplotlib\backends\qt_compat.py", line 199, in _maybe_allow_t
old_wakeup_fd = signal.set_wakeup_fd(wsock.fileno())
ValueError: set_wakeup_fd only works in main thread of the main interpreter
其实解决的方法很简单,只需要先运行
odrivetool
然后在接下来的命令行运行下列命令
In [1]: import matplotlib
In [2]: matplotlib.use('TkAgg')
然后再运行
start_liveplotter(lambda:[odrv0.axis0.encoder.pos_estimate, odrv0.axis0.controller.pos_setpoint])
就可以画图了。ez问题