ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
class DemoNode():
  def __init__(self):
    print("entering constructor")
    #super().__init__('custom_talker') = rospy.Publisher('topic',customMessage, queue_size=10)
    self.counter = 1
    print("creating a publisher")
    self.timer = rospy.Timer(rospy.Duration(1), self.demo_callback)
    print("timer called")

  def demo_callback(self, timer):
    print("entering callback")
    msg = DetectedObject()
    print("Reading the message correctly") = self.counter
    self.counter += 1
    rospy.loginfo("Publishing message {}".format(

if __name__ == '__main__':

  print("entering main")
    print("entering Try")
  except rospy.ROSInterruptException:
    print("exception thrown")

This should work, you were missing rospy.spin() that was main issue, and alos timer in callback, as it needs 2 arguments(including self). Also self was missing at 2 places in demo_callback.