Ask Your Question
0

Why RegisterCallBack and ros::Spin both don't work?

asked 2016-08-02 13:15:55 -0500

KWL gravatar image

Refer the code in velodyne_camera_calibration , when I run the code, it doesn't terminate and has no error but it doesn't continue in the middle(line 198 and line 190). In order to have convenient debug, I add some "cout" to print something.

  message_filters::Subscriber<sensor_msgs::Image> image_sub(n, CAMERA_FRAME_TOPIC, 1);
  message_filters::Subscriber<sensor_msgs::CameraInfo> info_sub(n, CAMERA_INFO_TOPIC, 1);
  message_filters::Subscriber<sensor_msgs::PointCloud2> cloud_sub(n, VELODYNE_TOPIC, 1);

 typedef sync_policies::ApproximateTime<sensor_msgs::Image, sensor_msgs::CameraInfo, sensor_msgs::PointCloud2> MySyncPolicy;
 Synchronizer<MySyncPolicy> sync(MySyncPolicy(10), image_sub, info_sub, cloud_sub);
 cout << "breakpoint 1 " << endl;
 sync.registerCallback(boost::bind(&callback, _1, _2, _3)); // Add "cout << "breakpoint 2" << endl;" at the beginning of callback function
cout << "breakpoint 3" << endl;
  ros::spin();
cout <<"breakpoint 4" << endl;

After I run the code, only "breakpoint 1" and "breakpoint 3" show up. It means that the callback function is skipped and ros::spin is not implementing.

Can anyone help me figure out where the problem is ? Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-08-02 13:59:41 -0500

ahendrix gravatar image

It looks like this code is fine.

If you're not getting callbacks, you should use rqt_graph or rostopic to confirm that the calibration node is subscribed to the correct topics, and that data is published on all topics. If one of the topics is not present, the synchronizer will never call its callback.

ros::spin() is supposed to block until the program terminates, so that seems to be working properly.

edit flag offensive delete link more

Comments

Thank you! As you suggest, I checked rqt_graph and found out that the node is not subscribed to the correct topics! :)

KWL gravatar image KWL  ( 2016-08-03 13:11:17 -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: 2016-08-02 13:15:55 -0500

Seen: 488 times

Last updated: Aug 02 '16