ros publisher not publishing
I have a class called PublishObject to manage my ros node, however, I only want to publish things when I use ctrl+c to to kill the spin() and return to the main function as following, however I find that when I return to the main function, everything works in the function node_instance.second_run_publish_matched_object(), but I think the publisher is notworking as the rviz doesn't receive anything?
How can I fix this? Or I am supposed only to using Publisher insided the callback function such that it will publish properly??
int main(int argc, char **argv)
ros::init(argc, argv, "publish_object");
PublishObject node_instance;
ros::spin();
node_instance.second_run_publish_matched_object(); // to publish things.
return 0;
}
it seems that when use ctrl+c to return to main function, my advertise rostopic also get killed
The purpose of ctrl+c is to shut your node down. You should not use it to switch to a different mode of operation as you're doing.