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

Redeclare loop_rate depending on boolean

asked 2016-02-14 12:33:11 -0600

user23fj239 gravatar image

Given this example, in which I want to decide via if which loop_rate to use when spinning

      if(my_bool)  ros::Rate loop_rate(100); //Hz
      else ros::Rate loop_rate(10);

   //thread safe regular mutex spin

The compiler complains about rate not declared, as it is out of scope. But I need the if to decide which rate to get.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2016-02-14 12:45:58 -0600

user23fj239 gravatar image

I had to move on out of the if and redeclare by loop_rate(double frequency), but with ros::Rate in front:

    ros::Rate loop_rate(rate_eff[type-1]/2+1);
    if(use_def) ros::Rate loop_rate(100);
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-02-14 12:33:11 -0600

Seen: 124 times

Last updated: Feb 14 '16