Passing Variables From Callback Function to Main Python
Hey,
Just want to pass a some subscribed data from my callback function to my main function so I can use it to command a controller.
import rospy
from geometry_msgs.msg import PoseStamped
def callback(msg):
x = msg.pose.position.x
y = msg.pose.position.y
z = msg.pose.position.z
def main():
rospy.init_node('pose_monitor')
rospy.Subscriber("/aruco_single/pose", PoseStamped, callback)
print (x)
rospy.spin()
if __name__== '__main__':
main()
This is the error I get:
Traceback (most recent call last):
File "/home/zachary/catkin_ws/src/panda_arm_test/src/suscriber.py", line 17, in <module>
main()
File "/home/zachary/catkin_ws/src/panda_arm_test/src/suscriber.py", line 14, in main
print (x)
Would appreciate the help!
Cheers!