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

Super late, and this is more of a general python question, but you can avoid global variables by just passing things around...

def Callback(data):
    myvar = data
    do_something(myvar)

def do_something(myvar):
   print "myvar is: " + myvar
   if myvar == 1:
         #do something"
    elif myvar == 0:
         #do something else
    else :
         #error    

rospy.init_node('rq3_proxy')

while not rospy.is_shutdown():
    rospy.Subscriber("SModelRobotInput", inputMsg.SModel_robot_input, Callback)
    rospy.sleep(1)

Super late, and this is more of a general python question, but you can avoid global variables by just passing things around...

def Callback(data):
    myvar = data
    do_something(myvar)

def do_something(myvar):
   print "myvar is: " + myvar
   if myvar == 1:
         #do something"
    elif myvar == 0:
         #do something else
    else :
         #error    

def Callback(data):
    myvar = data
    do_something(myvar)

rospy.init_node('rq3_proxy')

while not rospy.is_shutdown():
    rospy.Subscriber("SModelRobotInput", inputMsg.SModel_robot_input, Callback)
    rospy.sleep(1)