Ask Your Question

How to check if my call back function works

asked 2013-08-08 00:34:03 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

void poseCallback(const mera::lonaConstPtr &msg){  
        int i;  

        static tf::TransformBroadcaster br;
        tf::Transform transform;   
        transform.setOrigin( tf::Vector3(0,0,0));
        transform.setRotation( tf::Quaternion(1,1,1));
        br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "world", "madar_link"));

How do I know if this works. Are there any commands which can help me to know if this will work

edit retag flag offensive close merge delete


ROS_ERROR? Or any other print function?

TommyP gravatar image TommyP  ( 2013-08-08 04:11:27 -0600 )edit

@TommyP can you please elaborate on this? Should I just put something like ROS_INFO("See if it works"); insite my poseCallback function to check if its printing or something like that. I dont know how does ROS_ERROR works. Thanks

Bodgan Mircu gravatar image Bodgan Mircu  ( 2013-08-08 04:47:54 -0600 )edit

To check if your function callback "*works*" is slightly different than checking if the function callback is "*being executed*" ;) - but yes, add ROS_INFO("Executing poseCallback"); as the very first line of your function. If that function is being executed, you will see it in the log messages.

dPackard gravatar image dPackard  ( 2013-08-09 13:10:41 -0600 )edit

@dPackard I tried to do this but I cannot visualise my log messages. The only way to visualise log message is via rqt_console? Am I right. When I try to check it via rqt_console nothing appears. I cannot see any messages

Bodgan Mircu gravatar image Bodgan Mircu  ( 2013-08-11 21:49:36 -0600 )edit

The printout is also in the shell from where you started the program. If you start with launch file give the --screen flag to roslaunch otherwis you will not see all printouts (ROS_ERROR you will see without --screen)..

TommyP gravatar image TommyP  ( 2013-08-11 23:32:42 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2013-08-12 04:13:01 -0600

If you've included a ROS_INFO statement in your callback, and that message doesn't show up in rosconsole or the terminal where you started the node, then your cb is not being executed.

There are a few possible reasons that your callback would not be executed... but I'm going to guess at a couple likely reasons since you don't run into any build errors. I'm guessing that this is a callback for a subscribed topic. The callback for a subscribed topic is only executed when new data is published to the topic you've subscribed to.

This suggests that A) no data is being published to the topic you are subscribed to, or B) you are subscribed to a topic that doesn't exist

The rostopic and rqt_graph tools can help you investigate these possibilities.

edit flag offensive delete link more



If this didn't help, please update your question with more details describing your exact situation (e.g. how you registered the callback in your code, what is the output of `rostopic echo <topic name="">`, of `rosnode info <node name="">`, etc), and maybe someone can help you find an exact solution

dPackard gravatar image dPackard  ( 2013-08-12 04:18:05 -0600 )edit

@dPackard first of all, thanks for such a detailed answer. After some debugging I have figured out that the call back function does not work for me. However its not because of the 2 reasons you mentioned above [(A) no data is being published to the topic you are subscribed to, or B) you are subscribed to a topic that doesn't exist)] . Becuase when I do rostopic echo /mytopic then I can see information on the console which shows information is being published on the topic. Also when I subscribe I use the same topic /mytopic. I will try to debug my code further and try to figure it out. Thanks

Bodgan Mircu gravatar image Bodgan Mircu  ( 2013-08-12 15:08:02 -0600 )edit

Good luck! It sounds like you are on your way to figuring it out :D

dPackard gravatar image dPackard  ( 2013-08-12 16:35:00 -0600 )edit

answered 2013-08-09 02:26:30 -0600

pkohout gravatar image

Use one of the print function, like @TommyP said. Its very easy to use, and there is not a greate different if you use ROS_INFO or ROS_ERROR, that just means the Logger Level you use, [].

I mostly use the ROS_DEBUG("....") Method to make sure my callbacks work fine.

edit flag offensive delete link more

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


Asked: 2013-08-08 00:34:03 -0600

Seen: 543 times

Last updated: Aug 12 '13