rospy subscribing to topic, how can i save a variable?
Hi
I'm fairly new to programming in python and ROS, but my problem is as follows: I am using a robot gripper, and for control purposes i need to read the status of the gripper and save it to a variable, so I can use if in control sequences. I am getting the status of the gripper by subscribing to a topic.
import roslib; roslib.load_manifest('robotiq_s_model_control')
import rospy
from robotiq_s_model_control.msg import _SModel_robot_input as inputMsg
from robotiq_s_model_control.msg import _SModel_robot_output as outputMsg
def Callback(data):
myvar = data
rospy.init_node('rq3_proxy')
while not rospy.is_shutdown():
rospy.Subscriber("SModelRobotInput", inputMsg.SModel_robot_input, Callback)
rospy.sleep(1)
print "myvar is: " + myvar
if myvar == 1:
#do something"
elif myvar == 0:
#do something else
else :
#error
So my question is: how can I make use of the myvar variable outside the Callback function?
Thanks in advance for any help you can provide, and if you need additional info, just ask for it.
/Morten