ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
You should be able to do the same thing below. The changes are
class SomeClass(object):
def __init__(self):
rospy.init_node('node_name', anonymous=True)
self.sub = rospy.Subscriber('sub_name', sub_type, self.sub_callback, queue_size=10)
self.rate = 100
self.sub_msg = None
def sub_callback(self, msg):
self.sub_msg = msg
def spin(self):
r = rospy.Rate(self.rate)
while self.sub_msg == None:
r.sleep()
while not rospy.is_shutdown():
print(self.sub_msg)
r.sleep()
if __name__ == "__main__":
SC = SomeClass()
SC.spin()