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

while loop lock subcribing

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

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);
    _motor_power_pub.publish(_motor_power_msg);
    ros::spinOnce();
    loop_rate.sleep();
  }

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
0

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

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
0

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

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

Stats

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

Seen: 395 times

Last updated: Dec 08 '12