ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
0

Keep running the function without restarting it?

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

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

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-03-20 07:22:31 -0600

BennyRe gravatar image

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)

edit flag offensive delete link more

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: 2015-03-19 13:59:15 -0600

Seen: 231 times

Last updated: Mar 19 '15