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

This is really a Python issue, not a ROS one, but:

global a,b, callback, callback2, data, data1
[..]
data=0
[..]
def listener():
    [..]
    m= data.a
    [..]

The variable data is just an integer, not an object, or some other composite structure. You cannot index into it, nor use the dot operator to select contained fields.

I believe you are expecting the data argument to callback(..) (which may or may not have a field called a, depending on the message IDL) to be available to you in listener(), but that is not how this works.

This is really a Python issue, not a ROS one, but:

global a,b, callback, callback2, data, data1
[..]
data=0
[..]
def listener():
    [..]
    m= data.a
    [..]

The variable data is just an integer, not an object, or some other composite structure. You cannot index into it, nor use the dot operator to select contained fields.

I believe you are expecting the data argument to callback(..) (which may or may not have a field called a, depending on the message IDL) to be available to you in listener(), but that is not how this works.


I'm also rather puzzled by the the global a,b,... line at the top of your program. Those variables are already in the global scope, so what is it you're trying to do?

If I may suggest, it might be good to try and find some good Python books or online tutorials. With just a little Python experience I think you'll find that things (such as rospy) start to make a lot more sense.