Getting messages after an user input?
Hi all,
Right now my situation is that there is a node that publishes information, and I need to be able grab information from the publishing node and then print out (I need it for more than just "printing", but trying to keep it simple here) the information recieved when there is an user input.
Here's a snippet of the code
while(true)
{
std::string inputString;
std::cout << "Give input";
std::getline(std::cin, inputString);
if(inputString.compare("something") == 0)
{
//send a request to the node serving out the messages
//print out recieved messages.
}
ros::spinOnce();
}
So I noticed that the received messages do not update on the first input of "something" (hence printing out the previous, un-updated message), but rather on the second time of input. To the best of my knowledge, it has to do something with how getline() is a blocking function, and hence the subscriber/publisher/service calls within this node are not being called, and is only called after there is a spin function invovled (be it spinOnce or spin). In this case, what is a good solution to get around this?