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

Revision history [back]

data is just the variable name for the message that is passed in. You could name it msg, foo or whateveryoulike.

The content of it depends on the message type defined in the according instantiation of the subscriber. In the tutorial this is rospy.Subscriber("chatter", String, callback) type is std_msgs::String (check the import statements). You can find the data fields of ROS messages on the docs pages, e.g. here or using rosmsg show PKG MSG.

data is just the variable name for the message that is passed in. You could name it msg, foo or whateveryoulike.

The content of it depends on the message type defined in the according instantiation of the subscriber. In the tutorial this is rospy.Subscriber("chatter", String, callback) type is std_msgs::String (check the import statements). You can find the data fields of ROS messages on the docs pages, e.g. here or using rosmsg show PKG MSG.


EDIT

Well the first data in callback(data) is a ROS message, so if the ROS message is an std_msgs/Int16, data refers to that. However, this is actually a class and the actual int16 is found in the data.data member. Again, the first data is just a name, the second one is the variable of the std_msgs/Int16 which is "hardcoded".

data is just the variable name for the message that is passed in. You could name it msg, foo or whateveryoulike.

The content of it depends on the message type defined in the according instantiation of the subscriber. In the tutorial this is rospy.Subscriber("chatter", String, callback) type is std_msgs::String (check the import statements). You can find the data fields of ROS messages on the docs pages, e.g. here or using rosmsg show PKG MSG.


EDIT

Well the first data in callback(data) is a ROS message, so if the ROS message is an std_msgs/Int16, data refers to that. However, this is actually a class and the actual int16 is found in the data.data member. Again, the first data is just a name, the second one is the variable of the std_msgs/Int16 which is "hardcoded".

As a more intuitive example, as it gets rid of this double data thing is e.g. std_msgs/ColorRGBA. data is the full message and you can access the respective field r, g, b and a via data.r, data.g and so on...