ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Do you mean this:
def printActivationStatus(status):
variable = activationStatusInterpreter(status)
or do you want a global variable:
first define a global variable and then do:
def printActivationStatus(status):
global globVar
globVar = activationStatusInterpreter(status)
2 | No.2 Revision |
Do you mean this:
def printActivationStatus(status):
variable = activationStatusInterpreter(status)
or do you want a global variable:
first define a global variable and then do:
def printActivationStatus(status):
global globVar
globVar = activationStatusInterpreter(status)
Edit: You have to define the global variable outside of you function. Please read a good Python tutorial about global variables.
3 | No.3 Revision |
Do you mean this:
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
myvar = None
def printActivationStatus(status):
variable = activationStatusInterpreter(status)
or do you want a global variable:
first define a global variable and then do:
def printActivationStatus(status):
Callback(data):
global globVar
myvar
globVar myvar = activationStatusInterpreter(status)
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
Edit: You have to define the global variable outside of you function. Please read a good Python tutorial about global variables.