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

Revision history [back]

Almost certainly the issue has to do with scoping in Python. In your callbacks you likely have some line looking approximately like gps_xy = msg.data.something. This is creating a new variable local to the callback that goes out of scope as soon as the callback is done running. Here are several ways you could fix this:

  • Force the variables that you want updated to be global variables with the global keyword in your callbacks.
  • Make the variables, callbacks, and pubs/subs part of a class. Then your callback will receive a copy of self as its first argument, and you'll be able to access self.gps_xy
  • Use the callback_args argument in the Subscriber instantiation method to pass additional arguments to your callback. In this case, it would be the variables that you would want updated within the callbacks.