2

So I have a Class and in its init function, I subscribe to a camera, whose callback function is created in my class. i.e:

class example(object):
  def __init__(self):
    rospy.subscriber("/cameras/left_hand_camera/image",Image,self.callback_viewer)
  def callback_viewer(self,data):
    try:
      cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8")
    except CvBridgeError as e:
      print(e)
    cv2.imshow("window", cv_image)

So for the purposes of my project, I need to create another class, which, in addition to doing some other stuff, unsubscribe to all the topics it is currently subscribing to. but I don't know how to use the unsubscriber function listed here

Can anyone help me with that, how would i use that function?

lambda
  • 85
  • 1
  • 13

1 Answers1

8

I don't understand exactly what you have to do, but when you subscribe to a topic, you can write something like this:

sub = rospy.subscriber("/cameras/left_hand_camera/image",Image,self.callback_viewer)

Then when you have to unsubscribe you just have to do:

sub.unregister()

Hope this answer your question.

Fabiobreo
  • 248
  • 1
  • 3
  • 13