Ask Your Question
0

ROS fuerte - check subscriber

asked 2015-03-18 06:46:41 -0500

Bardo91 gravatar image

Hi,

I want to check if a subscriber has subscribe properly to a topic. I read in documentation ( http://docs.ros.org/api/roscpp/html/c... ) that this is made checking nodehandle but compiler sais that cant convert nodehandle to bool.

    ros::NodeHandle n;
    /* ... */
    intruder_sub[i]=n.subscribe(topicname.c_str(), 0,Intruder_StateCallBack);
    if(n){
        cout << "cant subscribe to " << topicname << endl;
        assert(false);
    }

What I'm doing wrong? Thanks in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-03-18 07:21:44 -0500

Wolf gravatar image

Well, thats a bit misleading in the documentation you linked.

ros::NodeHandle cannot be converted to bool, ros::Subscriber can and the conversion returns true, i. e. 1, if the subscriber is valid:

http://docs.ros.org/api/roscpp/html/c... http://docs.ros.org/api/roscpp/html/s...

In your case it'd be:

ros::NodeHandle n;
/* ... */
intruder_sub[i]=n.subscribe(topicname.c_str(), 0,Intruder_StateCallBack);
if( intruder_sub[i] ){
    cout << "cant subscribe to " << topicname << endl;
    assert(false);
}

In the docu you linked ( http://docs.ros.org/api/roscpp/html/c... ) it'd be clearer to understand if it were:

if (sub)
{
...
}

Maybe someone should open a ticket to update that....

edit flag offensive delete link more

Comments

That's it. Thank you very much. I put the ticket.

Bardo91 gravatar image Bardo91  ( 2015-03-18 10:24:13 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-03-18 06:46:41 -0500

Seen: 76 times

Last updated: Mar 18 '15