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

You can:

  1. use a global variable (not recommended for anything serious)
  2. use a custom class in which you save the data you a member variable
  3. use event-driven programming in which you call other functions from within the callback and pass the data to those functions

You can:

  1. use a global variable (not recommended for anything serious)
  2. use a custom class in which you save the data you a member variable
  3. use event-driven programming in which you call other functions from within the callback and pass the data to those functions

Update

my_data = None

def callback(data):
    # you have to let python know that this is a global otherwise
    # it thinks that it's a local variable
    global my_data 
    my_data = data.data
    rospy.loginfo(rospy.get_caller_id() + "I heard %s", my_data)