Ros QObject Timer Error without using TImer

21 views Asked by At

I have this code, which used to work, but I guess some update must have happened and now it print out the error: QObject::startTimer: Timers can only be used with threads started with QThread.

It confuses me, as I don't start a timer anywhere. I know that Ros and Matplotlib can cause some threading problems, yet as this code has worked before, I am a bit lost on how to fix it.

#!/usr/bin/env python3 
import numpy as np
from matplotlib import pyplot as plt
import rospy
from my_dsp.msg import range_doppler

fig = plt.figure()    #Seems to be a little bit faster if fig is outside class, but both work fine.

class Plotter:
  def __init__(self):
    #self.fig = plt.figure()
    self.rd = np.zeros((32,32))
    self.plot= plt.imshow(self.rd,vmin=0,vmax=10)           #Imshow creates type of figure we wish, vmin/vmax makes sure color scale works and not everything is blue 
    plt.colorbar()

  def plot_x(self,msg):
    self.rd= np.asarray(msg.data)
    self.rd = self.rd.reshape((32,32))
    self.plot.set_data(self.rd)
    plt.draw()

if __name__ == '__main__':
  rospy.init_node("watcher")
  obc = Plotter()
  rospy.Subscriber('range_doppler_abs', range_doppler, obc.plot_x)
  plt.show(block=True)
  rospy.spin()
0

There are 0 answers