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

Ros subscriber - Passing msg data to the callback

asked 2014-01-20 11:27:08 -0500

Phorce gravatar image

updated 2014-01-28 17:07:28 -0500

ngrennan gravatar image

I have a custom msg data file containing the data field names that I wish to use for a project.

This data is published in a topic, that is written in Python. What I am trying to do is create a C++ script (Subscriber) that subscribes to this topic and displays a particular name within the msg data.

So far I have written the following:

void callback(const leap_motion_sensor::leap& msg)
    ROS_INFO("I heard" + msg);

int main(int argc, char** argv)
    ros::init(argc, argv, "features");

    ros::NodeHandle n;

    //ros::Timer timer1 = n.createTimer(ros::Duration(0.08), callback);

    ros::Subscriber sub = n.subscribe("/leapmotion/data", callback);


  return 0;

I get the following warning message:

[WARN] [WallTime: 1390260279.317426] Could not process inbound connection: topic t
types do not match: [leap_motion_sensor/leap] vs. [leap_motion_sensor/leapros]
{'topic': '/leapmotion/data', 'tcp_nodelay': '0', 'md5sum': 
'3e9a0dc7fd1a98f1d7489e9011c78807', 'type': 'leap_motion_sensor/leap', 'callerid': 

Here is what the msg file contains:

Header header

float64[3] hand_direction float64[3] hand_normal float64[3] hand_palm_pos float64 hand_pitch float64 hand_roll float64 hand_yaw

I just want to copy the data from the "hand_direction" into a std::vector<float> Is this possible and if so, what needs to be in my callback function in order to be able to pass through this data?


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-01-20 15:58:09 -0500

ahendrix gravatar image

It looks like you aren't publishing and receiving the same message types; the message type that you're subscribing to and the message type that is being published must match.

For your example, it looks like you should be subscribing to the leap_motion_sensor/leapros message type (leap_motion_sensor::leapros in C++).

From there, you should be able to access the hand_direction data with msg->hand_direction

edit flag offensive delete link more

Question Tools



Asked: 2014-01-20 11:27:08 -0500

Seen: 1,303 times

Last updated: Jan 20 '14