ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
The code has a few bugs.
talker()
, you've got an infinite while() but you don't really do anything there (pub.publish()
isn't publishing any meaningful content).while not rospy.is_shutdown()
and rospy.spin()
? Also, rospy.spin()
is unreachable in your code.Based on message_filters Python example, I re-wrote your code (code is untested):
def callback(data1, data2):
rospy.loginfo(rospy.get_caller_id())
## do stuff with data1 and data2 ##
pub.publish("some_string")
if __name__ == '__main__':
rospy.init_node('SubPub', anonymous=True)
pub = rospy.Publisher('Publisher', String, queue_size=10)
sub_1 = message_filters.Subscriber("chatter", String)
sub_2 = message_filters.Subscriber("sub_chatter", String)
ts = message_filters.ApproximateTimeSynchronizer([sub_1, sub_2], 10, 0.1, allow_headerless=True)
ts.registerCallback(callback)
rospy.spin()