ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Initializer with timer:
void MainWindow::on_ROSSubscribeButton_clicked() { ros::init(m_argc, m_argv, "camera_check"); ros::NodeHandle n1; ros::Subscriber sub1 = n1.subscribe("/rtsp_1/image_raw", 100, &MainWindow::rtsp1Callback, this); CameraCheckTimer.start(100); //calls ros::spinOnce() every 1000ms; }
However I do not get any callbacks.
The problem here is scope: sub1
goes out of scope as soon as on_ROSSubscribeButton_clicked()
completes.
So the Subscriber
gets destroyed, cancelling the subscription. Additionally, the NodeHandle
also vanishes.
Caling ros::spinOne()
at this point doesn't really do much any more, as there are no subscriptions.
Make sure to keep the ros::Subscriber
around, and probably also the ros::NodeHandle
(as a member variable fi). Things should start working.
This makes me suspect that ros::spin() and ros::spinOnce() are somehow getting an implicit pointer to the GlobalCallbackQueue from the ros::init() function. Is this the case?
If so, what is the data type of ros::GlobalCallbackQueue (so that I can pass a global pointer to it into my timer loop)?
I don't believe this has anything to do with your problem.