How to use variable's value (subscriber function) in another function
Hello all !
I want to pass the variable which is set to its value when called the callback function. and then want to use the value of the variable in another function.
def where1(msg):
global x1
x1 = msg.data
def where2(gsm):
global y1
y1 = gsm.data
def ground():
global x1
global y1
rospy.init_node("ground")
rospy.Subscriber("/box_positiona", Float64, where1)
rospy.Subscriber("/box_positionb", Float64, where2)
print x1
print y1
rospy.spin() # this will block untill you hit Ctrl+C
if __name__ == '__main__':
try:
ground()
except rospy.ROSInterruptException:
rospy.loginfo("Ground motion node is shut down.")
But i got the following error print x1 NameError: global name 'x1' is not defined