Subscribe to Multiple Topics and Callback Function
Hello,
I would like to write a node in python which subscribes to multiple topics using only one callback function. What's the correct way to do this? For instance, I want to compare the values published on two different topics (cmd_vel
and base_velocity
) in a callback function. I'm assuming these two topics are being published continuously, so I think I want a callback when both topics are updated
def callback(data):
if cmdVel == baseVelocity:
# Do Step 1
else:
# Do Step 2
def listener():
rospy.Subscriber('cmd_vel', Twist, callback)
rospy.Subscriber('base_velocity', Twist, callback)
rospy.spin()
if __name__ == '__main__':
rospy.init_node('robot_controller', anonymous=True)
listener()
Thanks