[ros-users] Problems with subscriber and spinOnce

トップ ページ
添付ファイル:
Eメールのメッセージ
+ (text/plain)
+ (text/html)
このメッセージを削除
このメッセージに返信
著者: User discussions
日付:  
To: User discussions
題目: [ros-users] Problems with subscriber and spinOnce
Hey everyone

I got a small problem writting a subscriber using the spinOnce command
instead of the spin() used in the tutorial. I do not receive anything from
the subscription, but I know topics are being published. rviz is showing
that the data is published and if I rewrite the code to use spin() like in
the tutorial, then I get plenty of information. I have tried to search the
problem but did not find anything useful and I hope someone here can see the
problem.

My code is:

int main(int argc, char **argv)
{
        init(argc, argv, "testPlayer");
        NodeHandle n;


        Subscriber sub;


        Rate loop_rate(5);


        testPlayer test;


        while ( ok() ) {


            sub = n.subscribe("scan", 1000, &testPlayer::callBack, &test);


            spinOnce();


            loop_rate.sleep();
        }


return 0;
}

Regards

Sebastian Aslund