Ask Your Question

Revision history [back]

I'm not quite sure, what you are trying to achieve, with those __init__ etc. inside the functions Clock_ and Diagnostics_.

I would go for something like this:

def diagnostics_callback(diagnostics):
    print diagnostics

def clock_callback(clock):
    print clock

if __name__ == '__main__':
    rospy.init_node('listener', anonymous=True)
    diagnostics_sub = rospy.Subscriber('diagnostics', DiagnosticArray, diagnostics_callback)
    clock_sub = rospy.Subscriber('clock', Clock, clock_callback)
    rospy.spin()

or, if you want to use classes:

class ListnerVilma:
    def __init__(self):
        self.diagnostics_sub = rospy.Subscriber('diagnostics', DiagnosticArray, self.diagnostics_callback)
        self.clock_sub = rospy.Subscriber('clock', Clock, self.clock_callback)

    def diagnostics_callback(self, diagnostics):
        print diagnostics

    def clock_callback(self, clock):
        print clock

if __name__ == '__main__':
    rospy.init_node('listener', anonymous=True)
    myVilma = ListenerVilma()
    rospy.spin()

That should do the trick (from the top of my head, most probably not error free ;-) )