how to use callback() with python
can anyone explain how to use callback in writing a subscriber? the tutorial uses callback(data),but what it data? what content dose it have? thank you very much!
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
can anyone explain how to use callback in writing a subscriber? the tutorial uses callback(data),but what it data? what content dose it have? thank you very much!
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...
Asked: 2018-09-11 21:15:37 -0500
Seen: 3,326 times
Last updated: Sep 12 '18
how to bind a callback to include a MessageEvent [closed]
How to make a callback function to subscribe to a non string topic?
Publishing a topic/message in a callback member function
Subscription of pose is not properly subscribed
calling a service from an other file on the same machine
Callback function to a Class member function
Separating callback from other modules
After execution Call back function program doesnt return to orignal execution?