ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
To accomplish this you'll want to have your rospy.Subscriber
callback simply save the latest message. Then use a rospy.Timer
with a separate function that calls your processing code with the latest message on a fixed schedule.
class Node:
...
self.subscriber = rospy.Subscriber(sub_topic, MessageType, self.sub_callback)
self.publisher = rospy.Publisher(pub_topic, MessageType)
rospy.Timer(rospy.Duration(1), self.timer_callback)
def sub_callback(self, message):
self.latest_message = message
def timer_callback(self, _):
self.processing_code(self.latest_message)
def processing_code(self, message):
...
self.publisher.pub(processed_message)