ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 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)

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.

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.