ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

while loop lock subcribing

asked 2012-12-08 04:29:02 -0600

Auzias gravatar image

Hi everybody,I'm part of an international project team working on robot using ROS. We are stuck with a problem about multithreading. The code below never exit the loop because of the _current_angle is not changed:

  while(ros::ok() && _current_angle <= -1)
    ROS_INFO("[Navigation::Navigation] angle: %g", _current_angle);

You may be agree that it should not change by itself but the _current_angle is modified in a function called back by the subscriber.

The problem, I think, is that during the while loop the function called back from the subscriber is not executed. How should we manage it then ?

PS : the _current_angle is a class' attribute and the part of the code below is in the constructor of this class.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2012-12-08 05:33:53 -0600

Auzias gravatar image

My bad, sorry. The problem was that I subscribe to the topic (to change the _current_angle) after the constructor. Now it's working . About the code (which is on githug) I cannot post the link due to low karma: https:// github. com/kissdestinator/FroboMind

edit flag offensive delete link more

answered 2012-12-08 04:38:59 -0600

dornhege gravatar image

Well, yes, the code above should run. The error is in how the other code that you don't show is structured. If you want more detailed help, you need to come up with a complete minimal example.

The only guess I have from your description is that you are running the spin loop above in the constructor. This will mean that your object is actually NEVER constructed as the constructor can't finish. I have never tried what would happen in such a case, but that would be the first thing to change.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2012-12-08 04:29:02 -0600

Seen: 392 times

Last updated: Dec 08 '12