Keep running the function without restarting it?

asked 2015-03-19 13:59:15 -0500

215 gravatar image

I have this problem that i cannot make run my while(true) without it get restarted..

I think the problem occurs since

in my main loop

int main
{
    ros::init(argc,argv, "loop");
    loop();
    ros::spin();
}

In side loop()

void loop()
{

   cout << "Are you ready" << endl;
   while(ready == false
  {

      //DO SOMETHING 
     ros::spinOnce() //needed since i read from a subscriber in this while loop
  }

 cout << "i am out" << endl;
 while(true)
 {
 //do something again
     ros::spinOnce();
  }

}

Right now it keep printing "are you ready", the idea was it should print it once.. I don't understand how it comes outside the loop.. it seems impossible to do..

edit retag flag offensive close merge delete

Comments

This code snippet should not produce the output you describe. Maybe you omitted the line which causes your problem. Can you post a more complete code? (e.g. in the line while(ready == false a bracket is missing)

BennyRe gravatar imageBennyRe ( 2015-03-20 07:22:31 -0500 )edit